This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Flow86's profile picture

Items not correctly set

Started by Flow86, 24 March 2012 - 09:59 AM
Flow86 #1
Posted 24 March 2012 - 10:59 AM
Hi,

I've recently noticed that computercraft can't place items (like buildcraft pipes etc)

the simple solution for it I've found by comparing the computer-craft code and the buildcraft-code:

buildcraft simply uses "onItemUse" with a "fake" EntityPlayer.

if I remove the ItemBlock-check in takePlaceableItem and change the place-method to


   	 Item item = itemStack.getItem();
        if(item == null)
            return false;
        
        if (item.onItemUse(itemStack, getTempPlayer(worldObj), worldObj, x, y - 1, z, 1)) {
            if (item instanceof ItemComputer)
                ((ItemComputer) item).setupComputerAfterPlacement(itemStack, worldObj, x, y, z);

            Block block = Block.blocksList[worldObj.getBlockId(x, y, z)];
            if(block != null)
                mod_CCTurtle.playBlockSound(worldObj, x + 0.5F, y + 0.5F, z + 0.5F, block);
            return true;
        }

oh and the "getTempPlayer"-method I adapted from buildcraft:


    private static EntityPlayer tempPlayer = null;

    private static EntityPlayer getTempPlayer(World world) {
        if (tempPlayer == null) {
            tempPlayer = new EntityPlayer(world) {
                @Override
                public void func_6420_o() {
                }
            };
        }
        return tempPlayer;
    }

now my turtle can place every item as the player would
Sebra #2
Posted 24 March 2012 - 11:23 AM
Doubt it is a bug, doubt developer want it, no doubts many player want it in game.
Cloudy #3
Posted 24 March 2012 - 11:28 AM
It isn't a "bug" it's just how the code works. And yes, Dan has expressed interest in turtles using items.

Does this code work with placing seeds etc?
Sebra #4
Posted 24 March 2012 - 11:46 AM
buildcraft simply uses "onItemUse" with a "fake" EntityPlayer.
I want to ask if Deployer use the same method too, But Eloraam forbid decompiling.
Cloudy #5
Posted 24 March 2012 - 04:20 PM
Yeah, as far as I know the deployer uses the same method.
Flow86 #6
Posted 24 March 2012 - 07:12 PM
buildcraft simply uses "onItemUse" with a "fake" EntityPlayer.
I want to ask if Deployer use the same method too, But Eloraam forbid decompiling.
eloraam? what has eloraam to do with buildcraft? and how buildcraft handles the item stuff?

(oh I havent read deployer :(/>/> but he can't forbid decompiling - he possible can say "please please, dont decompile it …" but to look how he does something, that he says no is not a reason to not do it … )
Casper7526 #7
Posted 25 March 2012 - 12:54 AM
I've forwarded this to Dan, as I know he was interested in making them able to use more items/blocks correctly. So we'll see where it goes from here :(/>/>
djblocksaway #8
Posted 03 April 2012 - 03:18 PM
thanks for letting us know :)/>/>