Posted July 9, 20178 yr When spawning in an ItemStack the stack is a ghost item and can't be picked up. The code I am using to spawn the ItemStack is this: world.spawnEntity(new EntityItem(world, getPos().getX(), getPos().getY() + 1, getPos().getZ(), new ItemStack([some item], 1))); This is running on the server. Edited July 9, 20178 yr by meee39
July 9, 20178 yr Are you sure this is only running on the server? It sounds like it's running on the client. Post more of your code. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 9, 20178 yr Author package com.leo.mobsuppressors.tileentity; import com.leo.mobsuppressors.EnumAltarRecipes; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; import net.minecraftforge.items.CapabilityItemHandler; public class TileEntitySuppressionAltarCore extends TileEntity implements ITickable { public TileEntitySuppressionAltarCore() { } @Override public void update() { attemptCraft(); } public boolean attemptCraft() { if (!(world.getTileEntity(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ())) instanceof TileEntitySuppressionTower)) { return false; } TileEntitySuppressionTower tower; //Check structure BlockPos[] positions = { //Edges new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ()), new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() + 1 ), new BlockPos(getPos().getX() -1, getPos().getY(), getPos().getZ()), new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() - 1), //Corners new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ() + 1), new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ() - 1), new BlockPos(getPos().getX() - 1, getPos().getY(), getPos().getZ() - 1), new BlockPos(getPos().getX() - 1, getPos().getY(), getPos().getZ() + 1) }; tower = (TileEntitySuppressionTower)world.getTileEntity(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ())); for (BlockPos position: positions) { if (!(world.getTileEntity(position) instanceof TileEntitySuppressionPedestal)) { return false; } } for (EnumAltarRecipes recipe: EnumAltarRecipes.values()) { if (tower.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[4]) { //Check edges if (((TileEntitySuppressionPedestal)world.getTileEntity(positions[0])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[1])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[2])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[3])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1]) { //Check corners if (((TileEntitySuppressionPedestal)world.getTileEntity(positions[4])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[5])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[6])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[7])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0]) { if (tower.netherStarUsesLeft > 0) { tower.netherStarUsesLeft -= 1; tower.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).extractItem(0, 1, false); world.spawnEntity(new EntityItem(world, getPos().getX(), getPos().getY() + 1, getPos().getZ(), new ItemStack(recipe.output, 1))); //MobSuppressors.network.sendToAllAround(new PacketAltarCraft(tower, ItemStack.EMPTY), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); //MobSuppressors.network.sendToAllAround(new PacketAltarCraft(tower, new ItemStack(recipe.output, 1)), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); world.addWeatherEffect(new EntityLightningBolt(world, pos.getX(), pos.getY(), pos.getZ(), false)); for (BlockPos position: positions) { ((TileEntitySuppressionPedestal)world.getTileEntity(position)).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).extractItem(0, 1, false); } } } } } } return true; } }
July 9, 20178 yr ITickable#update is called on both the client and server, you need to check if it's being called on the server (i.e. World#isRemote is false) before spawning the items and the lightning bolt. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 9, 20178 yr Author After checking for server side it suddenly stops thinking there is a Nether Star there.
July 9, 20178 yr Author package com.leo.mobsuppressors.tileentity; import com.leo.mobsuppressors.EnumAltarRecipes; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; import net.minecraftforge.items.CapabilityItemHandler; public class TileEntitySuppressionAltarCore extends TileEntity implements ITickable { public TileEntitySuppressionAltarCore() { } @Override public void update() { if (!world.isRemote) { attemptCraft(); } } public boolean attemptCraft() { if (!(world.getTileEntity(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ())) instanceof TileEntitySuppressionTower)) { return false; } TileEntitySuppressionTower tower; //Check structure BlockPos[] positions = { //Edges new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ()), new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() + 1 ), new BlockPos(getPos().getX() -1, getPos().getY(), getPos().getZ()), new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() - 1), //Corners new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ() + 1), new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ() - 1), new BlockPos(getPos().getX() - 1, getPos().getY(), getPos().getZ() - 1), new BlockPos(getPos().getX() - 1, getPos().getY(), getPos().getZ() + 1) }; tower = (TileEntitySuppressionTower)world.getTileEntity(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ())); for (BlockPos position: positions) { if (!(world.getTileEntity(position) instanceof TileEntitySuppressionPedestal)) { return false; } } for (EnumAltarRecipes recipe: EnumAltarRecipes.values()) { if (tower.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[4]) { //Check edges if (((TileEntitySuppressionPedestal)world.getTileEntity(positions[0])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[1])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[2])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[3])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[1]) { //Check corners if (((TileEntitySuppressionPedestal)world.getTileEntity(positions[4])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[5])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[6])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0] && ((TileEntitySuppressionPedestal)world.getTileEntity(positions[7])).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).getStackInSlot(0).getItem() == recipe.inputs[0]) { if (tower.netherStarUsesLeft > 0) { tower.netherStarUsesLeft -= 1; tower.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).extractItem(0, 1, false); world.spawnEntity(new EntityItem(world, getPos().getX(), getPos().getY() + 1, getPos().getZ(), new ItemStack(recipe.output, 1))); //MobSuppressors.network.sendToAllAround(new PacketAltarCraft(tower, ItemStack.EMPTY), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); //MobSuppressors.network.sendToAllAround(new PacketAltarCraft(tower, new ItemStack(recipe.output, 1)), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); world.addWeatherEffect(new EntityLightningBolt(world, pos.getX(), pos.getY(), pos.getZ(), false)); for (BlockPos position: positions) { ((TileEntitySuppressionPedestal)world.getTileEntity(position)).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH).extractItem(0, 1, false); } } } } } } return true; } }
July 9, 20178 yr Author I used the debugger. This bit is: if (tower.netherStarUsesLeft > 0) { tower.netherStarUsesLeft -= 1;
July 9, 20178 yr Author I expected the condition to succeed, but it didn't. I put the star into the TE but the debugger said the netherstarusesleft variable was 0.
July 9, 20178 yr Author This: package com.leo.mobsuppressors.blocks; import com.leo.mobsuppressors.CreativeTab; import com.leo.mobsuppressors.tileentity.TileEntitySuppressionTower; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; public class BlockSuppressionTower extends Block implements ITileEntityProvider { public BlockSuppressionTower(String unlocalisedName, String registryName) { super(Material.ROCK); this.setHardness(2); this.setUnlocalizedName(unlocalisedName); this.setRegistryName(registryName); this.setCreativeTab(CreativeTab.mobSuppressorCreativeTab); } public BlockSuppressionTower(Material materialIn) { super(materialIn); } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean isFullyOpaque(IBlockState state) { return false; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntitySuppressionTower(); } @Override public void breakBlock(World world, BlockPos pos, IBlockState state) { super.breakBlock(world, pos, state); world.removeTileEntity(pos); TileEntitySuppressionTower tile = (TileEntitySuppressionTower)world.getTileEntity(pos); IItemHandler itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH); ItemStack stack = itemHandler.getStackInSlot(0); if (!stack.isEmpty()) { EntityItem item = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), stack); world.spawnEntity(item); } } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { TileEntitySuppressionTower TEST = (TileEntitySuppressionTower)world.getTileEntity(pos); IItemHandler itemHandler = TEST.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side); if (player.getHeldItem(hand).isEmpty()) { player.setHeldItem(hand, itemHandler.extractItem(0, 64, false)); } else if (player.getHeldItem(hand).getItem() == Items.NETHER_STAR) { if (TEST.netherStarUsesLeft < 1) { player.getHeldItem(hand).shrink(1); TEST.setHasNetherStar(); } } else { player.setHeldItem(hand, itemHandler.insertItem(0, player.getHeldItem(hand), false)); } TEST.markDirty(); } return true; } } Calls sethasnetherstar is this: package com.leo.mobsuppressors.tileentity; import javax.annotation.Nullable; import com.leo.mobsuppressors.MobSuppressors; import com.leo.mobsuppressors.network.PacketRequestUpdateTower; import com.leo.mobsuppressors.network.PacketUpdateTower; import com.leo.mobsuppressors.network.PacketUpdateTowerNetherStarUsesLeft; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemStackHandler; public class TileEntitySuppressionTower extends TileEntity { public ItemStackHandler itemStackHandler = new ItemStackHandler(1) { @Override protected void onContentsChanged(int slot) { if (!world.isRemote) { lastChangeTime = world.getTotalWorldTime(); MobSuppressors.network.sendToAllAround(new PacketUpdateTower(TileEntitySuppressionTower.this), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); } } }; public int netherStarUsesLeft; public long lastChangeTime; public TileEntitySuppressionTower() { this.netherStarUsesLeft = 0; } public void setHasNetherStar() { MobSuppressors.network.sendToAllAround(new PacketUpdateTowerNetherStarUsesLeft(TileEntitySuppressionTower.this, 10), new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 64)); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setTag("inventory", itemStackHandler.serializeNBT()); compound.setLong("lastChangeTime", lastChangeTime); compound.setInteger("netherStarUsesLeft", netherStarUsesLeft); return super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { itemStackHandler.deserializeNBT(compound.getCompoundTag("inventory")); lastChangeTime = compound.getLong("lastChangeTime"); netherStarUsesLeft = compound.getInteger("netherStarUsesLeft"); super.readFromNBT(compound); } @Override public void onLoad() { if (world.isRemote) { MobSuppressors.network.sendToServer(new PacketRequestUpdateTower(this)); } } @Override public AxisAlignedBB getRenderBoundingBox() { return new AxisAlignedBB(getPos(), getPos().add(1, 2, 1)); } @Override public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); } @Nullable @Override public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) { return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? (T)itemStackHandler : super.getCapability(capability, facing); } } Which sends this packet: package com.leo.mobsuppressors.network; import com.leo.mobsuppressors.tileentity.TileEntitySuppressionTower; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class PacketUpdateTowerNetherStarUsesLeft implements IMessage { public static class Handler implements IMessageHandler<PacketUpdateTowerNetherStarUsesLeft, IMessage> { @Override public IMessage onMessage(PacketUpdateTowerNetherStarUsesLeft message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(() -> { TileEntitySuppressionTower te = (TileEntitySuppressionTower)Minecraft.getMinecraft().world.getTileEntity(message.pos); te.netherStarUsesLeft = message.netherStarUses; te.lastChangeTime = message.lastChangeTime; }); return null; } } public int netherStarUses; public BlockPos pos; public long lastChangeTime; public PacketUpdateTowerNetherStarUsesLeft(int netherStarUses, BlockPos pos, long lastChangeTime) { this.netherStarUses = netherStarUses; this.pos = pos; this.lastChangeTime = lastChangeTime; } public PacketUpdateTowerNetherStarUsesLeft(TileEntitySuppressionTower te, int netherStarUses) { this(netherStarUses, te.getPos(), te.lastChangeTime); } public PacketUpdateTowerNetherStarUsesLeft() { } @Override public void toBytes(ByteBuf buf) { buf.writeInt(netherStarUses); buf.writeLong(pos.toLong()); buf.writeLong(lastChangeTime); } @Override public void fromBytes(ByteBuf buf) { netherStarUses = buf.readInt(); pos = BlockPos.fromLong(buf.readLong()); lastChangeTime = buf.readLong(); } } Which is registered here: package com.leo.mobsuppressors; import com.leo.mobsuppressors.blocks.ModBlocks; import com.leo.mobsuppressors.eventhooks.EventHooks; import com.leo.mobsuppressors.items.ModItems; import com.leo.mobsuppressors.network.PacketAltarCraft; import com.leo.mobsuppressors.network.PacketRequestUpdatePedestal; import com.leo.mobsuppressors.network.PacketRequestUpdateTower; import com.leo.mobsuppressors.network.PacketUpdatePedestal; import com.leo.mobsuppressors.network.PacketUpdateTower; import com.leo.mobsuppressors.network.PacketUpdateTowerNetherStarUsesLeft; import com.leo.mobsuppressors.proxies.ClientProxy; import com.leo.mobsuppressors.tileentity.ModTileEntities; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; @Mod(modid = MobSuppressors.modid, name = MobSuppressors.name, version = MobSuppressors.version, acceptedMinecraftVersions = MobSuppressors.acceptedMinecraftVersions) public class MobSuppressors { public static final String modid = "mobsuppressors"; public static final String name = "Mob Suppressors"; public static final String version = "0.1 - alpha"; public static final String acceptedMinecraftVersions = "[1.11.2]"; public static final SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel("mobsuppressors"); @SidedProxy(serverSide = "com.leo.mobsuppressors.proxies.ServerProxy", clientSide = "com.leo.mobsuppressors.proxies.ClientProxy") public static ClientProxy proxy; @Mod.Instance(MobSuppressors.modid) public static MobSuppressors instance; @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new EventHooks()); network.registerMessage(new PacketUpdatePedestal.Handler(), PacketUpdatePedestal.class, 0, Side.CLIENT); network.registerMessage(new PacketRequestUpdatePedestal.Handler(), PacketRequestUpdatePedestal.class, 1, Side.SERVER); network.registerMessage(new PacketUpdateTower.Handler(), PacketUpdateTower.class, 2, Side.CLIENT); network.registerMessage(new PacketRequestUpdateTower.Handler(), PacketRequestUpdateTower.class, 3, Side.SERVER); network.registerMessage(new PacketUpdateTowerNetherStarUsesLeft.Handler(), PacketUpdateTowerNetherStarUsesLeft.class, 4, Side.CLIENT); network.registerMessage(new PacketAltarCraft.Handler(), PacketAltarCraft.class, 5, Side.SERVER); network.registerMessage(new PacketAltarCraft.Handler(), PacketAltarCraft.class, 6, Side.CLIENT); } @Mod.EventHandler public void init(FMLInitializationEvent event) { ModBlocks.init(); ModTileEntities.init(); ModItems.init(); proxy.init(); } @Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { } }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.