Jump to content

_Cruelar_

Members
  • Posts

    292
  • Joined

  • Last visited

Everything posted by _Cruelar_

  1. Still doesn't work.I can't see the Hitbox when I press F3+B. What' is wrong? package com.cruelar.cruelars_triforcemod.entities.boss; import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core; import jline.internal.Nullable; import net.minecraft.entity.*; import net.minecraft.entity.ai.*; import net.minecraft.entity.monster.EntityIronGolem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntityPigZombie; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.BossInfo; import net.minecraft.world.BossInfoServer; import net.minecraft.world.World; public class Stone_Talus extends EntityMob implements IEntityMultiPart { public static final ResourceLocation LOOT = new ResourceLocation(Cruelars_Triforcemod_Core.MODID, "entities/stone_talus.json"); public static final ResourceLocation RESOURCE_LOCATION = new ResourceLocation("cruelars_triforcemod:textures/entity/stone_talus.png"); private final BossInfoServer bossInfo; public final MultiPartEntityPart[] talusParts; public final MultiPartEntityPart Mainbody = new MultiPartEntityPart(this, "mainbody", 5, 5); public final MultiPartEntityPart Oredeposit = new MultiPartEntityPart(this, "oredeposit", 1, 1); public float prevAnimTime; public float animTime; public Stone_Talus(World world) { super(world); this.setSize(2.0F, 3.5F); this.isNonBoss(); this.setHealth(this.getMaxHealth()); this.bossInfo = (BossInfoServer) (new BossInfoServer(this.getDisplayName(), BossInfo.Color.RED, BossInfo.Overlay.PROGRESS)); this.isImmuneToFire = true; this.talusParts = new MultiPartEntityPart[]{this.Mainbody, this.Oredeposit}; } public void readEntityFromNBT(NBTTagCompound p_readEntityFromNBT_1_) { super.readEntityFromNBT(p_readEntityFromNBT_1_); if (this.hasCustomName()) { this.bossInfo.setName(this.getDisplayName()); } } protected void updateAITasks() { super.updateAITasks(); } public void addTrackingPlayer(EntityPlayerMP p_addTrackingPlayer_1_) { super.addTrackingPlayer(p_addTrackingPlayer_1_); this.bossInfo.addPlayer(p_addTrackingPlayer_1_); } public void removeTrackingPlayer(EntityPlayerMP p_removeTrackingPlayer_1_) { super.removeTrackingPlayer(p_removeTrackingPlayer_1_); this.bossInfo.removePlayer(p_removeTrackingPlayer_1_); } public void setCustomNameTag(String p_setCustomNameTag_1_) { super.setCustomNameTag(p_setCustomNameTag_1_); this.bossInfo.setName(this.getDisplayName()); } @Override protected void entityInit() { super.entityInit(); } @Override protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(300.0D); this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.1D); this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(10.0D); this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(32.0D); this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(10.0D); this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(100.0D); } @Override protected void initEntityAI() { this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, true)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(7, new EntityAIWander(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.applyEntityAI(); } private void applyEntityAI() { this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, EntityPigZombie.class)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget<>(this, EntityPlayer.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<>(this, EntityVillager.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<>(this, EntityIronGolem.class, true)); } @Override public boolean attackEntityAsMob(Entity entity) { return super.attackEntityAsMob(entity); } @Override @Nullable protected ResourceLocation getLootTable() { return LOOT; } @Override protected boolean isValidLightLevel() { return true; } @Override protected boolean canDropLoot() { return true; } @Override public int getMaxSpawnedInChunk() { return 1; } @Override public boolean isNonBoss() { return false; } @Override public World getWorld() { return this.world; } @Override public boolean attackEntityFromPart(MultiPartEntityPart entityPart, DamageSource source, float damage) { return entityPart == Oredeposit; } @Override public void onLivingUpdate() { if (this.world.isRemote) { this.setHealth(this.getHealth()); } this.prevAnimTime = this.animTime; if (this.getHealth() <= 0.0F) { float f12 = (this.rand.nextFloat() - 0.5F) * 8.0F; float f13 = (this.rand.nextFloat() - 0.5F) * 4.0F; float f15 = (this.rand.nextFloat() - 0.5F) * 8.0F; this.world.spawnParticle(EnumParticleTypes.SPELL_MOB_AMBIENT, this.posX + (double) f12, this.posY + 2.0D + (double) f13, this.posZ + (double) f15, 0.0D, 0.0D, 0.0D); } if (this.isAIDisabled()) { this.animTime = 0.5F; } else { Mainbody.onUpdate(); Mainbody.setLocationAndAngles(this.posX, this.posY, this.posZ, 0, 0); Oredeposit.onUpdate(); Oredeposit.setLocationAndAngles(this.posX + 1, this.posY + 4, this.posZ, 0, 0); } this.bossInfo.setPercent(this.getHealth() / this.getMaxHealth()); } }
  2. Seems to work with new AxisAlignedBB(0,0,0,0,0,0) will tell you if crashes again
  3. So I just managed to set up the breakpoints. Seems like I've done something wrong before. But still The Entity is only set dead when I reload the world. All other conditions than entityplayer==null seem to be false all the time. I'll appreciate any help. (Code is in my older posts) Also the Entity starts after a short time at its startposition with its new movement speed.
  4. My Problem is I don't find anything about where the BoundingBox of the MultiPart is located
  5. Thanks but how it binds the MUltiParts to the ModelParts My Code (AI is only for testing I'm working on a better one): package com.cruelar.cruelars_triforcemod.entities.boss; import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core; import jline.internal.Nullable; import net.minecraft.entity.*; import net.minecraft.entity.ai.*; import net.minecraft.entity.monster.EntityIronGolem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.EntityPigZombie; import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.BossInfo; import net.minecraft.world.BossInfoServer; import net.minecraft.world.World; public class Stone_Talus extends EntityMob implements IEntityMultiPart { public static final ResourceLocation LOOT = new ResourceLocation(Cruelars_Triforcemod_Core.MODID,"entities/stone_talus.json"); public static final ResourceLocation RESOURCE_LOCATION = new ResourceLocation("cruelars_triforcemod:textures/entity/stone_talus.png"); private final BossInfoServer bossInfo; public final MultiPartEntityPart[] talusParts; public final MultiPartEntityPart Mainbody = new MultiPartEntityPart(this,"mainbody",8,8); public final MultiPartEntityPart Oredeposit = new MultiPartEntityPart(this,"oredeposit",1,1); public Stone_Talus(World world){ super(world); this.setSize(2.0F,3.5F ); this.isNonBoss(); this.setEntityBoundingBox(new AxisAlignedBB(this.getEntityBoundingBox().minX-2,this.getEntityBoundingBox().minY,this.getEntityBoundingBox().minZ,this.getEntityBoundingBox().maxX+2,this.getEntityBoundingBox().maxY+4,this.getEntityBoundingBox().maxZ)); this.bossInfo = (BossInfoServer)(new BossInfoServer(this.getDisplayName(), BossInfo.Color.RED, BossInfo.Overlay.PROGRESS)); this.isImmuneToFire = true; this.talusParts=new MultiPartEntityPart[]{this.Mainbody,this.Oredeposit}; } public void readEntityFromNBT(NBTTagCompound p_readEntityFromNBT_1_) { super.readEntityFromNBT(p_readEntityFromNBT_1_); if (this.hasCustomName()) { this.bossInfo.setName(this.getDisplayName()); } } protected void updateAITasks() { super.updateAITasks(); this.bossInfo.setPercent(this.getHealth() / this.getMaxHealth()); } public void addTrackingPlayer(EntityPlayerMP p_addTrackingPlayer_1_) { super.addTrackingPlayer(p_addTrackingPlayer_1_); this.bossInfo.addPlayer(p_addTrackingPlayer_1_); } public void removeTrackingPlayer(EntityPlayerMP p_removeTrackingPlayer_1_) { super.removeTrackingPlayer(p_removeTrackingPlayer_1_); this.bossInfo.removePlayer(p_removeTrackingPlayer_1_); } public void setCustomNameTag(String p_setCustomNameTag_1_) { super.setCustomNameTag(p_setCustomNameTag_1_); this.bossInfo.setName(this.getDisplayName()); } @Override protected void entityInit(){ super.entityInit(); } @Override protected void applyEntityAttributes(){ super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(300.0D); this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.1D); this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(10.0D); this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(32.0D); this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(10.0D); this.getEntityAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(100.0D); } @Override protected void initEntityAI(){ this.tasks.addTask(0,new EntityAISwimming(this)); this.tasks.addTask(2,new EntityAIAttackMelee(this,1.0D,true)); this.tasks.addTask(5,new EntityAIMoveTowardsRestriction(this,1.0D)); this.tasks.addTask(7,new EntityAIWander(this,1.0D)); this.tasks.addTask(8,new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(8,new EntityAILookIdle(this)); this.applyEntityAI(); } private void applyEntityAI() { this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, EntityPigZombie.class)); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget<>(this, EntityPlayer.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<>(this, EntityVillager.class, true)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget<>(this, EntityIronGolem.class, true)); } @Override public boolean attackEntityAsMob(Entity entity){ return super.attackEntityAsMob(entity); } @Override @Nullable protected ResourceLocation getLootTable(){ return LOOT; } @Override protected boolean isValidLightLevel(){ return true; } @Override protected boolean canDropLoot () { return true; } @Override public int getMaxSpawnedInChunk(){ return 1; } @Override public boolean isNonBoss(){ return false; } @Override public World getWorld() { return this.world; } @Override public boolean attackEntityFromPart(MultiPartEntityPart entityPart, DamageSource source, float damage) { if (entityPart==Oredeposit){ return true; } return false; } }
  6. Hi guys, I'm working on a Entity, Stone Talus from The Legend of Zelda: Breath of the Wild, which don't take any damage of getting hit except at an ore deposit located on his back. I thought about a second hitbox as a weak spot located at the deposit, but I've no Code yet for the weak spot, because I don't know how to start, but I'll look if I find a way to start, so maybe I can give the code soon.
  7. What's about this: package com.cruelar.cruelars_triforcemod.blocks; import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core; import com.cruelar.cruelars_triforcemod.init.ModBlocks; import com.cruelar.cruelars_triforcemod.proxy.CommonProxy; import com.cruelar.cruelars_triforcemod.tileentity.False_Block_TileEntity; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.EnumPushReaction; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockFaceShape; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import static com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod.CRUELARS_TRIFORCEMOD; public class False_Block extends Block { public static final PropertyBool VISIBLE = PropertyBool.create("visible"); /** * Creates an new False Block from another Block * @param blockname name of the block. false_ will be added before*/ public False_Block(String blockname){ super(Material.AIR); this.setDefaultState(this.blockState.getBaseState().withProperty(VISIBLE,true)); this.setRegistryName("false_"+blockname); this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".false_"+blockname); this.setCreativeTab(CRUELARS_TRIFORCEMOD); } @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[]{VISIBLE}); } @Override @SuppressWarnings("deprecation") public AxisAlignedBB getBoundingBox(IBlockState iBlockState, IBlockAccess p_getBoundingBox_2_, BlockPos p_getBoundingBox_3_) { return NULL_AABB; } @Override public boolean canCollideCheck(IBlockState p_canCollideCheck_1_, boolean p_canCollideCheck_2_) { return false; } @Override @SuppressWarnings("deprecation") public EnumBlockRenderType getRenderType(IBlockState p_getRenderType_1_) { return EnumBlockRenderType.MODEL; } @Override @SuppressWarnings("deprecation") public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(VISIBLE,(meta & 2)>0); } @Override @SuppressWarnings("deprecation") public IBlockState getActualState(IBlockState iBlockState,IBlockAccess iBlockAccess, BlockPos blockPos) { return iBlockState; } @Override public int getMetaFromState(IBlockState blockState) { int i = 0; if ((boolean)blockState.getValue(VISIBLE)){ i |= 2; } return i; } @Override public TileEntity createTileEntity(World world,IBlockState iBlockState){ return new False_Block_TileEntity(); } @Override public boolean hasTileEntity(IBlockState p_hasTileEntity_1_) { return true; } @Override @SuppressWarnings("deprecation") public boolean isOpaqueCube(IBlockState p_isOpaqueCube_1_) { return false; } public static void setVisible(IBlockState iBlockState){ iBlockState.cycleProperty(VISIBLE); } @Override public boolean isReplaceable(IBlockAccess p_isReplaceable_1_, BlockPos p_isReplaceable_2_) { return true; } @SideOnly(Side.CLIENT) public void initModel(){ ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory")); } @Override @SuppressWarnings("deprecation") public EnumPushReaction getMobilityFlag(IBlockState p_getMobilityFlag_1_) { return EnumPushReaction.IGNORE; } @Override @SideOnly(Side.CLIENT) @SuppressWarnings("deprecation") public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos blockPos, EnumFacing side){ return true; } @Override @SuppressWarnings("deprecation") public BlockFaceShape getBlockFaceShape(IBlockAccess p_getBlockFaceShape_1_, IBlockState p_getBlockFaceShape_2_, BlockPos p_getBlockFaceShape_3_, EnumFacing p_getBlockFaceShape_4_) { return BlockFaceShape.UNDEFINED; } @Override @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } @Override @SuppressWarnings("deprecation") public boolean isFullCube(IBlockState p_isFullCube_1_) { return false; } @Override public boolean isAir(IBlockState p_isAir_1_, IBlockAccess p_isAir_2_, BlockPos p_isAir_3_) { return false; } @Override public boolean isPassable(IBlockAccess p_isPassable_1_, BlockPos p_isPassable_2_) { return true; } @Override public boolean isNormalCube(IBlockState p_isNormalCube_1_, IBlockAccess p_isNormalCube_2_, BlockPos p_isNormalCube_3_) { return false; } } That overrides getBoundingBox() Sorry for the late answer.
  8. OBJ without animation OBJ with TESR
  9. Randomly the game crashes with this in the terminal. I post here as I think its related to this block. Updated code: package com.cruelar.cruelars_triforcemod.blocks; import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core; import com.cruelar.cruelars_triforcemod.init.ModBlocks; import com.cruelar.cruelars_triforcemod.init.ModItems; import com.cruelar.cruelars_triforcemod.tileentity.Hidden_Block_TileEntity; import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.EnumPushReaction; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Objects; import static com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod.CRUELARS_TRIFORCEMOD; public class Hidden_Block extends Block { public static final PropertyBool VISIBLE = PropertyBool.create("visible"); /** * Creates an new Hidden Block from another Block * @param blockname name of the block. hidden_ will be added before * @param blockmaterial material of the block*/ public Hidden_Block(String blockname, Material blockmaterial){ super(blockmaterial); this.setDefaultState(this.blockState.getBaseState().withProperty(VISIBLE,true)); this.setRegistryName(("hidden_"+blockname)); this.setUnlocalizedName((Cruelars_Triforcemod_Core.MODID+".hidden_"+blockname)); this.setCreativeTab(CRUELARS_TRIFORCEMOD); } @MethodsReturnNonnullByDefault @Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[]{VISIBLE}); } @Override @SuppressWarnings("deprecation") public IBlockState getStateFromMeta(int meta) { return getDefaultState() .withProperty(VISIBLE, meta!=0); } @SuppressWarnings("deprecation") @Override public IBlockState getActualState(IBlockState iBlockState,IBlockAccess iBlockAccess, BlockPos blockPos) { return iBlockState; } @Override public int getMetaFromState(IBlockState blockState) { int i = 0; if ((boolean)blockState.getValue(VISIBLE)){ i |= 2; } return i; } @Override public TileEntity createTileEntity(World world, IBlockState iBlockState){ return new Hidden_Block_TileEntity(); } @Override public boolean hasTileEntity(IBlockState p_hasTileEntity_1_) { return true; } @SuppressWarnings("deprecation") @Override public boolean isOpaqueCube(IBlockState p_isOpaqueCube_1_) { return false; } @Override @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } @Override public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState iBlockState, EntityPlayer entityPlayer, EnumHand enumHand, EnumFacing enumFacing, float p_float_1, float p_float_2, float p_float_3) { if (entityPlayer.getHeldItem(enumHand).getItem()== ModItems.lens_of_truth&&!iBlockState.getValue(VISIBLE)){ iBlockState.cycleProperty(VISIBLE); } else if (iBlockState.getValue(VISIBLE)){ iBlockState.cycleProperty(VISIBLE); } return true; } @SideOnly(Side.CLIENT) public void initModel(){ ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(Objects.requireNonNull(this.getRegistryName()), "inventory")); } @Override @SuppressWarnings("deprecation") public EnumPushReaction getMobilityFlag(IBlockState p_getMobilityFlag_1_) { return EnumPushReaction.IGNORE; } @Override @SuppressWarnings("deprecation") public boolean isTopSolid(IBlockState state) { return true; } } Everything else is the same as before I only changed it to be a blueprint for hidden_blocks
  10. Look at this: Which forge version do you use?
  11. @Animefan8888 and @diesieben07 I'm feeling we're close to the solution but I need your help as I don't know enough about this stuff yet.
  12. I found something that might give a hint to the core of the problem: I'm calling shoot in the constructor and in the readSpawnData() If I remove it in the constructor the Entity can't move. If I remove it in readSpawnData() the behavior doesn't change I noticed it by reading the output of shoot() when I Right click to shoot: A minor thing would be that I want to have a chain or at least a line between the entity and the item and don't know how to do that.
  13. which forge version have you installed? What says the quote about the log and the Forge version? diesieben007 was faster ?
  14. I made some changes to improve its behavior. But Still it dies after a certain amount of time that static. Also it then still respawns with the same motion speed as the moment it died. Updated code: package com.cruelar.cruelars_triforcemod.entities.projectiles; import io.netty.buffer.ByteBuf; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.MoverType; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.*; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Iterator; import java.util.List; import java.util.UUID; public class Clawshot_Head extends Entity implements IEntityAdditionalSpawnData{ private UUID entityPlayer; public Entity caughtEntity; public Clawshot_Head.State currentState; private static final DataParameter<Integer> DATA_HOOKED_ENTITY; private boolean inGround; private int ticksInAir; private int ticksInGround; public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png"); public Clawshot_Head(World world){ super(world); } public Clawshot_Head(World world, EntityPlayer entityPlayer){ super(world); this.init(entityPlayer); this.currentState = Clawshot_Head.State.FLYING; this.setPosition((double)entityPlayer.posX,(double)entityPlayer.posY+entityPlayer.getEyeHeight(),(double)entityPlayer.posZ); this.shoot(entityPlayer); this.setNoGravity(true); } @SideOnly(Side.CLIENT) public Clawshot_Head(World world, EntityPlayer entityPlayer, double posX, double posY, double posZ) { super(world); this.init(entityPlayer); this.setPosition(posX,posY,posZ); this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; } public void notifyDataManagerChange(DataParameter<?> p_notifyDataManagerChange_1_) { if (DATA_HOOKED_ENTITY.equals(p_notifyDataManagerChange_1_)) { int i = (Integer)this.getDataManager().get(DATA_HOOKED_ENTITY); this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null; } super.notifyDataManagerChange(p_notifyDataManagerChange_1_); } public void onUpdate() { super.onUpdate(); if (this.entityPlayer == null) { System.out.println("ln:70 got called"); this.setDead(); } else if (this.world.isRemote) { if (this.inGround) { ++this.ticksInGround; motionX = 0; motionY = 0; motionZ = 0; } if(this.collidedHorizontally){ motionX=0; motionY=0; motionZ=0; ++this.ticksInGround; } if(this.getDistance(getEntityByUUID(entityPlayer,world))>=64){ System.out.println("ln:92 got called"); this.setDead(); } BlockPos blockpos = new BlockPos(this); IBlockState iblockstate = this.world.getBlockState(blockpos); if (this.currentState == Clawshot_Head.State.FLYING) { if (this.caughtEntity != null) { this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY; return; } if (!this.world.isRemote) { this.checkCollision(); } if (!this.inGround && !this.onGround && !this.collidedHorizontally) { ++this.ticksInAir; } else { this.ticksInAir = 0; this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; } } else { if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY) { if (this.caughtEntity != null) { if (this.caughtEntity.isDead) { this.caughtEntity = null; this.currentState = Clawshot_Head.State.FLYING; } else { this.posX = this.caughtEntity.posX; double d2 = (double)this.caughtEntity.height; this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D; this.posZ = this.caughtEntity.posZ; this.setPosition(this.posX, this.posY, this.posZ); } } return; } } this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ); this.updateRotation(); this.setPosition(this.posX, this.posY, this.posZ); } if (this.ticksInGround >= 1200) { System.out.println("ln:157 got called"); this.setDead(); } if (ticksInAir>=200){ System.out.println("ln:162 got called"); this.setDead(); } } private void updateRotation() { float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI)); for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; } public void shoot(Entity entity) { System.out.println(entity); this.motionX=0.6D*entity.getLookVec().x; this.motionY=0.6D*entity.getLookVec().y; this.motionZ=0.6D*entity.getLookVec().z; } public void shoot(double p_shoot_1_, double p_shoot_3_, double p_shoot_5_, float p_shoot_7_, float p_shoot_8_){} public int handleHookRetraction() { if (!this.world.isRemote && this.entityPlayer != null) { int i = 0; if (this.caughtEntity != null) { this.bringInHookedEntity(); this.world.setEntityState(this, (byte)31); i = this.caughtEntity instanceof EntityItem ? 3 : 5; } else if (this.inGround) { i = 2; } this.setDead(); return i; } else { return 0; } } protected void bringInHookedEntity() { if (this.getEntityByUUID(entityPlayer,world) != null) { double d0 = this.getEntityByUUID(entityPlayer,world).posX - this.posX; double d1 = this.getEntityByUUID(entityPlayer,world).posY - this.posY; double d2 = this.getEntityByUUID(entityPlayer,world).posZ - this.posZ; double d3 = 0.1D; this.caughtEntity.motionX += d0 * 0.1D; this.caughtEntity.motionY += d1 * 0.1D; this.caughtEntity.motionZ += d2 * 0.1D; } } public void setDead() { super.setDead(); } public EntityPlayer getAngler() { return this.getEntityByUUID(entityPlayer,this.world); } private EntityPlayer getEntityByUUID(UUID entityUUID, World worldIn){ int lenght =worldIn.getLoadedEntityList().size(); List<Entity> loadedEntityList= worldIn.getLoadedEntityList(); EntityPlayer foundEntity = null; for (int i = 0;i<lenght;i++){ if (loadedEntityList.get(i).getUniqueID()==entityUUID){ if (loadedEntityList.get(i) instanceof EntityPlayer) { foundEntity = (EntityPlayer) loadedEntityList.get(i); } } } return foundEntity; } private void init(EntityPlayer p_init_1_) { this.setSize(0.25F, 0.25F); this.ignoreFrustumCheck = true; this.entityPlayer = p_init_1_.getUniqueID(); } private void checkCollision() { Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ); Vec3d vec3d1 = new Vec3d(this.posX + 0.2, this.posY + 0.2, this.posZ + 0.2); RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false); vec3d = new Vec3d(this.posX, this.posY, this.posZ); vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (raytraceresult != null) { vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z); this.inGround=true; this.motionX=0; this.motionY=0; this.motionZ=0; getEntityByUUID(entityPlayer,this.world).posX=this.posX; getEntityByUUID(entityPlayer,this.world).posY=this.posY; getEntityByUUID(entityPlayer,this.world).posZ=this.posZ; } Entity entity = null; List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D)); double d0 = 0.0D; Iterator var8 = list.iterator(); while(true) { Entity entity1; double d1; do { RayTraceResult raytraceresult1; do { do { do { if (!var8.hasNext()) { if (entity != null) { raytraceresult = new RayTraceResult(entity); } if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS) { if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY) { this.caughtEntity = raytraceresult.entityHit; this.setHookedEntity(); } else { this.inGround = true; } } return; } entity1 = (Entity)var8.next(); } while(!this.canBeHooked(entity1)); } while(entity1 == this.getEntityByUUID(entityPlayer,this.world) && this.ticksInAir < 5); AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D); raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1); } while(raytraceresult1 == null); d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec); } while(d1 >= d0 && d0 != 0.0D); entity = entity1; d0 = d1; } } private void setHookedEntity() { this.getDataManager().set(DATA_HOOKED_ENTITY, this.caughtEntity.getEntityId() + 1); } protected boolean canBeHooked(Entity p_canBeHooked_1_) { return p_canBeHooked_1_.canBeCollidedWith() || p_canBeHooked_1_ instanceof EntityItem; } protected void entityInit() { this.getDataManager().register(DATA_HOOKED_ENTITY, 0); } @Override protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) { } @Override protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) { } static { DATA_HOOKED_ENTITY = EntityDataManager.createKey(Clawshot_Head.class, DataSerializers.VARINT); } @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeBoolean(getEntityByUUID(entityPlayer,this.world)==null); if (getEntityByUUID(entityPlayer,this.world)!=null) { buffer.writeInt(getEntityByUUID(entityPlayer,this.world).getEntityId()); } } @Override public void readSpawnData(ByteBuf additionalData) { boolean nullPlayer = additionalData.readBoolean(); if (!nullPlayer){ EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt()); if (entityByID!=null){ entityPlayer=entityByID.getUniqueID(); } this.shoot(getEntityByUUID(entityPlayer,this.world)); } } static enum State { FLYING, HOOKED_IN_ENTITY; private State() { } } }
  15. This is interesting. None of my Breakpoints responds. Code: package com.cruelar.cruelars_triforcemod.entities.projectiles; import io.netty.buffer.ByteBuf; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.MoverType; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.*; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Iterator; import java.util.List; import java.util.UUID; public class Clawshot_Head extends Entity implements IEntityAdditionalSpawnData{ private UUID entityPlayer; public Entity caughtEntity; public Clawshot_Head.State currentState; private static final DataParameter<Integer> DATA_HOOKED_ENTITY; private boolean inGround; private int ticksInAir; private int ticksInGround; public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png"); public Clawshot_Head(World world){ super(world); } public Clawshot_Head(World world, EntityPlayer entityPlayer){ super(world); this.init(entityPlayer); this.currentState = Clawshot_Head.State.FLYING; this.setPosition((double)entityPlayer.posX,(double)entityPlayer.posY+entityPlayer.getEyeHeight(),(double)entityPlayer.posZ); this.shoot(entityPlayer); } @SideOnly(Side.CLIENT) public Clawshot_Head(World world, EntityPlayer entityPlayer, double posX, double posY, double posZ) { super(world); this.init(entityPlayer); this.setPosition(posX,posY,posZ); this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; } public void notifyDataManagerChange(DataParameter<?> p_notifyDataManagerChange_1_) { if (DATA_HOOKED_ENTITY.equals(p_notifyDataManagerChange_1_)) { int i = (Integer)this.getDataManager().get(DATA_HOOKED_ENTITY); this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null; } super.notifyDataManagerChange(p_notifyDataManagerChange_1_); } public void onUpdate() { super.onUpdate(); if (this.entityPlayer == null) { this.setDead(); System.out.println("ln:69 got called"); } else if (this.world.isRemote) { if (this.inGround) { ++this.ticksInGround; motionX = 0; motionY = 0; motionZ = 0; } if(this.collidedHorizontally){ motionX=0; motionY=0; motionZ=0; ++this.ticksInGround; } if(this.getDistance(getEntityByUUID(entityPlayer,world))>=64){ this.setDead(); System.out.println("ln:89 got called"); } BlockPos blockpos = new BlockPos(this); IBlockState iblockstate = this.world.getBlockState(blockpos); if (this.currentState == Clawshot_Head.State.FLYING) { if (this.caughtEntity != null) { this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY; return; } if (!this.world.isRemote) { this.checkCollision(); } if (!this.inGround && !this.onGround && !this.collidedHorizontally) { ++this.ticksInAir; } else { this.ticksInAir = 0; this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; } } else { if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY) { if (this.caughtEntity != null) { if (this.caughtEntity.isDead) { this.caughtEntity = null; this.currentState = Clawshot_Head.State.FLYING; } else { this.posX = this.caughtEntity.posX; double d2 = (double)this.caughtEntity.height; this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D; this.posZ = this.caughtEntity.posZ; this.setPosition(this.posX, this.posY, this.posZ); } } return; } } this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ); this.updateRotation(); this.setPosition(this.posX, this.posY, this.posZ); } if (this.ticksInGround >= 1200) { this.setDead(); System.out.println("ln:155 got called"); } if (ticksInAir>=200){ this.setDead(); System.out.println("ln:159 got called"); } } private void updateRotation() { float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI)); for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; } public void shoot(Entity entity) { System.out.println(entity); this.motionX=0.6D*entity.getLookVec().x; this.motionY=0.6D*entity.getLookVec().y; this.motionZ=0.6D*entity.getLookVec().z; } public void shoot(double p_shoot_1_, double p_shoot_3_, double p_shoot_5_, float p_shoot_7_, float p_shoot_8_){} public int handleHookRetraction() { if (!this.world.isRemote && this.entityPlayer != null) { int i = 0; if (this.caughtEntity != null) { this.bringInHookedEntity(); this.world.setEntityState(this, (byte)31); i = this.caughtEntity instanceof EntityItem ? 3 : 5; } else if (this.inGround) { i = 2; } this.setDead(); return i; } else { return 0; } } protected void bringInHookedEntity() { if (this.getEntityByUUID(entityPlayer,world) != null) { double d0 = this.getEntityByUUID(entityPlayer,world).posX - this.posX; double d1 = this.getEntityByUUID(entityPlayer,world).posY - this.posY; double d2 = this.getEntityByUUID(entityPlayer,world).posZ - this.posZ; double d3 = 0.1D; this.caughtEntity.motionX += d0 * 0.1D; this.caughtEntity.motionY += d1 * 0.1D; this.caughtEntity.motionZ += d2 * 0.1D; } } public void setDead() { super.setDead(); } public EntityPlayer getAngler() { return this.getEntityByUUID(entityPlayer,this.world); } private EntityPlayer getEntityByUUID(UUID entityUUID, World worldIn){ int lenght =worldIn.getLoadedEntityList().size(); List<Entity> loadedEntityList= worldIn.getLoadedEntityList(); EntityPlayer foundEntity = null; for (int i = 0;i<lenght;i++){ if (loadedEntityList.get(i).getUniqueID()==entityUUID){ if (loadedEntityList.get(i) instanceof EntityPlayer) { foundEntity = (EntityPlayer) loadedEntityList.get(i); } } } return foundEntity; } private void init(EntityPlayer p_init_1_) { this.setSize(0.25F, 0.25F); this.ignoreFrustumCheck = true; this.entityPlayer = p_init_1_.getUniqueID(); } private void checkCollision() { Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ); Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false); vec3d = new Vec3d(this.posX, this.posY, this.posZ); vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (raytraceresult != null) { vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z); this.motionX=0; this.motionY=0; this.motionZ=0; getEntityByUUID(entityPlayer,this.world).posX=this.posX; getEntityByUUID(entityPlayer,this.world).posY=this.posY; getEntityByUUID(entityPlayer,this.world).posZ=this.posZ; } Entity entity = null; List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D)); double d0 = 0.0D; Iterator var8 = list.iterator(); while(true) { Entity entity1; double d1; do { RayTraceResult raytraceresult1; do { do { do { if (!var8.hasNext()) { if (entity != null) { raytraceresult = new RayTraceResult(entity); } if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS) { if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY) { this.caughtEntity = raytraceresult.entityHit; this.setHookedEntity(); } else { this.inGround = true; } } return; } entity1 = (Entity)var8.next(); } while(!this.canBeHooked(entity1)); } while(entity1 == this.getEntityByUUID(entityPlayer,this.world) && this.ticksInAir < 5); AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D); raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1); } while(raytraceresult1 == null); d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec); } while(d1 >= d0 && d0 != 0.0D); entity = entity1; d0 = d1; } } private void setHookedEntity() { this.getDataManager().set(DATA_HOOKED_ENTITY, this.caughtEntity.getEntityId() + 1); } protected boolean canBeHooked(Entity p_canBeHooked_1_) { return p_canBeHooked_1_.canBeCollidedWith() || p_canBeHooked_1_ instanceof EntityItem; } protected void entityInit() { this.getDataManager().register(DATA_HOOKED_ENTITY, 0); } @Override protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) { } @Override protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) { } static { DATA_HOOKED_ENTITY = EntityDataManager.createKey(Clawshot_Head.class, DataSerializers.VARINT); } @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeBoolean(getEntityByUUID(entityPlayer,this.world)==null); if (getEntityByUUID(entityPlayer,this.world)!=null) { buffer.writeInt(getEntityByUUID(entityPlayer,this.world).getEntityId()); } } @Override public void readSpawnData(ByteBuf additionalData) { boolean nullPlayer = additionalData.readBoolean(); if (!nullPlayer){ EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt()); if (entityByID!=null){ entityPlayer=entityByID.getUniqueID(); } this.shoot(getEntityByUUID(entityPlayer,this.world)); } } static enum State { FLYING, HOOKED_IN_ENTITY; private State() { } } } I changed the code to mainly use the UUID of the Player after thinking over Problematic code #9 Didn't solved the Problem though
  16. With this: public void onUpdate() { super.onUpdate(); if (this.entityPlayer == null) { this.setDead(); } else if (this.world.isRemote) { if (this.inGround) { ++this.ticksInGround; motionX = 0; motionY = 0; motionZ = 0; } if(this.getDistance(entityPlayer)>=64){ this.setDead(); return; } BlockPos blockpos = new BlockPos(this); IBlockState iblockstate = this.world.getBlockState(blockpos); if (this.currentState == Clawshot_Head.State.FLYING) { if (this.caughtEntity != null) { this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY; return; } if (!this.world.isRemote) { this.checkCollision(); } if (!this.inGround && !this.onGround && !this.collidedHorizontally) { ++this.ticksInAir; } else { this.ticksInAir = 0; this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; } } else { if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY) { if (this.caughtEntity != null) { if (this.caughtEntity.isDead) { this.caughtEntity = null; this.currentState = Clawshot_Head.State.FLYING; } else { this.posX = this.caughtEntity.posX; double d2 = (double)this.caughtEntity.height; this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D; this.posZ = this.caughtEntity.posZ; this.setPosition(this.posX, this.posY, this.posZ); } } return; } } this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ); this.updateRotation(); this.setPosition(this.posX, this.posY, this.posZ); } if (this.ticksInGround >= 1200) { this.setDead(); } if (ticksInAir>=200){ this.setDead(); return; } } I give the command to kill it on both sides,am I right? So why it doesn't works? Also setting the motion to o doesn't works. Is this also a problem with sides.
  17. As the title says I want to replace the Renderer for the Player to add CustomArmorModels if an Item implementing IBauble out of Baubles API is worn. This is not about how to code the Renderer. I only need to know what I need to replace the Vanilla Renderer. But help on coding the Renderer/LayerBaubles in a clean way is appreciated.
  18. As far as I know the recommended version is the latest version already tested completely so should be always stable, while latest version is the latest version with the latest bugfixes but also with possible yet undetected bugs. Usually you should use the recommended version.
  19. Updated code of Item(doesn't results in NPE anymore): package com.cruelar.cruelars_triforcemod.items; import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core; import com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head; import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nullable; import java.util.List; import java.util.Objects; import java.util.UUID; public class Clawshot_TP extends Item { public Clawshot_TP(){ this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD); this.setRegistryName("clawshot_tp"); this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".clawshot_tp"); this.addPropertyOverride(new ResourceLocation("cast"), new IItemPropertyGetter() { @SideOnly(Side.CLIENT) public float apply(ItemStack p_apply_1_, @Nullable World p_apply_2_, @Nullable EntityLivingBase p_apply_3_) { if (p_apply_3_ == null) { return 0.0F; } else { boolean lvt_4_1_ = p_apply_3_.getHeldItemMainhand() == p_apply_1_; boolean lvt_5_1_ = p_apply_3_.getHeldItemOffhand() == p_apply_1_; if (p_apply_3_.getHeldItemMainhand().getItem() instanceof Clawshot_TP) { lvt_5_1_ = false; } return (lvt_4_1_ || lvt_5_1_) && p_apply_3_ instanceof EntityPlayer && ((EntityPlayer)p_apply_3_).fishEntity != null ? 1.0F : 0.0F; } } }); } @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer,EnumHand enumHand) { ItemStack itemStack = entityPlayer.getHeldItem(enumHand); Clawshot_Head clawshot_head = new Clawshot_Head(world, entityPlayer); if (!world.isRemote) { if (!this.getTagCompoundSafe(itemStack).hasKey("shot") || !this.getTagCompoundSafe(itemStack).getBoolean("shot") || this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack)!=null && this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack).isDead) { world.spawnEntity(clawshot_head); this.getTagCompoundSafe(itemStack).setBoolean("shot",true); this.getTagCompoundSafe(itemStack).setUniqueId("head",clawshot_head.getUniqueID()); } else if (this.getEntityByUUID(this.getTagCompoundSafe(itemStack).getUniqueId("head"),world,itemStack)!=null){ this.getEntityByUUID(this.getTagCompoundSafe(itemStack).getUniqueId("head"),world,itemStack).setDead(); this.getTagCompoundSafe(itemStack).setBoolean("shot",false); } } return new ActionResult(EnumActionResult.SUCCESS,itemStack); } @SideOnly(Side.CLIENT) public void initModel(){ ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory")); } private NBTTagCompound getTagCompoundSafe(ItemStack stack) { NBTTagCompound tagCompound = stack.getTagCompound(); if (tagCompound == null) { tagCompound = new NBTTagCompound(); stack.setTagCompound(tagCompound); } return tagCompound; } private Entity getEntityByUUID(UUID entityUUID, World worldIn, ItemStack itemStack){ int lenght =worldIn.getLoadedEntityList().size(); List<Entity> loadedEntityList= worldIn.getLoadedEntityList(); Entity foundEntity = null; for (int i = 0;i<lenght;i++){ if (loadedEntityList.get(i).getUniqueID()==entityUUID){ foundEntity = loadedEntityList.get(i); } } return foundEntity; } } The Entity: package com.cruelar.cruelars_triforcemod.entities.projectiles; import io.netty.buffer.ByteBuf; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.MoverType; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.*; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Iterator; import java.util.List; public class Clawshot_Head extends Entity implements IEntityAdditionalSpawnData{ private EntityPlayer entityPlayer; public Entity caughtEntity; public Clawshot_Head.State currentState; private static final DataParameter<Integer> DATA_HOOKED_ENTITY; private boolean inGround; private int ticksInAir; private int ticksInGround; public static ResourceLocation RESOURCE_LOCATION=new ResourceLocation("cruelars_triforcemod:textures/entity/projectiles/clawshot_head.png"); public Clawshot_Head(World world){ super(world); } public Clawshot_Head(World world, EntityPlayer entityPlayer){ super(world); this.init(entityPlayer); this.currentState = Clawshot_Head.State.FLYING; this.setPosition((double)entityPlayer.posX,(double)entityPlayer.posY+entityPlayer.getEyeHeight(),(double)entityPlayer.posZ); this.shoot(entityPlayer); } @SideOnly(Side.CLIENT) public Clawshot_Head(World world, EntityPlayer entityPlayer, double posX, double posY, double posZ) { super(world); this.init(entityPlayer); this.setPosition(posX,posY,posZ); this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; } public void notifyDataManagerChange(DataParameter<?> p_notifyDataManagerChange_1_) { if (DATA_HOOKED_ENTITY.equals(p_notifyDataManagerChange_1_)) { int i = (Integer)this.getDataManager().get(DATA_HOOKED_ENTITY); this.caughtEntity = i > 0 ? this.world.getEntityByID(i - 1) : null; } super.notifyDataManagerChange(p_notifyDataManagerChange_1_); } public void onUpdate() { super.onUpdate(); if (this.entityPlayer == null) { this.setDead(); } else if (this.world.isRemote) { if (this.inGround) { ++this.ticksInGround; motionX=0; motionY=0; motionZ=0; if (this.ticksInGround >= 1200) { this.setDead(); return; } } if(this.getDistance(entityPlayer)>=64){ this.setDead(); return; } BlockPos blockpos = new BlockPos(this); IBlockState iblockstate = this.world.getBlockState(blockpos); if (this.currentState == Clawshot_Head.State.FLYING) { if (this.caughtEntity != null) { this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; this.currentState = Clawshot_Head.State.HOOKED_IN_ENTITY; return; } if (!this.world.isRemote) { this.checkCollision(); } if (!this.inGround && !this.onGround && !this.collidedHorizontally) { ++this.ticksInAir; } else { this.ticksInAir = 0; this.motionX = 0.0D; this.motionY = 0.0D; this.motionZ = 0.0D; } if (ticksInAir>=100){ this.setDead(); return; } } else { if (this.currentState == Clawshot_Head.State.HOOKED_IN_ENTITY) { if (this.caughtEntity != null) { if (this.caughtEntity.isDead) { this.caughtEntity = null; this.currentState = Clawshot_Head.State.FLYING; } else { this.posX = this.caughtEntity.posX; double d2 = (double)this.caughtEntity.height; this.posY = this.caughtEntity.getEntityBoundingBox().minY + d2 * 0.8D; this.posZ = this.caughtEntity.posZ; this.setPosition(this.posX, this.posY, this.posZ); } } return; } } this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ); this.updateRotation(); this.setPosition(this.posX, this.posY, this.posZ); } } private void updateRotation() { float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI)); for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) { } while (this.rotationPitch - this.prevRotationPitch >= 180.0F) { this.prevRotationPitch += 360.0F; } while (this.rotationYaw - this.prevRotationYaw < -180.0F) { this.prevRotationYaw -= 360.0F; } while (this.rotationYaw - this.prevRotationYaw >= 180.0F) { this.prevRotationYaw += 360.0F; } this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F; this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F; } public void shoot(Entity entity) { System.out.println(entity); this.motionX=0.6D*entity.getLookVec().x; this.motionY=0.6D*entity.getLookVec().y; this.motionZ=0.6D*entity.getLookVec().z; } public void shoot(double p_shoot_1_, double p_shoot_3_, double p_shoot_5_, float p_shoot_7_, float p_shoot_8_){} public int handleHookRetraction() { if (!this.world.isRemote && this.entityPlayer != null) { int i = 0; if (this.caughtEntity != null) { this.bringInHookedEntity(); this.world.setEntityState(this, (byte)31); i = this.caughtEntity instanceof EntityItem ? 3 : 5; } else if (this.inGround) { i = 2; } this.setDead(); return i; } else { return 0; } } protected void bringInHookedEntity() { if (this.entityPlayer != null) { double d0 = this.entityPlayer.posX - this.posX; double d1 = this.entityPlayer.posY - this.posY; double d2 = this.entityPlayer.posZ - this.posZ; double d3 = 0.1D; this.caughtEntity.motionX += d0 * 0.1D; this.caughtEntity.motionY += d1 * 0.1D; this.caughtEntity.motionZ += d2 * 0.1D; } } public void setDead() { super.setDead(); } public EntityPlayer getAngler() { return this.entityPlayer; } private void init(EntityPlayer p_init_1_) { this.setSize(0.25F, 0.25F); this.ignoreFrustumCheck = true; this.entityPlayer = p_init_1_; } private void checkCollision() { Vec3d vec3d = new Vec3d(this.posX, this.posY, this.posZ); Vec3d vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d, vec3d1, false, true, false); vec3d = new Vec3d(this.posX, this.posY, this.posZ); vec3d1 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ); if (raytraceresult != null) { vec3d1 = new Vec3d(raytraceresult.hitVec.x, raytraceresult.hitVec.y, raytraceresult.hitVec.z); this.motionX=0; this.motionY=0; this.motionZ=0; entityPlayer.posX=this.posX; entityPlayer.posY=this.posY; entityPlayer.posZ=this.posZ; } Entity entity = null; List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D)); double d0 = 0.0D; Iterator var8 = list.iterator(); while(true) { Entity entity1; double d1; do { RayTraceResult raytraceresult1; do { do { do { if (!var8.hasNext()) { if (entity != null) { raytraceresult = new RayTraceResult(entity); } if (raytraceresult != null && raytraceresult.typeOfHit != RayTraceResult.Type.MISS) { if (raytraceresult.typeOfHit == RayTraceResult.Type.ENTITY) { this.caughtEntity = raytraceresult.entityHit; this.setHookedEntity(); } else { this.inGround = true; } } return; } entity1 = (Entity)var8.next(); } while(!this.canBeHooked(entity1)); } while(entity1 == this.entityPlayer && this.ticksInAir < 5); AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.30000001192092896D); raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1); } while(raytraceresult1 == null); d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec); } while(d1 >= d0 && d0 != 0.0D); entity = entity1; d0 = d1; } } private void setHookedEntity() { this.getDataManager().set(DATA_HOOKED_ENTITY, this.caughtEntity.getEntityId() + 1); } protected boolean canBeHooked(Entity p_canBeHooked_1_) { return p_canBeHooked_1_.canBeCollidedWith() || p_canBeHooked_1_ instanceof EntityItem; } protected void entityInit() { this.getDataManager().register(DATA_HOOKED_ENTITY, 0); } @Override protected void readEntityFromNBT(NBTTagCompound nbtTagCompound) { } @Override protected void writeEntityToNBT(NBTTagCompound nbtTagCompound) { } static { DATA_HOOKED_ENTITY = EntityDataManager.createKey(Clawshot_Head.class, DataSerializers.VARINT); } @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeBoolean(entityPlayer==null); if (entityPlayer!=null) { buffer.writeInt(entityPlayer.getEntityId()); } } @Override public void readSpawnData(ByteBuf additionalData) { boolean nullPlayer = additionalData.readBoolean(); if (!nullPlayer){ EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt()); if (entityByID!=null){ entityPlayer=entityByID; } this.shoot(entityPlayer); } } static enum State { FLYING, HOOKED_IN_ENTITY; private State() { } } }
  20. clawshot_head.setDead(); What does this do? It references a new Entity just created in this method, not yet spawned in the world, and sets it to be dead. What it should do is gets the entity from the nbt and set that entity to be dead. Ok, I should give more details about that: The Entity is spawned correctly. Check. It lives a certain time. Check. (Not exactly what I want it to do but I should already know how to fix that) Then it dies (NOT by Right clicking again). Check And Respawns at its original spawnPos and moves again. But you're right about the error in the code,will fix that.
  21. I've wrote a method to find the Entity Code package com.cruelar.cruelars_triforcemod.items; import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core; import com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head; import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nullable; import java.util.List; import java.util.Objects; import java.util.UUID; public class Clawshot_TP extends Item { public Clawshot_TP(){ this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD); this.setRegistryName("clawshot_tp"); this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".clawshot_tp"); this.addPropertyOverride(new ResourceLocation("cast"), new IItemPropertyGetter() { @SideOnly(Side.CLIENT) public float apply(ItemStack p_apply_1_, @Nullable World p_apply_2_, @Nullable EntityLivingBase p_apply_3_) { if (p_apply_3_ == null) { return 0.0F; } else { boolean lvt_4_1_ = p_apply_3_.getHeldItemMainhand() == p_apply_1_; boolean lvt_5_1_ = p_apply_3_.getHeldItemOffhand() == p_apply_1_; if (p_apply_3_.getHeldItemMainhand().getItem() instanceof Clawshot_TP) { lvt_5_1_ = false; } return (lvt_4_1_ || lvt_5_1_) && p_apply_3_ instanceof EntityPlayer && ((EntityPlayer)p_apply_3_).fishEntity != null ? 1.0F : 0.0F; } } }); } @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer,EnumHand enumHand) { ItemStack itemStack = entityPlayer.getHeldItem(enumHand); Clawshot_Head clawshot_head = new Clawshot_Head(world, entityPlayer); if (!world.isRemote) { if (!this.getTagCompoundSafe(itemStack).hasKey("shot") || !this.getTagCompoundSafe(itemStack).getBoolean("shot") || this.getEntityByUUID(Objects.requireNonNull(this.getTagCompoundSafe(itemStack).getUniqueId("head")),world,itemStack).isDead) { world.spawnEntity(clawshot_head); this.getTagCompoundSafe(itemStack).setBoolean("shot",true); this.getTagCompoundSafe(itemStack).setUniqueId("head",clawshot_head.getUniqueID()); } else { clawshot_head.setDead(); this.getTagCompoundSafe(itemStack).setBoolean("shot",false); } } return new ActionResult(EnumActionResult.SUCCESS,itemStack); } @SideOnly(Side.CLIENT) public void initModel(){ ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory")); } private NBTTagCompound getTagCompoundSafe(ItemStack stack) { NBTTagCompound tagCompound = stack.getTagCompound(); if (tagCompound == null) { tagCompound = new NBTTagCompound(); stack.setTagCompound(tagCompound); } return tagCompound; } public Entity getEntityByUUID(UUID entityUUID, World worldIn, ItemStack itemStack){ int lenght =worldIn.getLoadedEntityList().size(); List<Entity> loadedEntityList= worldIn.getLoadedEntityList(); Entity foundEntity = null; for (int i = 0;i<lenght;i++){ if (loadedEntityList.get(i).getUniqueID()==entityUUID){ foundEntity = loadedEntityList.get(i); } } return foundEntity; } } Error: Still the Entity respawns after being setDead. What am I missing?
  22. I feel pretty dumb to ask but how get I an Entity by its UUID as world only has the method getPlayerEntitiesByUUID()
  23. I know that I also try that but for big Problems like that I often start with Vanilla code that works quite similar like in this case the FishingRod and FishHook similar to my Clawshot and its head to get the theory. BTW: How would I add a signature to my posts?
×
×
  • Create New...

Important Information

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