-
Posts
292 -
Joined
-
Last visited
Everything posted by _Cruelar_
-
[Reopened again][1.12.2] How to change blockstate based on helditem
_Cruelar_ replied to _Cruelar_'s topic in Modder Support
Yes. @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<net.minecraft.block.Block> event){ event.getRegistry().register(new False_Block()); event.getRegistry().register(new Hidden_Block()); GameRegistry.registerTileEntity(False_Block_TileEntity.class,new ResourceLocation("cruelars_triforcemod:tileentity/False_Block_TileEntity")); GameRegistry.registerTileEntity(Hidden_Block_TileEntity.class,new ResourceLocation("cruelars_triforcemod:tileentity/Hidden_Block_TileEntity")); -
The Item: 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.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.Objects; 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 = new ItemStack(this); Clawshot_Head clawshot_head = new Clawshot_Head(world, entityPlayer); if (!world.isRemote) { if (!this.getTagCompoundSafe(itemStack).getBoolean("shot")) { this.getTagCompoundSafe(itemStack).setBoolean("shot",true); world.spawnEntity(clawshot_head); } 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; } } The Entity: package com.cruelar.cruelars_triforcemod.entities.projectiles; import io.netty.buffer.ByteBuf; import net.minecraft.block.material.Material; 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; private boolean shouldRetarct=false; 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.posX); 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; if (this.ticksInGround >= 1200) { 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.shouldRetarct=true; } } 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; } } if (iblockstate.getMaterial() != Material.WATER) { this.motionY -= 0.03D; } 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; net.minecraftforge.event.entity.player.ItemFishedEvent event = null; 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 0; } 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); 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() { } } } Report of shoot(Entity entity): [18:34:17] [main/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:209]: EntityPlayerSP['Player99'/356, l='MpServer', x=161.70, y=74.62, z=255.17] [18:34:17] [Server thread/INFO] [STDOUT]: [com.cruelar.cruelars_triforcemod.entities.projectiles.Clawshot_Head:shoot:209]: EntityPlayerMP['Player99'/356, l='Triforce Test', x=161.70, y=74.62, z=255.17]
-
[Reopened again][1.12.2] How to change blockstate based on helditem
_Cruelar_ replied to _Cruelar_'s topic in Modder Support
I haven't overrode the methods. now it works with new placed Blocks although the ones I placed before the change still don't work. Thanks. -
Like this? 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.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.Objects; 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.MAIN_HAND); Clawshot_Head clawshot_head = new Clawshot_Head(world, entityPlayer); if (!world.isRemote) { if (this.getTagCompoundSafe(itemStack).getBoolean("shot")) { this.getTagCompoundSafe(itemStack).setBoolean("shot",true); world.spawnEntity(clawshot_head); } 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; } } PS: NBT never worked for me. I've never understand what to do.
-
[Reopened again][1.12.2] How to change blockstate based on helditem
_Cruelar_ replied to _Cruelar_'s topic in Modder Support
The Textures doesn't change anymore after reloading the world. Is there a way to fix that? -
Removed that. Removed that. So when checking for the head beeing not null also check for !world..isRemote ? Like that: @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer, EnumHand enumHand) { ItemStack itemStack = entityPlayer.getHeldItem(EnumHand.MAIN_HAND); if (clawshot_head==null) { Clawshot_Head clawshot_head1 = new Clawshot_Head(world, entityPlayer); clawshot_head=clawshot_head1; if (!world.isRemote) { world.spawnEntity(clawshot_head); } } else if (!world.isRemote){ clawshot_head.setDead(); clawshot_head=null; } return new ActionResult(EnumActionResult.SUCCESS,itemStack); } So what should I use?
-
Problem this @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer entityPlayer, EnumHand enumHand) { ItemStack itemStack = entityPlayer.getHeldItem(EnumHand.MAIN_HAND); Item item = entityPlayer.getHeldItemMainhand().getItem(); if (item == this) { if (clawshot_head==null) { Clawshot_Head clawshot_head1 = new Clawshot_Head(world, entityPlayer); clawshot_head=clawshot_head1; if (!world.isRemote) { world.spawnEntity(clawshot_head); } } else { clawshot_head.setDead(); clawshot_head=null; } } return new ActionResult(EnumActionResult.SUCCESS,itemStack); } gets called multible times per use of item. Would it be better to use onItemUseFinish?
-
Inevitable client freeze and then time out?
_Cruelar_ replied to Leiffality's topic in Support & Bug Reports
Look at the game logs of the player that freezed and also at the Server logs. You can provide these to get more help.(Use pastebin or Github for larger files) -
Do you use the new Minecraft Launcher? Because I'm not able to open the crashreport with the link they provide. Search in the folder manually if this is the case.
-
Now it moves and I can fire it but it respawns after its "death" and starts to move again. Clawshot_head: package com.cruelar.cruelars_triforcemod.entities.projectiles; import io.netty.buffer.ByteBuf; import net.minecraft.block.material.Material; 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; private boolean shouldRetarct=false; 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.posX); 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; if (this.ticksInGround >= 1200) { 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.shouldRetarct=true; } } 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; } } if (iblockstate.getMaterial() != Material.WATER) { this.motionY -= 0.03D; } 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; net.minecraftforge.event.entity.player.ItemFishedEvent event = null; 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 0; } 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); 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() { } } } Everything else is the same. Do I need a Capability to allow only one Clawshot head per Player?
-
Could anyone look for a solution please, I need this working. Here's my code: Clawshot: 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.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.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.Objects; 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.MAIN_HAND); Item item = entityPlayer.getHeldItemMainhand().getItem(); if (item == this) { Clawshot_Head clawshot_head = new Clawshot_Head(world,entityPlayer); if (!world.isRemote) { world.spawnEntity(clawshot_head); } } return new ActionResult(EnumActionResult.SUCCESS,itemStack); } @SideOnly(Side.CLIENT) public void initModel(){ ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory")); } } Clawshot_Head: package com.cruelar.cruelars_triforcemod.entities.projectiles; import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityFishHook; 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.AxisAlignedBB; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; 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; 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.posX); 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 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_){} 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); 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(EntityFishHook.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() { } } }
-
Guide I used without animation with animation
- 1 reply
-
- 1
-
This means he couldn't find a block, item, etc. that was in the world already. this could mean: A mod is missing. Ask the Player you've got the world from. A mod has another version than it originally had. Ask the Player you've got the world from. In your log it's the entity cfm.mirror. You should be able to continue starting the server when you type /fml confirm
-
Please give more information. This can mean almost everything
-
Rendering code not running (Render box problem?)
_Cruelar_ replied to MrJake's topic in Modder Support
There's a explanation by Animefan8888, may it helps (honestly I never used TESR, I've just started with modding so this is the only help I can give) http://www.minecraftforge.net/forum/topic/65310-tileentity-animation-system-explanation/ -
So like this? @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); } }
-
Problem: this results in a NPE @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(entityPlayer.getEntityId()); } @Override public void readSpawnData(ByteBuf additionalData) { EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt()); if (entityByID!=null){ entityPlayer=entityByID; } this.shoot(entityPlayer); } the log: minecraft crash report:
-
Is this better or would always write and always read be better? @Override public void writeSpawnData(ByteBuf buffer) { if (entityPlayer!=null) { buffer.writeInt(entityPlayer.getEntityId()); } } @Override public void readSpawnData(ByteBuf additionalData) { EntityPlayer entityByID=(EntityPlayer) world.getEntityByID(additionalData.readInt()); if (entityByID!=null){ entityPlayer=entityByID; } if (world.isRemote){ this.shoot(entityPlayer); } } Also I'm still not sure where shoot would be best. I've tried in onItemRightClick what resulted in this:
-
Rendering code not running (Render box problem?)
_Cruelar_ replied to MrJake's topic in Modder Support
Not important but in the Series the gate has an diameter of 6.7m and an inner diameter of 5.0m. Just saying. Also you could look at Stargate-Atlantiscraft a Stargate mod for 1.12.2 based on Greg's SGCraft.