Jump to content

meee39

Members
  • Posts

    119
  • Joined

  • Last visited

Everything posted by meee39

  1. That isn't part of the problem though. That is just caused by it not being able to find the item to drop when breaking the block.
  2. Code: package com.leo.mobsuppressors.tileentity; import com.leo.mobsuppressors.EnumAltarRecipes; import com.leo.mobsuppressors.MobSuppressors; import com.leo.mobsuppressors.network.PacketAltarCraft; 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.fml.common.network.NetworkRegistry; 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))); System.out.println(pos); 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; } } Log:
  3. In 1.11.2 I used: world.spawnEntity(new EntityItem(world, getPos().getX(), getPos().getY() + 1, getPos().getZ(), new ItemStack(recipe.output, 1))); Although it doesn't seem to work anymore. So is there a special spawning function for items like there is for lightning?
  4. In a custom HUD or GUI how do I set it the game to only render part of an image?
  5. I am updating my 1.11.2 mod into 1.12 and I have used various Forge Forums threads and other websites to figure out how to port the code. I have found nothing on doing TESRs in 1.12 though and it is saying that my method signature isn't an override: public void renderTileEntityAt(TileEntitySuppressionPedestal te, double x, double y, double z, float partialTicks, int destroyStage)
  6. If I use: public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { AxisAlignedBB collision = new AxisAlignedBB(0, 0, 0, 0, 0, 0); return collision; } There is no player collision although the block can't be mined.
  7. Here is the packet: package com.leo.lbacraft.network; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.util.DamageSource; 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 PacketDamageEntity implements IMessage { public static class Handler implements IMessageHandler<PacketDamageEntity, IMessage> { @Override public IMessage onMessage(PacketDamageEntity message, MessageContext ctx) { System.out.println("Server" + message.ID); Minecraft.getMinecraft().world.getEntityByID(message.ID).attackEntityFrom(DamageSource.MAGIC, message.damage); return null; } } public int ID; public float damage; public PacketDamageEntity() { } public PacketDamageEntity(int ID, float damage) { this.ID = ID; this.damage = damage; } @Override public void fromBytes(ByteBuf buf) { ID = buf.readInt(); damage = buf.readFloat(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(ID); buf.writeFloat(damage); } } It still doesn't damage the entities.
  8. For the packet how do I serialise the Entity as NBT?
  9. I have a keybind that will damage entities and of course keybinds are client-side. If I use entity.attackEntityFrom() it doesn't work because that is a server-side function. Is there a packet built in to damage entities or do I need to write my own one?
  10. I am making a mod with the Baubles API and in part of it I need to check if the player is wearing a certain Bauble.
  11. In my event hooks I replace the Door break AI task with my own: @SubscribeEvent public void onEntitySpawn(EntityJoinWorldEvent e) { if (e.getEntity() instanceof EntityZombie) { ((EntityZombie)e.getEntity()).tasks.removeTask(new EntityAIBreakDoor((EntityLiving) e.getEntity())); ((EntityZombie)e.getEntity()).tasks.addTask(8, new EntityAIBreakDoorCheckMobSuppressor((EntityLiving)e.getEntity())); } } package com.leo.mobsuppressors.entities.ai; import com.leo.mobsuppressors.EnumMobSuppressorType; import com.leo.mobsuppressors.tileentity.TileEntityMobSuppressor; import net.minecraft.block.Block; import net.minecraft.block.BlockDoor; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.ai.EntityAIDoorInteract; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.EnumDifficulty; public class EntityAIBreakDoorCheckMobSuppressor extends EntityAIDoorInteract { private int breakingTime; private int previousBreakProgress = -1; public EntityAIBreakDoorCheckMobSuppressor(EntityLiving entityIn) { super(entityIn); } /** * Returns whether the EntityAIBase should begin execution. */ public boolean shouldExecute() { for (TileEntity te: theEntity.world.loadedTileEntityList) { if (te instanceof TileEntityMobSuppressor && ((TileEntityMobSuppressor) te).type == EnumMobSuppressorType.ZOMBIE) { double distanceX = te.getPos().getX() - theEntity.getPosition().getX(); double distanceY = te.getPos().getY() - theEntity.getPosition().getY(); double distanceZ = te.getPos().getZ() - theEntity.getPosition().getZ(); System.out.println(distanceX + "\n"); System.out.println(distanceY + "\n"); System.out.println(distanceZ + "\n\n"); if (!(distanceX < 5 && distanceY < 5 && distanceZ < 5)) { return false; } } } if (!super.shouldExecute()) { return false; } else if (!this.theEntity.world.getGameRules().getBoolean("mobGriefing") || !this.theEntity.world.getBlockState(this.doorPosition).getBlock().canEntityDestroy(this.theEntity.world.getBlockState(this.doorPosition), this.theEntity.world, this.doorPosition, this.theEntity) || !net.minecraftforge.event.ForgeEventFactory.onEntityDestroyBlock(this.theEntity, this.doorPosition, this.theEntity.world.getBlockState(this.doorPosition))) { return false; } else { BlockDoor blockdoor = this.doorBlock; return !BlockDoor.isOpen(this.theEntity.world, this.doorPosition); } } /** * Execute a one shot task or start executing a continuous task */ public void startExecuting() { super.startExecuting(); this.breakingTime = 0; } /** * Returns whether an in-progress EntityAIBase should continue executing */ public boolean continueExecuting() { double d0 = this.theEntity.getDistanceSq(this.doorPosition); boolean flag; if (this.breakingTime <= 240) { BlockDoor blockdoor = this.doorBlock; if (!BlockDoor.isOpen(this.theEntity.world, this.doorPosition) && d0 < 4.0D) { flag = true; return flag; } } flag = false; return flag; } /** * Resets the task */ public void resetTask() { super.resetTask(); this.theEntity.world.sendBlockBreakProgress(this.theEntity.getEntityId(), this.doorPosition, -1); } /** * Updates the task */ public void updateTask() { super.updateTask(); if (this.theEntity.getRNG().nextInt(20) == 0) { this.theEntity.world.playEvent(1019, this.doorPosition, 0); } ++this.breakingTime; int i = (int)((float)this.breakingTime / 240.0F * 10.0F); if (i != this.previousBreakProgress) { this.theEntity.world.sendBlockBreakProgress(this.theEntity.getEntityId(), this.doorPosition, i); this.previousBreakProgress = i; } if (this.breakingTime == 240 && this.theEntity.world.getDifficulty() == EnumDifficulty.HARD) { this.theEntity.world.setBlockToAir(this.doorPosition); this.theEntity.world.playEvent(1021, this.doorPosition, 0); this.theEntity.world.playEvent(2001, this.doorPosition, Block.getIdFromBlock(this.doorBlock)); } } } The zombies still break down doors.
  12. Oh I just realised the problem. I am using EntityLivingEvent.getEntity() which returns Entity, not EntityLiving. I will need to cast it to EntityZombie and then it will be fine.
  13. That is odd. Eclipse claims that tasks cannot be resolved.
  14. But it didn't show up in autocomplete.
  15. How do I replace EntityAI tasks?
  16. Okay
  17. Thanks. It works now. Why use hasTileEntity instead of ITIleEntityProvider?
  18. 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) { } }
  19. 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.
  20. I used the debugger. This bit is: if (tower.netherStarUsesLeft > 0) { tower.netherStarUsesLeft -= 1;
  21. 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; } }
  22. After checking for server side it suddenly stops thinking there is a Nether Star there.
  23. 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; } }
  24. 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.
  25. It does the same as before; the item that should be there is on the pedestal and when you take it out you just get back the item that was originally in that place.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.