Jump to content

JimiIT92

Members
  • Posts

    867
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JimiIT92

  1. Ok, so i've done this try { Field damage = RenderGlobal.class.getDeclaredField("damagedBlocks"); damage.setAccessible(true); System.out.println(damage.get(0)); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } But now every tick i get this [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: java.lang.IllegalArgumentException: Can not set final java.util.Map field net.minecraft.client.renderer.RenderGlobal.damagedBlocks to java.lang.Integer [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(Unknown Source) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.get(Unknown Source) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at java.lang.reflect.Field.get(Unknown Source) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at blaze.blocks.BlockCoalBlock.getActualState(BlockCoalBlock.java:65) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.block.Block.isSideSolid(Block.java:1295) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.block.Block.canCreatureSpawn(Block.java:1585) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.world.SpawnerAnimals.canCreatureTypeSpawnAtLocation(SpawnerAnimals.java:237) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.world.SpawnerAnimals.findChunksForSpawning(SpawnerAnimals.java:152) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.world.WorldServer.tick(WorldServer.java:206) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:763) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [15:25:20] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:-1]: at java.lang.Thread.run(Unknown Source) this is called from the system out, where i do "damage.get(0)"
  2. I don't know how to use field instead of reflection to access specific private values. I know that using this Field[] fields = RenderGlobal.class.getFields(); System.out.println(fields.length); it gives me the fields of a class but the system out return 0 (so is not returning anything at all). How can i access the damagedBlocks value using field?
  3. Infact i see that when i place any block it calls taht method (and it always return null), so how to change this? How to use Field to get that value?
  4. Ok, so i've done what you said but now i give this error java.lang.IllegalArgumentException: Don't know how to convert null[damage=0] back into data... at net.minecraft.block.Block.getMetaFromState(Block.java:272) at net.minecraft.block.Block.setHarvestLevel(Block.java:2201) at net.minecraft.block.Block.setHarvestLevel(Block.java:2183) at blaze.blocks.BlockCoalBlock.<init>(BlockCoalBlock.java:40) at blaze.core.BLBlocks.addBlocks(BLBlocks.java:108) at blaze.core.BL.preInit(BL.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:536) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:187) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:514) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:243) at net.minecraft.client.Minecraft.startGame(Minecraft.java:446) at net.minecraft.client.Minecraft.run(Minecraft.java:356) at net.minecraft.client.main.Main.main(Main.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) I see is related to the getMetaFromState method (wich you told me to not add it), so how can i fix that? This is the updated block class package blaze.blocks; import java.util.Random; import blaze.core.BLItems; import blaze.items.ItemHammer; import blaze.tileentities.TileEntityCoalBlock; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderGlobal; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.ReflectionHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockCoalBlock extends Block{ public static Item drop; public static final PropertyInteger DAMAGE = PropertyInteger.create("damage", 0, 10); public BlockCoalBlock() { super(Material.rock); this.setCreativeTab(CreativeTabs.tabBlock); this.setDefaultState(this.blockState.getBaseState().withProperty(DAMAGE, Integer.valueOf(0))); this.setHarvestLevel("pickaxe", 0); this.setHardness(3.0F); this.setResistance(15.0F); } /** * Get the actual Block state of this Block at the given position. This applies properties not visible in the * metadata, such as fence connections. */ @Override @SideOnly(Side.CLIENT) public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) { IBlockState newState = state; RenderGlobal render = Minecraft.getMinecraft().renderGlobal; int damage = ReflectionHelper.getPrivateValue(RenderGlobal.class, render, 21); System.out.println(damage); return newState; } @SideOnly(Side.CLIENT) public Item getItem(World worldIn, BlockPos pos) { return Item.getItemFromBlock(this); } /** * Get the Item that this Block should drop when harvested. * * @param fortune the level of the Fortune enchantment on the player's tool */ public Item getItemDropped(IBlockState state, Random rand, int fortune) { return drop == null ? Item.getItemFromBlock(this) : drop; } public static Item setItemToDrop(EntityPlayer player, World world, BlockPos pos) { Block down = world.getBlockState(pos.down()).getBlock(); Item item = player.getHeldItem().getItem(); if(item instanceof ItemHammer && down.equals(Blocks.anvil)) { drop = BLItems.carbon; } else { drop = null; } return null; } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {DAMAGE}); } }
  5. Thank you, i've change the isInGround function to this public boolean isInGround() { return ReflectionHelper.getPrivateValue(EntityArrow.class, this, 5); } and it's still working, so i think i'll leave this Thanks really much for your help and explanations, i only i could i'll give you more than one thank you
  6. Using reflection i think is the best way, so if i want to use it where should i put that code (i mean where should i set the onGround value)?
  7. Ok, this is my class for custom sapling public class BlockCorruptedSapling extends BlockBush implements IGrowable { public static final PropertyEnum TYPE = PropertyEnum.create("type", BlockCorruptedWood.EnumType.class); public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1); public BlockCorruptedSapling() { this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, BlockCorruptedWood.EnumType.NORMAL).withProperty(STAGE, Integer.valueOf(0))); this.setTickRandomly(true); } public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { super.updateTick(worldIn, pos, state, rand); if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0) { this.grow(worldIn, pos, state, rand); } } } public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (((Integer)state.getValue(STAGE)).intValue() == 0) { worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4); } else { this.generateTree(worldIn, pos, state, rand); } } public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return; Object object = rand.nextInt(10) == 0 ? new WorldGenBigCorruptedTree(true) : new WorldGenCorruptedTree(true); int i = 0; int j = 0; boolean flag = false; IBlockState iblockstate1 = Blocks.air.getDefaultState(); if (flag) { worldIn.setBlockState(pos.add(i, 0, j), iblockstate1, 4); worldIn.setBlockState(pos.add(i + 1, 0, j), iblockstate1, 4); worldIn.setBlockState(pos.add(i, 0, j + 1), iblockstate1, 4); worldIn.setBlockState(pos.add(i + 1, 0, j + 1), iblockstate1, 4); } else { worldIn.setBlockState(pos, iblockstate1, 4); } if (!((WorldGenerator)object).generate(worldIn, rand, pos.add(i, 0, j))) { if (flag) { worldIn.setBlockState(pos.add(i, 0, j), state, 4); worldIn.setBlockState(pos.add(i + 1, 0, j), state, 4); worldIn.setBlockState(pos.add(i, 0, j + 1), state, 4); worldIn.setBlockState(pos.add(i + 1, 0, j + 1), state, 4); } else { worldIn.setBlockState(pos, state, 4); } } } /** * Check whether the given BlockPos has a Sapling of the given type */ public boolean isTypeAt(World worldIn, BlockPos pos, BlockCorruptedWood.EnumType type) { IBlockState iblockstate = worldIn.getBlockState(pos); return iblockstate.getBlock() == this && iblockstate.getValue(TYPE) == type; } /** * Get the damage value that this Block should drop */ public int damageDropped(IBlockState state) { return ((BlockCorruptedWood.EnumType)state.getValue(TYPE)).getMetadata(); } /** * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) */ @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { BlockCorruptedWood.EnumType[] aenumtype = BlockCorruptedWood.EnumType.values(); int i = aenumtype.length; for (int j = 0; j < i; ++j) { BlockCorruptedWood.EnumType enumtype = aenumtype[j]; list.add(new ItemStack(itemIn, 1, enumtype.getMetadata())); } } /** * Whether this IGrowable can grow */ public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) { return true; } public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state) { return (double)worldIn.rand.nextFloat() < 0.45D; } public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { this.grow(worldIn, pos, state, rand); } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(TYPE, BlockCorruptedWood.EnumType.byMetadata(meta & 7)).withProperty(STAGE, Integer.valueOf((meta & >> 3)); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { byte b0 = 0; int i = b0 | ((BlockCorruptedWood.EnumType)state.getValue(TYPE)).getMetadata(); i |= ((Integer)state.getValue(STAGE)).intValue() << 3; return i; } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {TYPE, STAGE}); } static final class SwitchEnumType { static final int[] WOOD_TYPE_LOOKUP = new int[blockCorruptedWood.EnumType.values().length]; static { try { WOOD_TYPE_LOOKUP[blockCorruptedWood.EnumType.NORMAL.ordinal()] = 0; } catch (NoSuchFieldError var6) { ; } } } } What you are missing is to extend BlockBush class, not just Block
  8. Alright, solved by doing this public boolean isInGround() { double x = this.posX - this.lastTickPosX; double y = this.posY - this.lastTickPosY; double z = this.posZ - this.lastTickPosZ; return (x == 0.0D && y == 0.0D && z == 0.0D); } /** * Called by a player entity when they collide with an entity */ @Override public void onCollideWithPlayer(EntityPlayer entityIn) { if (!this.worldObj.isRemote && this.isInGround() && this.arrowShake <= 0) { boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && entityIn.capabilities.isCreativeMode; if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(BLItems.onice_spear, 1))) { flag = false; } if (flag) { this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); entityIn.onItemPickup(this, 1); this.setDead(); } } } Thanks for the help you gave me
  9. I think i'll try the "velocity way". Unfortunately i don't know how to use asm (any link to a tutorial will be very appreciated) and for reflection i'm still learning how it works I'll let you know if checking it's velocity solve the problem
  10. As Jedi say look into the BlockSapling vanilla code, then starting from that code your own block sapling class by changing the function that needs to be changed (for example the item drop and the tree generation functions)
  11. any suggest? I want to make something similar to how the discs works on pixelmon (so i place a block down, i keep hitting it and sometimes it change it's model), i figured out how to change its drop if i'm using a certain tool or a condition is true, but how can i also "make it visual", how can i change it's model the more the breaking progress goes up (so the more i breaking it the more the model will be smaller)
  12. If you don't want to grow your tree even using the bonemeal than you need to overrid the canGrow method like this ** * Whether this IGrowable can grow */ public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient) { return false; } So you can use the bonemeal on sapling but it will never grow. If you want instead to generate your tree than look into the BlockSapling vanilla class, or use this public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state) { this.grow(worldIn, pos, state, rand); } public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (((Integer)state.getValue(STAGE)).intValue() == 0) { worldIn.setBlockState(pos, state.cycleProperty(STAGE), 4); } else { this.generateTree(worldIn, pos, state, rand); } } public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return; Object object = new WorldGenMyTree(true); IBlockState iblockstate1 = Blocks.air.getDefaultState(); worldIn.setBlockState(pos, iblockstate1, 4); if (!((WorldGenerator)object).generate(worldIn, rand, pos.add(i, 0, j))) { if (flag) { worldIn.setBlockState(pos.add(i, 0, j), state, 4); worldIn.setBlockState(pos.add(i + 1, 0, j), state, 4); worldIn.setBlockState(pos.add(i, 0, j + 1), state, 4); worldIn.setBlockState(pos.add(i + 1, 0, j + 1), state, 4); } else { worldIn.setBlockState(pos, state, 4); } } } WorldGenMyTree is your custom tree generator (wich you can use whatever you want, even a custom tree "designed" like a structure
  13. Instead of using "parent": "block/wall_post", define your own json file for that and use that as a parent So for example, you define a json file called "my_wall.json" { "textures": { "particle": "#wall" }, "elements": [ { "from": [ 4, 0, 4 ], "to": [ 12, 16, 12 ], "faces": { "down": { "uv": [ 4, 4, 12, 12 ], "texture": "#wall", "cullface": "down" }, "up": { "uv": [ 4, 4, 12, 12 ], "texture": "#up", "cullface": "up" }, "north": { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" }, "south": { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" }, "west": { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" }, "east": { "uv": [ 4, 0, 12, 16 ], "texture": "#wall" } }, } ] } With this code you have a different texture on the upper side, so in your wall json file (the one that you've posted) you need to do this { "parent": "ID:block/my_wall", "textures": { "wall": "blocks/log_oak", "up" : "blocks/stone" } } ID is your modid, my_wall is the file that "replace" the wall_post of before, and with this you can make a wall that has a stone texture on the upper side [/code]
  14. What do you mean by "can't get the sapling right"? You mean that breaking the leaves doesn't give you the correspective sapling or else? If you could post at least a screenshot or a video of what is your problem we can better understand
  15. It is in the new code. Anyway i've updated the original post so you should see it now
  16. I have that constructor, is here public EntityOniceSpear(World worldIn) { super(worldIn); }
  17. Ok, so i've added the event handler, so i now have this package blaze.core; import net.minecraft.block.Block; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class Events { @SubscribeEvent public void breakSpeed(PlayerEvent.BreakSpeed event) { if ( (event.state == null || event.state.getBlock() != BLBlocks.coal_block) && (event.entityPlayer == null || event.entityPlayer.getCurrentEquippedItem() == null || event.entityPlayer.getCurrentEquippedItem().getItem() != BLItems.topaz_hammer)) { return; } else { System.out.println("BREAKING"); Block block = event.state.getBlock(); } } } So now how can i tell the game "change the block model while breaking"?
  18. Of course, here is the entity class package blaze.entities; import blaze.core.BLItems; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; public class EntityOniceSpear extends EntityArrow implements IEntityAdditionalSpawnData { private boolean inGround; public EntityOniceSpear(World worldIn) { super(worldIn); } public EntityOniceSpear(World worldIn, EntityLivingBase shooter, EntityLivingBase par3, float par4, float par5) { super(worldIn, shooter, par3, par4, par5); } public EntityOniceSpear(World worldIn, EntityLivingBase shooter, float par3) { super(worldIn, shooter, par3); } /** * Called by a player entity when they collide with an entity */ @Override public void onCollideWithPlayer(EntityPlayer entityIn) { if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0) { boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && entityIn.capabilities.isCreativeMode; if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(BLItems.onice_spear, 1))) { flag = false; } if (flag) { this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); entityIn.onItemPickup(this, 1); this.setDead(); } } } @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(shootingEntity != null ? shootingEntity.getEntityId() : -1); } @Override public void readSpawnData(ByteBuf buffer) { Entity shooter = worldObj.getEntityByID(buffer.readInt()); if (shooter instanceof EntityLivingBase) { shootingEntity = (EntityLivingBase) shooter; } } }
  19. This is the item class from where i shoot the spear package blaze.items; import blaze.core.BLTabs; import blaze.entities.EntityMalachiteSpear; import blaze.entities.EntityOniceSpear; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemBow; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ItemSpear extends ItemBow { private int type; public ItemSpear(int type) { this.setMaxDamage(0); this.setMaxStackSize(16); this.type = type; this.setCreativeTab(BLTabs.tabCombat); } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) { net.minecraftforge.event.entity.player.ArrowNockEvent event = new net.minecraftforge.event.entity.player.ArrowNockEvent(playerIn, itemStackIn); if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return event.result; playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn)); return itemStackIn; } /** * How long it takes to use or consume an item */ @Override public int getMaxItemUseDuration(ItemStack stack) { return 72000; } /** * Called when the player stops using an Item (stops holding the right mouse button). * * @param timeLeft The amount of ticks left before the using would have been complete */ @Override public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft) { int j = this.getMaxItemUseDuration(stack) - timeLeft; net.minecraftforge.event.entity.player.ArrowLooseEvent event = new net.minecraftforge.event.entity.player.ArrowLooseEvent(playerIn, stack, j); if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return; j = event.charge; boolean flag = playerIn.capabilities.isCreativeMode; float f = (float)j / 20.0F; f = (f * f + f * 2.0F) / 3.0F; if ((double)f < 0.1D) { return; } if (f > 1.0F) { f = 1.0F; } if(this.type == 0) { EntityOniceSpear entityspear = new EntityOniceSpear(worldIn, playerIn, f * 2.0F); if (flag) { entityspear.canBePickedUp = 2; } else { playerIn.inventory.consumeInventoryItem(this); } playerIn.triggerAchievement(StatList.objectUseStats[item.getIdFromItem(this)]); if (!worldIn.isRemote) { worldIn.spawnEntityInWorld(entityspear); } } else { EntityMalachiteSpear entityspear = new EntityMalachiteSpear(worldIn, playerIn, f * 2.0F); if (flag) { entityspear.canBePickedUp = 2; } else { playerIn.inventory.consumeInventoryItem(this); } playerIn.triggerAchievement(StatList.objectUseStats[item.getIdFromItem(this)]); if (!worldIn.isRemote) { worldIn.spawnEntityInWorld(entityspear); } } } @Override @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } }
  20. yes i was able to pickup before, and i didn't change anything about that part (the function onCollideWithPlayer is the same)
  21. Thanks, i'll check it out I found another method but i don't know if is correct. Overriding this function @SideOnly(Side.CLIENT) public boolean addHitEffects(World world, MovingObjectPosition target, net.minecraft.client.particle.EffectRenderer effectRenderer) { return false; } lets me handle what happens when breaking the block. Is it correct doing stuff here?
  22. Is there any way to see how a block is damaged? I mean, you hit the block for a period of time and then it breaks, is there a way to see "if the block has been hitten for X time than use this model, if it has been hitten for Z time than use this other model" I've tried using the damageValue but it always return the metadata (wich in my case is 0). So basically how can i check if a player is breaking a block and from how long he's doing it?
  23. Thanks for your reply I've added these methods but now the entity is not rendering ad eclipse gives me this error [22:27:36] [Client thread/ERROR] [FML]: A severe problem occurred during the spawning of an entity at ( 558.0625,5.5, -549.84375) java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World) at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_51] at java.lang.Class.getConstructor(Unknown Source) ~[?:1.8.0_51] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:98) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) [EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) [EntitySpawnHandler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_51] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) [FMLCommonHandler.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1070) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] [22:27:36] [Client thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World) java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World) at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_51] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_51] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:710) [FMLCommonHandler.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1070) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_51] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_51] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World) at com.google.common.base.Throwables.propagate(Throwables.java:160) ~[guava-17.0.jar:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:147) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) ~[EntitySpawnHandler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_51] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_51] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?] ... 11 more Caused by: java.lang.NoSuchMethodException: blaze.entities.EntityOniceSpear.<init>(net.minecraft.world.World) at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.8.0_51] at java.lang.Class.getConstructor(Unknown Source) ~[?:1.8.0_51] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.spawnEntity(EntitySpawnHandler.java:98) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.process(EntitySpawnHandler.java:56) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler.access$000(EntitySpawnHandler.java:31) ~[EntitySpawnHandler.class:?] at net.minecraftforge.fml.common.network.internal.EntitySpawnHandler$1.run(EntitySpawnHandler.java:46) ~[EntitySpawnHandler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_51] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_51] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?] ... 11 more QUICK UPDATE: i've solved that problem by adding the other constructors, but now i can't pickup the spear when on ground public EntityOniceSpear(World worldIn) { super(worldIn); } public EntityOniceSpear(World worldIn, double x, double y, double z) { super(worldIn); } public EntityOniceSpear(World worldIn, EntityLivingBase shooter, EntityLivingBase p_i1755_3_, float p_i1755_4_, float p_i1755_5_) { super(worldIn); }
  24. I have a spear that acts like an arrow, but when i shoot it in a block it has a strange behavior. It "moves" up after it hit the block. Here is a video to show you what i mean https://www.youtube.com/watch?v=RUIcAT-zqTc&feature=youtu.be This is my entity class package blaze.entities; import blaze.core.BLItems; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; public class EntityOniceSpear extends EntityArrow implements IEntityAdditionalSpawnData { private boolean inGround; public EntityOniceSpear(World worldIn) { super(worldIn); } public EntityOniceSpear(World worldIn, EntityLivingBase shooter, EntityLivingBase par3, float par4, float par5) { super(worldIn, shooter, par3, par4, par5); } public EntityOniceSpear(World worldIn, EntityLivingBase shooter, float par3) { super(worldIn, shooter, par3); } /** * Called by a player entity when they collide with an entity */ @Override public void onCollideWithPlayer(EntityPlayer entityIn) { if (!this.worldObj.isRemote && this.inGround && this.arrowShake <= 0) { boolean flag = this.canBePickedUp == 1 || this.canBePickedUp == 2 && entityIn.capabilities.isCreativeMode; if (this.canBePickedUp == 1 && !entityIn.inventory.addItemStackToInventory(new ItemStack(BLItems.onice_spear, 1))) { flag = false; } if (flag) { this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); entityIn.onItemPickup(this, 1); this.setDead(); } } } @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(shootingEntity != null ? shootingEntity.getEntityId() : -1); } @Override public void readSpawnData(ByteBuf buffer) { Entity shooter = worldObj.getEntityByID(buffer.readInt()); if (shooter instanceof EntityLivingBase) { shootingEntity = (EntityLivingBase) shooter; } } } And this is how i register the entity EntityRegistry.registerModEntity(EntityMalachiteSpear.class, "malachiteSpear", 2 , BL.instance, 64, 20, true); The value 64 and 20 has been taken from the registration of the EntityArrow class in EntityTracker (here it also set false the last value, but if i do the arrow doesn't do the moving animation) So why has this behavior? Thanks in advance to all who will help me
  25. Just fixed that by chaging the two functions above with this @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(this.art.ordinal()); buffer.writeInt(this.hangingPosition.getX()); // x buffer.writeInt(this.hangingPosition.getY()); // y buffer.writeInt(this.hangingPosition.getZ()); // z buffer.writeByte(this.getHorizontalFacing().getIndex()); } @Override public void readSpawnData(ByteBuf buffer) { EntityPaintingEB.EnumArt[] aenumart = EntityPaintingEB.EnumArt.values(); this.art = aenumart[buffer.readInt()]; int x = buffer.readInt(); int y = buffer.readInt(); int z = buffer.readInt(); BlockPos pos = new BlockPos(x, y, z); this.hangingPosition = pos; this.func_174859_a(EnumFacing.getFront((buffer.readByte()))); } Finally this problem is solved, thanks to everyone of you!!!! Hope this will help you jeffryfisher in your updating process
×
×
  • Create New...

Important Information

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