Jump to content

Ms_Raven

Members
  • Posts

    106
  • Joined

  • Last visited

Everything posted by Ms_Raven

  1. No? All my new inventory slots use inventoryCustom. I'm adding slots the same exact way here as I did with my backpack inventory which works perfectly fine. Only difference is that I'm now including crafting and armour slots, the addition of which would not result in the error I'm getting. This is the backpack that works fine: package skye.gamecube.core.inventories; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class ContainerBackpack extends Container { public final InventoryBackpack inventory; public ContainerBackpack(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, InventoryBackpack inventoryItem) { this.inventory = inventoryItem; for (int i = 0; i < 20; i++) { addSlotToContainer(new SlotBackpack(this.inventory, i, 80 + 18 * (i / 4), 8 + 18 * (i % 4))); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142)); } } public boolean canInteractWith(EntityPlayer player) { return this.inventory.isUseableByPlayer(player); } public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(par2); if ((slot != null) && (slot.getHasStack())) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 < 20) { if (!mergeItemStack(itemstack1, 20, 56, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if ((par2 >= 20) && (par2 < 47)) { if (!mergeItemStack(itemstack1, 47, 56, false)) { return null; } } else if ((par2 >= 47) && (par2 < 56)) { if (!mergeItemStack(itemstack1, 20, 47, false)) { return null; } } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(par1EntityPlayer, itemstack1); } return itemstack; } public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) { if ((slot >= 0) && (getSlot(slot) != null) && (getSlot(slot).getStack() == player.getHeldItem())) { return null; } return super.slotClick(slot, button, flag, player); } protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4) { boolean flag1 = false; int k = par2; if (par4) { k = par3 - 1; } if (par1ItemStack.isStackable()) { while ((par1ItemStack.stackSize > 0) && (((!par4) && (k < par3)) || ((par4) && (k >= par2)))) { Slot slot = (Slot) this.inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if ((itemstack1 != null) && (itemstack1 == par1ItemStack) && ((!par1ItemStack.getHasSubtypes()) || (par1ItemStack.getItemDamage() == itemstack1.getItemDamage())) && (ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1))) { int l = itemstack1.stackSize + par1ItemStack.stackSize; if ((l <= par1ItemStack.getMaxStackSize()) && (l <= slot.getSlotStackLimit())) { par1ItemStack.stackSize = 0; itemstack1.stackSize = l; this.inventory.markDirty(); flag1 = true; } else if ((itemstack1.stackSize < par1ItemStack.getMaxStackSize()) && (l < slot.getSlotStackLimit())) { par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = par1ItemStack.getMaxStackSize(); this.inventory.markDirty(); flag1 = true; } } if (par4) { k--; } else { k++; } } } if (par1ItemStack.stackSize > 0) { if (par4) { k = par3 - 1; } else { k = par2; } while (((!par4) && (k < par3)) || ((par4) && (k >= par2))) { Slot slot = (Slot) this.inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if (itemstack1 == null) { int l = par1ItemStack.stackSize; if (l <= slot.getSlotStackLimit()) { slot.putStack(par1ItemStack.copy()); par1ItemStack.stackSize = 0; this.inventory.markDirty(); flag1 = true; break; } putStackInSlot(k, new ItemStack(par1ItemStack.getItem(), slot.getSlotStackLimit())); par1ItemStack.stackSize -= slot.getSlotStackLimit(); this.inventory.markDirty(); flag1 = true; } if (par4) { k--; } else { k++; } } } return flag1; } } I cannot figure out what I'm doing wrong now that I did right in the backpack.
  2. This is my error: I'm assuming it's only recognising the 45 slots in the Vanilla inventory, not the additional 20 slots in my new inventory? Each time I click on a new slot I get this crash report. But I can't figure out where that goes wrong. How do I fix this? My inventory container: public class ContainerExtendedInventory extends Container { public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2); public IInventory craftResult = new InventoryCraftResult(); public ExtendedInventory inventory; private EntityPlayer player; private int slotAmount; public ContainerExtendedInventory(EntityPlayer player, InventoryPlayer inventory, ExtendedInventory inventoryCustom) { this.player = player; this.inventory = inventoryCustom; int i; int j; // Accessories this.addSlotToContainer(new SlotHead(inventoryCustom, 0, 188, ); this.addSlotToContainer(new SlotNeck(inventoryCustom, 1, 188, 26)); this.addSlotToContainer(new SlotBody(inventoryCustom, 2, 188, 44)); this.addSlotToContainer(new SlotHandL(inventoryCustom, 3, 170, 35)); this.addSlotToContainer(new SlotHandR(inventoryCustom, 4, 188, 35)); this.addSlotToContainer(new SlotBeltL(inventoryCustom, 5, 170, 53)); this.addSlotToContainer(new SlotBeltR(inventoryCustom, 6, 188, 53)); this.addSlotToContainer(new SlotFeet(inventoryCustom, 7, 188, 63)); // (Future Accessory Slots) this.addSlotToContainer(new SlotNull(inventoryCustom, 8, 170, 17)); this.addSlotToContainer(new SlotNull(inventoryCustom, 9, 206, 17)); // (Future Slots) this.addSlotToContainer(new SlotNull(inventoryCustom, 10, 179, 93)); this.addSlotToContainer(new SlotNull(inventoryCustom, 11, 197, 93)); this.addSlotToContainer(new SlotNull(inventoryCustom, 12, 179, 111)); this.addSlotToContainer(new SlotNull(inventoryCustom, 13, 197, 111)); // (Future Slots) this.addSlotToContainer(new SlotNull(inventoryCustom, 14, 180, 132)); this.addSlotToContainer(new SlotNull(inventoryCustom, 15, 198, 132)); // Ammo this.addSlotToContainer(new SlotAmmo(inventoryCustom, 16, 80, ); this.addSlotToContainer(new SlotAmmo(inventoryCustom, 17, 80, 26)); this.addSlotToContainer(new SlotAmmo(inventoryCustom, 18, 80, 44)); this.addSlotToContainer(new SlotAmmo(inventoryCustom, 19, 80, 62)); slotAmount = 20; Tools.print("Custom slots ended at " + slotAmount); for (i = 0; i < 4; ++i) { this.addSlotToContainer( new SlotArmourDefault(player, inventory, inventoryCustom.getSizeInventory() - 1 - i, 8, 8 + i * 18, i)); slotAmount++; } Tools.print("Armour ended at " + slotAmount); for (i = 0; i < 3; ++i) { for (int k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(inventory, k + i * 9 + 9, 8 + k * 18, 84 + i * 18)); slotAmount++; } } Tools.print("Inventory ended at " + slotAmount); for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142)); slotAmount++; } Tools.print("Hotbar ended at " + slotAmount); for (i = 0; i < 2; ++i) { for (j = 0; j < 2; ++j) { this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 125 + j * 18, 17 + i * 18)); slotAmount++; } } Tools.print("Crafting ended at " + slotAmount); this.addSlotToContainer(new SlotCrafting(player, this.craftMatrix, this.craftResult, 0, 134, 60)); slotAmount++; Tools.print("Craft result ended at " + slotAmount); } public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) { if ((slot >= 0) && (getSlot(slot) != null) && (getSlot(slot).getStack() == player.getHeldItem())) { return null; } Tools.print("Clicked on slot " + slot); return super.slotClick(slot, button, flag, player); } @Override public boolean canInteractWith(EntityPlayer player) { return true; } @Override public ItemStack transferStackInSlot(EntityPlayer player, int par2) { // Accessories 0-19 // Armour 20-23 // Inventory 24-50 // Hotbar 51-59 // Crafting 60-63 // Craft result 64 ItemStack itemstack = null; Slot slot = (Slot) this.inventorySlots.get(par2); if ((slot != null) && (slot.getHasStack())) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); // Accessories to inventory if (par2 < 20) { if (!mergeItemStack(itemstack1, 24, 51, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } // Armour to inventory else if ((par2 >= 20) && (par2 < 24)) { if (!mergeItemStack(itemstack1, 24, 51, false)) { return null; } } // Hotbar to inventory else if ((par2 >= 51) && (par2 < 60)) { if (!mergeItemStack(itemstack1, 24, 51, false)) { return null; } } else if ((par2 >= 24) && par2 < 51) { if (itemstack.getItem() instanceof CoreAccessory) { Place place = ((CoreAccessory) itemstack.getItem()).getPlacement(); switch (place) { case HEAD: if (inventory.getStackInSlot(0) != null) { return null; } case NECK: if (inventory.getStackInSlot(1) != null) { return null; } case BODY: if (inventory.getStackInSlot(2) != null) { return null; } case HANDS: if ((inventory.getStackInSlot(3) != null) || inventory.getStackInSlot(4) != null) { return null; } case BELT: if ((inventory.getStackInSlot(5) != null) || inventory.getStackInSlot(6) != null) { return null; } case FEET: if (inventory.getStackInSlot(7) != null) { return null; } case AMMO: if (inventory.getStackInSlot(16) != null) { return null; } } } else if (!mergeItemStack(itemstack1, 51, 60, false)) { return null; } } if (itemstack1.stackSize == 64) { slot.putStack((ItemStack) null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(player, itemstack1); } return itemstack; } protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4) { boolean flag1 = false; int k = par2; if (par4) { k = par3 - 1; } if (par1ItemStack.isStackable()) { while ((par1ItemStack.stackSize > 0) && (((!par4) && (k < par3)) || ((par4) && (k >= par2)))) { Slot slot = (Slot) this.inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if ((itemstack1 != null) && (itemstack1 == par1ItemStack) && ((!par1ItemStack.getHasSubtypes()) || (par1ItemStack.getItemDamage() == itemstack1.getItemDamage())) && (ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1))) { int l = itemstack1.stackSize + par1ItemStack.stackSize; if ((l <= par1ItemStack.getMaxStackSize()) && (l <= slot.getSlotStackLimit())) { par1ItemStack.stackSize = 0; itemstack1.stackSize = l; this.inventory.markDirty(); flag1 = true; } else if ((itemstack1.stackSize < par1ItemStack.getMaxStackSize()) && (l < slot.getSlotStackLimit())) { par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize; itemstack1.stackSize = par1ItemStack.getMaxStackSize(); this.inventory.markDirty(); flag1 = true; } } if (par4) { k--; } else { k++; } } } if (par1ItemStack.stackSize > 0) { if (par4) { k = par3 - 1; } else { k = par2; } while (((!par4) && (k < par3)) || ((par4) && (k >= par2))) { Slot slot = (Slot) this.inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if (itemstack1 == null) { int l = par1ItemStack.stackSize; if (l <= slot.getSlotStackLimit()) { slot.putStack(par1ItemStack.copy()); par1ItemStack.stackSize = 0; this.inventory.markDirty(); flag1 = true; break; } putStackInSlot(k, new ItemStack(par1ItemStack.getItem(), slot.getSlotStackLimit())); par1ItemStack.stackSize -= slot.getSlotStackLimit(); this.inventory.markDirty(); flag1 = true; } if (par4) { k--; } else { k++; } } } return flag1; } }
  3. I made a larger player inventory. But I forgot that the default size is 176x166. I just fixed the size so the GUI displays normally, unfortunately all the actual slots in the container are still in the locations for the old inventory. I can't figure out how to change the Container size to fit the larger GUI size. How do I manage that?
  4. I used this site's own tutorial to try to do this. Inside the preInit() of the main class is: CoreRegistry.init() Inside CoreRegistry (leaving all unrelated things out) is this: public static Fluid honey = new Fluid("honey").setViscosity(6500); public static Block honey_fluid; public static Block[] blocks = { honey_fluid = new HoneyClassic("honey", honey, Material.water), }; public static void init() { honey.setBlock(honey_fluid); FluidRegistry.registerFluid(honey); for (int i = 0; i < blocks.length; i++) { GameRegistry.registerBlock(blocks[i], blocks[i].getUnlocalizedName()); } } Inside HoneyClassic is this: public class HoneyClassic extends BlockFluidClassic { private String name; @SideOnly(Side.CLIENT) protected IIcon stillIcon; @SideOnly(Side.CLIENT) protected IIcon flowingIcon; public HoneyClassic(String name, Fluid fluid, Material material) { super(fluid, material); this.name = name; this.setCreativeTab(CoreTabs.core); this.setBlockName(name); } @SideOnly(Side.CLIENT) public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { return Tools.getColour("gold", 2); } @Override public IIcon getIcon(int side, int meta) { return (side == 0 || side == 1) ? stillIcon : flowingIcon; } @SideOnly(Side.CLIENT) @Override public void registerBlockIcons(IIconRegister register) { stillIcon = register.registerIcon(Tools.get(name + "_still")); flowingIcon = register.registerIcon(Tools.get(name + "_flowing")); } @Override public boolean canDisplace(IBlockAccess world, int x, int y, int z) { if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false; return super.canDisplace(world, x, y, z); } @Override public boolean displaceIfPossible(World world, int x, int y, int z) { if (world.getBlock(x, y, z).getMaterial().isLiquid()) return false; return super.displaceIfPossible(world, x, y, z); } }
  5. Didn't see that... Okay, well that fixes the texture. But I'm still getting the same exact error.
  6. I don't understand why I'm getting this error. My fluid is registered. Why is this happening? This is the method I'm using to register everything. It works perfectly fine until I add the fluid there, doesn't matter if it comes before or after everything else. public static void init() { FluidRegistry.registerFluid(honey); for (int i = 0; i < items.length; i++) { GameRegistry.registerItem(items[i], items[i].getUnlocalizedName()); } for (int i = 0; i < blocks.length; i++) { GameRegistry.registerBlock(blocks[i], blocks[i].getUnlocalizedName()); } } And this is how it's registered in the blocks array: honey_fluid = new HoneyClassic("honey_fluid", honey, Material.water),
  7. I'm making a shooting star. So I want to have a chance of one falling from the sky when each new chunk is generated. The problem with that is the player most likely won't be able to see it falling since I can't exactly make an EntityItem give off light like that. So I want to adjust its fall speed so that when a player would typically be entering the area where it's falling or landing, they'll be able to see it. This is what I have so far but I'm guessing it's not the best way to do what I'm after: private void worldGen(World world, Random random, int chunkX, int chunkZ) { if (!world.isDaytime()) { int i = random.nextInt(10); if (i == 5) { int x = chunkX + random.nextInt(16); int y = 255; int z = chunkZ + random.nextInt(16); EntityItem item = new EntityItem(world, x, y, z, new ItemStack(Reg.fallen_star)); world.spawnEntityInWorld(item); item.motionY *= 2; } } } And then how would I manage to play a sound on impact to all players within view distance of the star, with equal volume to each? Would I be better off just making a new entity that extends EntityItem and adding that along with a light effect in there? Or would that even work?
  8. How would I write the repair item and the value of EnumChatFormatting to NBT?
  9. Nevermind this edit, I asked a stupid question here.
  10. I'm trying to make randomly-generated weapons. Everything from their damage, durability, enchantability, repair item, name colour and size. I have it all set up the way I want it but now I need to have it be saved to each individual generated sword. But how do I save those to NBT and read from NBT to set the actual values so already-existing swords don't re-generate upon every load?
  11. I'm trying to make a gun have recoil, so every time you shoot it the camera jolts up a few pixels before returning back to where it was after a fraction of a second. But I can't figure out how to move the camera.
  12. I'm making a mod that I want to have over a dozen addons for, like DLC that can be added without needing to update the core mod. But I was just wondering if there were any other requirements for the way the modid has to be written other than being lower-case. Would something like 'mod-addon1' work for example?
  13. There's a lot of code in a lot of classes that deals with biomes. I asked specifically what part of the code deals with the biome borders so I didn't have to make a massive post...
  14. I finally got my dimension to have multiple biomes but they generate like this. What part of the code deals with that and how would I fix it?
  15. It doesn't point to any part of my code so I have no idea what's wrong. Crash: These are my tabs, in the main class. public static final CreativeTabs tab = new CreativeTabs("tab") { @SideOnly(Side.CLIENT) public Item getTabIconItem() { return Item.getItemFromBlock(WLBlocks.flower_lavender); } }; public static final CreativeTabs tab2 = new CreativeTabs("tab2") { @SideOnly(Side.CLIENT) public Item getTabIconItem() { return Extras.backpack; } };
  16. I've been trying all day to get this mod to work for a server (it works fine in SP) but during startup it crashed with this: I've read that crash happens when trying to load a client mod on a server, but this is not a client mod since it adds items. The line it points to isn't doing anything except loading the texture. Class with the error: public class Jetpack extends ItemArmor { int delay = 0; public static Tab tab = Gadgets.tab; public Jetpack(ArmorMaterial material, int renderIndex, int armourType) { super(material, renderIndex, armourType); this.setCreativeTab(tab); this.canRepair = true; if(armourType == 1) { this.setTextureName(Tools.location("jetpack")); } } @Override public String getArmorTexture(ItemStack stack, Entity entity, int slot, String layer) { if(stack.getItem().equals(Gadgets.jetpack)) { return Tools.location("textures/items/jetpackWorn.png"); } else { return null; } } public boolean hasFuel(EntityPlayer player) { return player.inventory.hasItem(Items.coal); } public void consumeFuel(EntityPlayer player, int rate) { this.delay += 1; if (this.delay > rate) { if (player.inventory.hasItem(Items.coal)) { player.inventory.consumeInventoryItem(Items.coal); } this.delay = 0; } } @Override public void onArmorTick(World world, EntityPlayer player, ItemStack stack) { if (player == null) { return; } ItemStack item = player.inventory.armorItemInSlot(2); if (item != null) { if ((item.getItem() instanceof Jetpack)) { ((Jetpack)item.getItem()).action(player, (int)player.posX, (int)player.posY, (int)player.posZ, true); } } } public void action(EntityPlayer player, int x, int y, int z, boolean key) { Random rand = new Random(); double velx = rand.nextDouble() * 0.05D - 0.025D; double vely = -0.2D; double velz = rand.nextDouble() * 0.05D - 0.025D; if ((Keyboard.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindJump.getKeyCode())) && (hasFuel(player))) { player.motionY = 0.1D; player.jumpMovementFactor = 0.05F; player.worldObj.spawnParticle("flame", player.posX, player.posY-1, player.posZ, velx, vely, velz); player.worldObj.spawnParticle("largesmoke", player.posX, player.posY-1, player.posZ, velx, vely, velz); consumeFuel(player, 10); } if(hasFuel(player)) { player.fallDistance = 0.0F; } } } Main class: @Mod(modid = Gadgets.MODID, version = Gadgets.VERSION) public class Gadgets { public static final String MODID = "gadgets"; public static final String VERSION = "1.0"; @Instance(MODID) public static Gadgets instance; @SidedProxy(clientSide = "apocalypse.gadgets.network.Client", serverSide = "apocalypse.gadgets.network.Server") public static Server server; public static final Tab tab = new Tab("tab"); public static int backpackID = 1; public static Item jetpack, backpack, handgun, bomb, bullet, bullet2, heart; public static Item harbinger, halsSword, swordOfAeons; public static Block bin; @EventHandler public void preInit(FMLPreInitializationEvent event) { server.registerEntityRenderers(); server.registerEvents(); server.registerTiles(); jetpack = new Jetpack(ArmorMaterial.IRON, 4, 1).setUnlocalizedName("jetpack").setTextureName(Tools.location("jetpack")).setCreativeTab(tab); GameRegistry.registerItem(jetpack, "jetpack"); backpack = new Backpack().setUnlocalizedName("backpack").setTextureName(Tools.location("backpack")).setCreativeTab(tab); GameRegistry.registerItem(backpack, "backpack"); handgun = new Handgun().setUnlocalizedName("handgun").setTextureName(Tools.location("handgun")).setCreativeTab(tab); GameRegistry.registerItem(handgun, "handgun"); bomb = new Bomb().setUnlocalizedName("bomb").setTextureName(Tools.location("bomb")).setCreativeTab(tab); GameRegistry.registerItem(bomb, "bomb"); bullet = new Item().setUnlocalizedName("bullet").setTextureName(Tools.location("bullet")).setCreativeTab(tab); GameRegistry.registerItem(bullet, "bullet"); bullet2 = new Item().setUnlocalizedName("bullet2").setTextureName(Tools.location("bullet2")); GameRegistry.registerItem(bullet2, "bullet2"); heart = new Item().setUnlocalizedName("heart").setTextureName(Tools.location("heart")).setCreativeTab(tab); GameRegistry.registerItem(heart, "heart"); harbinger = new Sword("", 600, 8, true, true, Items.emerald, false).setUnlocalizedName("harbinger").setTextureName(Tools.location("harbinger")).setCreativeTab(tab); GameRegistry.registerItem(harbinger, "harbinger"); halsSword = new EnergySword("", 20, 30, true, false, null, true).setUnlocalizedName("halsSword").setTextureName(Tools.location("halsSword")).setCreativeTab(tab); GameRegistry.registerItem(halsSword, "halsSword"); swordOfAeons = new Sword("", 2000, 10, true, true, Items.nether_star, false).setUnlocalizedName("swordOfAeons").setTextureName(Tools.location("swordOfAeons")).setCreativeTab(tab); GameRegistry.registerItem(swordOfAeons, "swordOfAeons"); bin = new TrashBin().setBlockName("bin").setBlockTextureName(Tools.location("bin")).setCreativeTab(tab); GameRegistry.registerBlock(bin, "bin"); GameRegistry.addShapedRecipe(new ItemStack(Gadgets.swordOfAeons), new Object[]{"A ", " B ", " B",'A', Gadgets.harbinger,'B', Items.nether_star,}); GameRegistry.addShapedRecipe(new ItemStack(Gadgets.jetpack), new Object[]{"ABA", "ADA", "CAC",'A', Items.iron_ingot,'B', Items.redstone,'C', Items.blaze_rod,'D', Items.gunpowder}); GameRegistry.addShapedRecipe(new ItemStack(Gadgets.backpack), new Object[]{"AAA", "A A", "AAA",'A', Items.leather}); GameRegistry.addShapedRecipe(new ItemStack(Gadgets.bomb), new Object[]{"AAB", "ACA", "AAA",'A', Items.iron_ingot,'B', Items.string,'C', Items.gunpowder}); GameRegistry.addShapedRecipe(new ItemStack(Gadgets.handgun), new Object[]{"AAB", " CA", " A",'A', Items.iron_ingot,'B', Blocks.lever,'C', Blocks.tripwire_hook}); GameRegistry.addShapedRecipe(new ItemStack(Gadgets.bin), new Object[]{"ABA", "A A", "AAA",'A', Items.iron_ingot,'B', Blocks.trapdoor}); GameRegistry.addSmelting(Items.iron_ingot, new ItemStack(Gadgets.bullet, 3), 0F); int id = Config.getEntityIdStart(); EntityRegistry.registerModEntity(EntityBomb.class, "Bomb", id++, Gadgets.instance, 64, 10, true); EntityRegistry.registerModEntity(ProjectileBullet.class, "Bullet", id++, Gadgets.instance, 64, 10, true); } @EventHandler public void init(FMLInitializationEvent event) { PacketHandler.initPackets(); NetworkRegistry.INSTANCE.registerGuiHandler(instance, server); } @EventHandler public void postInit(FMLPostInitializationEvent event) { MinecraftForge.addGrassSeed(new ItemStack(Gadgets.heart), 1); ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST).addItem(new WeightedRandomChestContent(new ItemStack(Gadgets.bomb), 1, 2, 3)); ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST).addItem(new WeightedRandomChestContent(new ItemStack(Gadgets.bullet), 1, 6, 6)); ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST).addItem(new WeightedRandomChestContent(new ItemStack(Gadgets.harbinger), 1, 1, 1)); ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST).addItem(new WeightedRandomChestContent(new ItemStack(Gadgets.halsSword), 1, 1, 1)); } } Why is this happening?
  17. I redid the whole pet structure and got it to work by just adding setHealth(defaultHealth); at the end of the constructor. But now it doesn't follow the player (still teleports when moving away, but doesn't follow) and its only movement is when it jumps to attack a mob. Its speed is also 0.30000001192092896F like the Wolf instead of the very first variable which is clearly 0.3.... New cat class: public class PetCat extends UniversalPet { public float speed = 0.3; public float defaultHealth = 6; public float tamedHealth = 25; public float defaultDamage = 4; public float tamedDamage = 6; public float eyeHeight = 0.7F; public boolean isEvolved = false; public PetCat(World world) { super(world); this.breedingItem = Items.fish; this.befriendingItem = BPItems.ball_of_yarn; this.healingItem = BPItems.tuna; this.droppedItem = BPItems.cat_tail; this.setSize(0.5F, 0.7F); this.getNavigator().setAvoidsWater(true); this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityWolf.class, 200, false)); this.tasks.addTask(1, new EntityAISwimming(this)); this.tasks.addTask(2, this.aiSit); this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F)); this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true)); this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); this.tasks.addTask(6, new EntityAIMate(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new BegUniversal(this, 8.0F)); this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(9, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false)); this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityWolf.class, 200, false)); //this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityInsect.class, 200, false)); //this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, Mouse.class, 200, false)); this.setTamed(false); this.setHealth(defaultHealth); this.printEntityData("Cat"); } public void printEntityData(String name) { Tools.println("[printEntityData()]:"); Tools.println( "'" + name + "' mob spawned."); Tools.println("Breeding item: " + breedingItem.getUnlocalizedName()); Tools.println("Befriending item: " + befriendingItem.getUnlocalizedName()); Tools.println("Healing item: " + healingItem.getUnlocalizedName()); Tools.println("Dropped item: " + droppedItem.getUnlocalizedName()); Tools.println("Eye height: " + eyeHeight); Tools.println("Speed: " + speed); Tools.println("Damage when tamed: " + tamedDamage); Tools.println("Damage when wild: " + defaultDamage); Tools.println("Health when tamed: " + tamedHealth); Tools.println("Health when wild: " + defaultHealth); Tools.println("Current health: " + this.getHealth()); } protected void applyEntityAttributes() { super.applyEntityAttributes(); Tools.println("[applyEntityAttributes()]:"); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(speed); Tools.println("Speed set to: " + this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue()); if (this.isTamed()) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(tamedHealth); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(defaultHealth); } Tools.println("Max health set to: " + this.getEntityAttribute(SharedMonsterAttributes.maxHealth).getAttributeValue()); } public boolean isAIEnabled() { return true; } public void setAttackTarget(EntityLivingBase p_70624_1_) { super.setAttackTarget(p_70624_1_); if (p_70624_1_ == null) { this.setAngry(false); } else if (!this.isTamed()) { this.setAngry(true); } } protected void updateAITick() { this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth())); } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(18, new Float(this.getHealth())); this.dataWatcher.addObject(19, new Byte((byte)0)); } public void writeEntityToNBT(NBTTagCompound p_70014_1_) { super.writeEntityToNBT(p_70014_1_); p_70014_1_.setBoolean("Angry", this.isAngry()); } public void readEntityFromNBT(NBTTagCompound p_70037_1_) { super.readEntityFromNBT(p_70037_1_); this.setAngry(p_70037_1_.getBoolean("Angry")); } protected Item getDropItem() { return this.droppedItem; } public void onUpdate() { super.onUpdate(); if (this.func_70922_bv()) { this.numTicksToChaseTarget = 10; } } public float getEyeHeight() { return this.height * eyeHeight; } public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (this.isEntityInvulnerable()) { return false; } else { Entity entity = p_70097_1_.getEntity(); this.aiSit.setSitting(false); if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow)) { p_70097_2_ = (p_70097_2_ + 1.0F) / 2.0F; } return super.attackEntityFrom(p_70097_1_, p_70097_2_); } } public boolean attackEntityAsMob(Entity p_70652_1_) { float i = this.isTamed() ? defaultDamage : tamedDamage; return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), i); } public void setTamed(boolean p_70903_1_) { super.setTamed(p_70903_1_); if (p_70903_1_) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(tamedHealth); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(defaultHealth); } } public boolean interact(EntityPlayer p_70085_1_) { ItemStack itemstack = p_70085_1_.inventory.getCurrentItem(); if (this.isTamed()) { if (itemstack != null) { if (itemstack.getItem() instanceof ItemFood) { ItemFood itemfood = (ItemFood)itemstack.getItem(); if (itemfood == healingItem && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } this.heal((float)itemfood.func_150905_g(itemstack)); if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } return true; } } } if (this.func_152114_e(p_70085_1_) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack)) { this.aiSit.setSitting(!this.isSitting()); this.isJumping = false; this.setPathToEntity((PathEntity)null); this.setTarget((Entity)null); this.setAttackTarget((EntityLivingBase)null); } } else if (itemstack != null && itemstack.getItem() == befriendingItem && !this.isAngry()) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } if (!this.worldObj.isRemote) { if (this.rand.nextInt(3) == 0) { this.setTamed(true); this.setPathToEntity((PathEntity)null); this.setAttackTarget((EntityLivingBase)null); this.aiSit.setSitting(true); this.setHealth(20.0F); this.func_152115_b(p_70085_1_.getUniqueID().toString()); this.playTameEffect(true); this.worldObj.setEntityState(this, (byte)7); } else { this.playTameEffect(false); this.worldObj.setEntityState(this, (byte)6); } } return true; } return super.interact(p_70085_1_); } public boolean isBreedingItem(ItemStack p_70877_1_) { return p_70877_1_ == null ? false : (!(p_70877_1_.getItem() == breedingItem) ? false : ((ItemFood)p_70877_1_.getItem()).isWolfsFavoriteMeat()); } public int getMaxSpawnedInChunk() { return 5; } public boolean isAngry() { return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0; } public void setAngry(boolean p_70916_1_) { byte b0 = this.dataWatcher.getWatchableObjectByte(16); if (p_70916_1_) { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2))); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3))); } } public void func_70918_i(boolean p_70918_1_) { if (p_70918_1_) { this.dataWatcher.updateObject(19, Byte.valueOf((byte)1)); } else { this.dataWatcher.updateObject(19, Byte.valueOf((byte)0)); } } public boolean func_70922_bv() { return this.dataWatcher.getWatchableObjectByte(19) == 1; } protected boolean canDespawn() { return !this.isTamed() && this.ticksExisted > 2400; } public boolean func_142018_a(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_) { if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast)) { if (p_142018_1_ instanceof EntityTameable) { EntityTameable pet = (EntityTameable)p_142018_1_; if (pet.isTamed() && pet.getOwner() == p_142018_2_) { return false; } } return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer && !((EntityPlayer)p_142018_2_).canAttackPlayer((EntityPlayer)p_142018_1_) ? false : !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse)p_142018_1_).isTame(); } else { return false; } } @Override public void setDead() { super.setDead(); } public boolean canMateWith(EntityAnimal p_70878_1_) { if (p_70878_1_ == this) {return false;} else if (!this.isTamed()) {return false;} else if (!(p_70878_1_ instanceof PetCat)) {return false;} else { PetCat thisPet = (PetCat)p_70878_1_; return !thisPet.isTamed() ? false : (thisPet.isSitting() ? false : this.isInLove() && thisPet.isInLove()); } } protected String getLivingSound() { return this.isTamed() ? (this.isInLove() ? "mob.cat.purr" : (this.rand.nextInt(4) == 0 ? "mob.cat.purreow" : "mob.cat.meow")) : ""; } protected String getHurtSound() {return "mob.cat.hitt";} protected String getDeathSound() {return "mob.cat.hitt";} @Override public PetCat createChild(EntityAgeable p_90011_1_) { PetCat cat = new PetCat(this.worldObj); String s = this.func_152113_b(); if (s != null && s.trim().length() > 0) { cat.func_152115_b(s); cat.setTamed(true); } return cat; } public static void createEntity(Class entityClass, String entityName, int solidColour, int spotColour) { int id = EntityRegistry.findGlobalUniqueEntityId(); EntityRegistry.registerGlobalEntityID(entityClass, entityName, id); EntityRegistry.registerModEntity(entityClass, entityName, id, Main.instance, 64, 1, true); EntityList.entityEggs.put(Integer.valueOf(id), new EntityList.EntityEggInfo(id, solidColour, spotColour)); } } New pet class, made just so the Beg AI can be used for all pets: public class UniversalPet extends EntityTameable { public Item breedingItem; public Item befriendingItem; public Item healingItem; public Item droppedItem; public UniversalPet(World p_i1696_1_) { super(p_i1696_1_); this.setTamed(false); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(2); if (this.isTamed()) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(10); } } public void func_70918_i(boolean p_70918_1_) { if (p_70918_1_) { this.dataWatcher.updateObject(19, Byte.valueOf((byte)1)); } else { this.dataWatcher.updateObject(19, Byte.valueOf((byte)0)); } } @Override public EntityAgeable createChild(EntityAgeable p_90011_1_) { return null; } }
  18. I had already tried doing that and, unfortunately, it still doesn't work...
  19. The problem is that the applyEntityAttributes method is called before any of the variables are set in Cat's constructor. The constructor recognises the correct variables but applyEntityAttributes thinks they're still 0. Applying the attributes from the Cat class instead of EntityPet doesn't have any effect, neither does doing anything with setDead()... How do I get applyEntityAttributes() to read the variables AFTER they've been set ?
  20. I have a generic EntityPet class that's basically copied EntityWolf code. It has a bunch of variables like health and damage that I want to set in the classes that extend it so the code in those new classes is shorter and easier to edit. But when my Cat mob is spawned, it just immediately rolls over and dies while printing the following log. Why is its health 0 if its attributes are set correctly? [16:43:27] [Client thread/INFO] [LOG]: 'Cat' mob spawned with the following attributes: [16:43:27] [Client thread/INFO] [LOG]: Breeding item: item.fish [16:43:27] [Client thread/INFO] [LOG]: Befriending item: item.ball_of_yarn [16:43:27] [Client thread/INFO] [LOG]: Healing item: item.tuna [16:43:27] [Client thread/INFO] [LOG]: Dropped item: item.cat_tail [16:43:27] [Client thread/INFO] [LOG]: Eye height: 0.7 [16:43:27] [Client thread/INFO] [LOG]: Speed: 0.30000001192092896 [16:43:27] [Client thread/INFO] [LOG]: Damage when tamed: 6.0 [16:43:27] [Client thread/INFO] [LOG]: Damage when wild: 4.0 [16:43:27] [Client thread/INFO] [LOG]: Health when tamed: 25.0 [16:43:27] [Client thread/INFO] [LOG]: Health when wild: 6.0 [16:43:27] [Client thread/INFO] [LOG]: Current health: 0.0 Cat class: public class Cat extends EntityPet { public Cat(World world) { super(world); this.setSize(0.5F, 0.7F); this.getNavigator().setAvoidsWater(true); this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityWolf.class, 200, false)); //this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityInsect.class, 200, false)); //this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, Mouse.class, 200, false)); this.breedingItem = Items.fish; this.befriendingItem = BPItems.ball_of_yarn; this.healingItem = BPItems.tuna; this.droppedItem = BPItems.cat_tail; this.eyeHeight = 0.7F; this.speed = 0.3F; this.tamedDamage = 6; this.defaultDamage = 4; this.defaultHealth = 6; this.tamedHealth = 25; this.printEntityData("Cat"); } public boolean canMateWith(EntityAnimal p_70878_1_) { if (p_70878_1_ == this) {return false;} else if (!this.isTamed()) {return false;} else if (!(p_70878_1_ instanceof Cat)) {return false;} else { Cat thisPet = (Cat)p_70878_1_; return !thisPet.isTamed() ? false : (thisPet.isSitting() ? false : this.isInLove() && thisPet.isInLove()); } } protected String getLivingSound() { return this.isTamed() ? (this.isInLove() ? "mob.cat.purr" : (this.rand.nextInt(4) == 0 ? "mob.cat.purreow" : "mob.cat.meow")) : ""; } protected String getHurtSound() {return "mob.cat.hitt";} protected String getDeathSound() {return "mob.cat.hitt";} @Override public Cat createChild(EntityAgeable p_90011_1_) { Cat cat = new Cat(this.worldObj); String s = this.func_152113_b(); if (s != null && s.trim().length() > 0) { cat.func_152115_b(s); cat.setTamed(true); } return cat; } public static void createEntity(Class entityClass, String entityName, int solidColour, int spotColour) { int id = EntityRegistry.findGlobalUniqueEntityId(); EntityRegistry.registerGlobalEntityID(entityClass, entityName, id); EntityRegistry.registerModEntity(entityClass, entityName, id, Main.instance, 64, 1, true); EntityList.entityEggs.put(Integer.valueOf(id), new EntityList.EntityEggInfo(id, solidColour, spotColour)); } } EntityPet class public class EntityPet extends EntityTameable { public Item breedingItem, befriendingItem, healingItem, droppedItem; public double speed, defaultHealth, tamedHealth, damage; public float defaultDamage, tamedDamage, eyeHeight; public boolean isEvolved; public EntityPet(World p_i1696_1_) { super(p_i1696_1_); this.tasks.addTask(1, new EntityAISwimming(this)); this.tasks.addTask(2, this.aiSit); this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F)); this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true)); this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); this.tasks.addTask(6, new EntityAIMate(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new Beg(this, 8.0F)); this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(9, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false)); this.setTamed(false); isEvolved = false; } public void printEntityData(String name) { Tools.println("'" + name + "' mob spawned with the following attributes:"); Tools.println("Breeding item: " + breedingItem.getUnlocalizedName()); Tools.println("Befriending item: " + befriendingItem.getUnlocalizedName()); Tools.println("Healing item: " + healingItem.getUnlocalizedName()); Tools.println("Dropped item: " + droppedItem.getUnlocalizedName()); Tools.println("Eye height: " + eyeHeight); Tools.println("Speed: " + speed); Tools.println("Damage when tamed: " + tamedDamage); Tools.println("Damage when wild: " + defaultDamage); Tools.println("Health when tamed: " + tamedHealth); Tools.println("Health when wild: " + defaultHealth); Tools.println("Current health: " + this.getHealth()); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(speed); if (this.isTamed()) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(tamedHealth); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(defaultHealth); } } public boolean isAIEnabled() { return true; } public void setAttackTarget(EntityLivingBase p_70624_1_) { super.setAttackTarget(p_70624_1_); if (p_70624_1_ == null) { this.setAngry(false); } else if (!this.isTamed()) { this.setAngry(true); } } protected void updateAITick() { this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth())); } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(18, new Float(this.getHealth())); this.dataWatcher.addObject(19, new Byte((byte)0)); } public void writeEntityToNBT(NBTTagCompound p_70014_1_) { super.writeEntityToNBT(p_70014_1_); p_70014_1_.setBoolean("Angry", this.isAngry()); } public void readEntityFromNBT(NBTTagCompound p_70037_1_) { super.readEntityFromNBT(p_70037_1_); this.setAngry(p_70037_1_.getBoolean("Angry")); } protected Item getDropItem() { return this.droppedItem; } public void onUpdate() { super.onUpdate(); if (this.func_70922_bv()) { this.numTicksToChaseTarget = 10; } } public float getEyeHeight() { return this.height * eyeHeight; } public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (this.isEntityInvulnerable()) { return false; } else { Entity entity = p_70097_1_.getEntity(); this.aiSit.setSitting(false); if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow)) { p_70097_2_ = (p_70097_2_ + 1.0F) / 2.0F; } return super.attackEntityFrom(p_70097_1_, p_70097_2_); } } public boolean attackEntityAsMob(Entity p_70652_1_) { float i = this.isTamed() ? defaultDamage : tamedDamage; return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), i); } public void setTamed(boolean p_70903_1_) { super.setTamed(p_70903_1_); if (p_70903_1_) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(tamedHealth); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(defaultHealth); } } public boolean interact(EntityPlayer p_70085_1_) { ItemStack itemstack = p_70085_1_.inventory.getCurrentItem(); if (this.isTamed()) { if (itemstack != null) { if (itemstack.getItem() instanceof ItemFood) { ItemFood itemfood = (ItemFood)itemstack.getItem(); if (itemfood == healingItem && this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } this.heal((float)itemfood.func_150905_g(itemstack)); if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } return true; } } } if (this.func_152114_e(p_70085_1_) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack)) { this.aiSit.setSitting(!this.isSitting()); this.isJumping = false; this.setPathToEntity((PathEntity)null); this.setTarget((Entity)null); this.setAttackTarget((EntityLivingBase)null); } } else if (itemstack != null && itemstack.getItem() == befriendingItem && !this.isAngry()) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } if (!this.worldObj.isRemote) { if (this.rand.nextInt(3) == 0) { this.setTamed(true); this.setPathToEntity((PathEntity)null); this.setAttackTarget((EntityLivingBase)null); this.aiSit.setSitting(true); this.setHealth(20.0F); this.func_152115_b(p_70085_1_.getUniqueID().toString()); this.playTameEffect(true); this.worldObj.setEntityState(this, (byte)7); } else { this.playTameEffect(false); this.worldObj.setEntityState(this, (byte)6); } } return true; } return super.interact(p_70085_1_); } public boolean isBreedingItem(ItemStack p_70877_1_) { return p_70877_1_ == null ? false : (!(p_70877_1_.getItem() == breedingItem) ? false : ((ItemFood)p_70877_1_.getItem()).isWolfsFavoriteMeat()); } public int getMaxSpawnedInChunk() { return 5; } public boolean isAngry() { return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0; } public void setAngry(boolean p_70916_1_) { byte b0 = this.dataWatcher.getWatchableObjectByte(16); if (p_70916_1_) { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2))); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3))); } } public void func_70918_i(boolean p_70918_1_) { if (p_70918_1_) { this.dataWatcher.updateObject(19, Byte.valueOf((byte)1)); } else { this.dataWatcher.updateObject(19, Byte.valueOf((byte)0)); } } public boolean func_70922_bv() { return this.dataWatcher.getWatchableObjectByte(19) == 1; } protected boolean canDespawn() { return !this.isTamed() && this.ticksExisted > 2400; } public boolean func_142018_a(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_) { if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast)) { if (p_142018_1_ instanceof EntityPet) { EntityPet entitywolf = (EntityPet)p_142018_1_; if (entitywolf.isTamed() && entitywolf.getOwner() == p_142018_2_) { return false; } } return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer && !((EntityPlayer)p_142018_2_).canAttackPlayer((EntityPlayer)p_142018_1_) ? false : !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse)p_142018_1_).isTame(); } else { return false; } } @Override public EntityAgeable createChild(EntityAgeable p_90011_1_) { return null; } }
  21. My first problem is that when I use an item on the entity that's meant to add 1 to its health multiplier, it adds 2. My second problem is that the entity won't follow the player because it won't recognise the player as its owner. Cat: public class Cat extends EntityPet { public Cat(World world) { super(world); this.setSize(0.6F, 0.8F); this.getNavigator().setAvoidsWater(true); this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntityWolf.class, 200, false)); this.breedingItem = Items.fish; this.befriendingItem = BPItems.ball_of_yarn; this.healingItem = BPItems.tuna; this.eyeHeight = 0.8F; this.tamedDamage = 6; this.baseDamage = 4; this.minHealth = 6; this.newHealth = 25; } public boolean canMateWith(EntityAnimal p_70878_1_) { if (p_70878_1_ == this) { return false; } else if (!this.isTamed()) { return false; } else if (!(p_70878_1_ instanceof Cat)) { return false; } else { Cat thisPet = (Cat)p_70878_1_; return !thisPet.isTamed() ? false : (thisPet.isSitting() ? false : this.isInLove() && thisPet.isInLove()); } } protected String getLivingSound() { return this.isTamed() ? (this.isInLove() ? "mob.cat.purr" : (this.rand.nextInt(4) == 0 ? "mob.cat.purreow" : "mob.cat.meow")) : ""; } protected String getHurtSound() { return "mob.cat.hitt"; } protected String getDeathSound() { return "mob.cat.hitt"; } protected Item getDropItem() { return BPItems.cat_tail; } public boolean attackEntityAsMob(Entity p_70652_1_) { return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), 3.0F); } public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (this.isEntityInvulnerable()) { return false; } else { this.aiSit.setSitting(false); return super.attackEntityFrom(p_70097_1_, p_70097_2_); } } @Override public Cat createChild(EntityAgeable p_90011_1_) { Cat cat = new Cat(this.worldObj); String s = this.func_152113_b(); if (s != null && s.trim().length() > 0) { cat.func_152115_b(s); cat.setTamed(true); } return cat; } @Override public void readEntityFromNBT(NBTTagCompound nbt) { super.readEntityFromNBT(nbt); healthMultiplier = nbt.getInteger("Health Multiplier"); damageMultiplier = nbt.getInteger("Damage Multiplier"); } @Override public void writeEntityToNBT(NBTTagCompound nbt) { super.readEntityFromNBT(nbt); nbt.setInteger("Health Multiplier", this.healthMultiplier); nbt.setInteger("Damage Multiplier", this.damageMultiplier); } public static void createEntity(Class entityClass, String entityName, int solidColour, int spotColour) { int id = EntityRegistry.findGlobalUniqueEntityId(); Tools.println("Attempting to register 'Cat' entity."); Tools.println("Class: " + entityClass.getCanonicalName() + "."); Tools.println("Name: " + entityName + "."); Tools.println("Egg Colour: " + Integer.toString(solidColour) + "."); Tools.println("Egg Colour: " + Integer.toString(spotColour) + "."); Tools.println("Instance: " + Main.instance.toString() + "."); EntityRegistry.registerGlobalEntityID(entityClass, entityName, id); EntityRegistry.registerModEntity(entityClass, entityName, id, Main.instance, 64, 1, true); EntityList.entityEggs.put(Integer.valueOf(id), new EntityList.EntityEggInfo(id, solidColour, spotColour)); } } EntityPet: public class EntityPet extends EntityTameable { public static Item breedingItem, befriendingItem, healingItem; public static double minHealth, newHealth, speed, strength; public static float eyeHeight, scale; public static int baseDamage, tamedDamage, damageMultiplier = 0, healthMultiplier = 0; public EntityPet(World p_i1696_1_) { super(p_i1696_1_); this.tasks.addTask(1, new EntityAISwimming(this)); this.tasks.addTask(2, this.aiSit); this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F)); this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true)); this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 10.0F, 2.0F)); this.tasks.addTask(6, new EntityAIMate(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new Beg(this, 8.0F)); this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(9, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this)); this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this)); this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true)); this.setTamed(false); } public static void scale() { if(healthMultiplier == 3 && damageMultiplier == 3) { scale = 1.2F; } else { scale = 1F; } } public static Item getBreedingItem() { return breedingItem; } public static Item getBefriendingItem() { return befriendingItem; } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(speed); if (this.isTamed()) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(newHealth + (healthMultiplier * 2)); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(minHealth); } } public boolean isAIEnabled() { return true; } public void setAttackTarget(EntityLivingBase p_70624_1_) { super.setAttackTarget(p_70624_1_); if (p_70624_1_ == null) { this.setAngry(false); } else if (!this.isTamed()) { this.setAngry(true); } } /** * main AI tick function, replaces updateEntityActionState */ protected void updateAITick() { this.dataWatcher.updateObject(18, Float.valueOf(this.getHealth())); } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(18, new Float(this.getHealth())); this.dataWatcher.addObject(19, new Byte((byte)0)); } protected String getLivingSound() { return this.isAngry() ? "mob.wolf.growl" : (this.rand.nextInt(3) == 0 ? (this.isTamed() && this.dataWatcher.getWatchableObjectFloat(18) < 10.0F ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark"); } protected float getSoundVolume() { return 0.4F; } public float getEyeHeight() { return this.height * eyeHeight; } public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) { if (this.isEntityInvulnerable()) { return false; } else { Entity entity = p_70097_1_.getEntity(); this.aiSit.setSitting(false); if (entity != null && !(entity instanceof EntityPlayer) && !(entity instanceof EntityArrow)) { p_70097_2_ = (p_70097_2_ + 1.0F) / 2.0F; } return super.attackEntityFrom(p_70097_1_, p_70097_2_); } } public boolean attackEntityAsMob(Entity p_70652_1_) { int i = this.isTamed() ? (tamedDamage * damageMultiplier) : baseDamage; return p_70652_1_.attackEntityFrom(DamageSource.causeMobDamage(this), (float)i); } public void setTamed(boolean p_70903_1_) { super.setTamed(p_70903_1_); if (p_70903_1_) { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(newHealth); } else { this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(minHealth); } } public boolean interact(EntityPlayer p_70085_1_) { ItemStack itemstack = p_70085_1_.inventory.getCurrentItem(); if (this.isTamed()) { if (itemstack != null) { if (itemstack.getItem() == BPItems.damageEnhancer) { if(this.damageMultiplier < 3) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } damageMultiplier += 1; Tools.println("Increased pet's damage multiplier to " + damageMultiplier); if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } return true; } }if (itemstack.getItem() == BPItems.healthEnhancer) { if(this.healthMultiplier < 3) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } healthMultiplier += 1; Tools.println("Increased pet's health multiplier to " + healthMultiplier); if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } return true; } } if (itemstack.getItem() == healingItem) { ItemFood itemfood = (ItemFood)itemstack.getItem(); if (this.dataWatcher.getWatchableObjectFloat(18) < 20.0F) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } this.heal((float)itemfood.func_150905_g(itemstack)); if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } return true; } } } if (this.func_152114_e(p_70085_1_) && !this.worldObj.isRemote && !this.isBreedingItem(itemstack)) { this.aiSit.setSitting(!this.isSitting()); this.isJumping = false; this.setPathToEntity((PathEntity)null); this.setTarget((Entity)null); this.setAttackTarget((EntityLivingBase)null); } } else if (itemstack != null && itemstack.getItem() == befriendingItem && !this.isAngry()) { if (!p_70085_1_.capabilities.isCreativeMode) { --itemstack.stackSize; } if (itemstack.stackSize <= 0) { p_70085_1_.inventory.setInventorySlotContents(p_70085_1_.inventory.currentItem, (ItemStack)null); } if (!this.worldObj.isRemote) { if (this.rand.nextInt(3) == 0) { this.setTamed(true); Tools.println("This is now a pet!"); if(this.getOwner() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)this.getOwner(); Tools.println("The owner is " + player.getDisplayName()); } else { Tools.println("Owner unknown."); } this.setPathToEntity((PathEntity)null); this.setAttackTarget((EntityLivingBase)null); this.aiSit.setSitting(true); this.setHealth(20.0F); this.func_152115_b(p_70085_1_.getUniqueID().toString()); this.playTameEffect(true); this.worldObj.setEntityState(this, (byte)7); } else { this.playTameEffect(false); this.worldObj.setEntityState(this, (byte)6); } } return true; } return super.interact(p_70085_1_); } public boolean isBreedingItem(ItemStack stack) { if(stack.getItem() == breedingItem) { return true; } return false; } public int getMaxSpawnedInChunk() { return 8; } public boolean isAngry() { return (this.dataWatcher.getWatchableObjectByte(16) & 2) != 0; } public void setAngry(boolean p_70916_1_) { byte b0 = this.dataWatcher.getWatchableObjectByte(16); if (p_70916_1_) { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 2))); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -3))); } } public void func_70918_i(boolean p_70918_1_) { if (p_70918_1_) { this.dataWatcher.updateObject(19, Byte.valueOf((byte)1)); } else { this.dataWatcher.updateObject(19, Byte.valueOf((byte)0)); } } public boolean func_70922_bv() { return this.dataWatcher.getWatchableObjectByte(19) == 1; } protected boolean canDespawn() { return !this.isTamed() && this.ticksExisted > 2400; } public boolean func_142018_a(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_) { if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast)) { if (p_142018_1_ instanceof EntityPet) { EntityPet pet = (EntityPet)p_142018_1_; if (pet.isTamed() && pet.getOwner() == p_142018_2_) { return false; } } return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer && !((EntityPlayer)p_142018_2_).canAttackPlayer((EntityPlayer)p_142018_1_) ? false : !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse)p_142018_1_).isTame(); } else { return false; } } @Override public EntityAgeable createChild(EntityAgeable p_90011_1_) { return null; } }
  22. Is there any way to customise what's printed in the server/Eclipse console? Like instead of displaying this: [sTDOUT]: [apocalypse.fandomcraft.structures.DungeonDekuTree:generateSurface:1088]: Successfully built a forest dungeon at (291, 75, 529) ...have it display as this?: [FandomCraft]: Successfully built a forest dungeon at (291, 75, 529) I've tried looking through the Vanilla/Forge classes but can't find where they do it.
  23. I'm trying to make new iron bars that can connect to my own blocks. I can't use rusty_iron_bars = new BlockPane(); because the constructor is protected. I can't make my own new pane class because that loses access to the rendering. I tried making a class that extends BlockPane, but canPaneConnectToBlock can't be overridden so I can't change that method to add my own blocks. Is there any way of doing this?
×
×
  • Create New...

Important Information

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