Jump to content

fcelon

Members
  • Posts

    115
  • Joined

  • Last visited

Everything posted by fcelon

  1. I just found it. @Override public boolean canBeCollidedWith() { return true; } After adding this to the code the entity works fine.
  2. super.readEntityFromNBT doesn't work. Cannot directly invoke the abstract method readEntityFromNBT(NBTTagCompound) for the type Entity
  3. Even without the @Override annotation calling the super.readFromNBT still causes the infinite loop.
  4. With the readEntityFromNBT and writeEntityToNBT methods calling super, an infinite loop will be created (readFromNBT calls readEntityFromNBT). I have already tried this and the entity could not be summoned.
  5. Hello, I have created my own entity, but I can't interact with it. When I spawn it into the world, I can see it's hitbox, but clicking on it does nothing and I can even place blocks right into it. This is my entity code. What should I do to make the hitbox work? import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.World; public class EntityBallista extends Entity { public EntityBallista(World worldIn) { super(worldIn); this.setSize(3, 2); this.entityCollisionReduction = 1; System.out.println(this.getEntityBoundingBox()); System.out.println(this.getCollisionBox(this)); } @Override public AxisAlignedBB getCollisionBox(Entity entityIn) { return entityIn.getEntityBoundingBox(); } public boolean processInitialInteract(EntityPlayer player, EnumHand hand) { System.out.println("Interacting"); if (player.isSneaking()) { return false; } else if (this.isBeingRidden()) { return true; } else { if (!this.world.isRemote) { player.startRiding(this); } return true; } } @Override protected void entityInit() { } @Override protected void readEntityFromNBT(NBTTagCompound compound) { //super.readFromNBT(compound); } @Override protected void writeEntityToNBT(NBTTagCompound compound) { //super.writeToNBT(compound); } } Thanks for any help.
  6. Hello, does minecraft forge add a way to imlement custom item models? I know JSON models allow to do a lot of things, but they aren't limitless. For example vanilla shields do have a custom model similar to entities. Is there any way how to add custm model for my own items?
  7. Hello, how can I make my custom item render as an entity when held (like shields or chests do)? I know I have to set parent in it's json model file to buildin/entity, but how can I attach entity model to that item? Thanks for any help.
  8. I created an enchantment, that made a tool break faster all blocks, not just those, that it can mine. However, for that I need the tool effeciency, because I need to set how fast it should mine them. Back in 1.11.2 I used event.setNewSpeed(event.getOriginalSpeed()*(tool.getToolMaterial().getEfficiencyOnProperMaterial()/2)); which made tool break block it is not supposed to faster than hand, but slower than blocks, that it can mine properly. Is there another way, how to do that?
  9. You can create a public list in your item registry and add all of your items (at least those you want to be dropped from that item) ot that list while registering them. You can then select a random item from that list. I think it's propably the fastest way.
  10. Hello, is there any way, how to get tool effeciency in 1.12.1? I used tool.getToolMaterial().getEfficiencyOnProperMaterial(), but it doesn't work anymore. In 1.12 there is no tool.getToolMaterial, just tool.getToolMaterialName, which is totally useless for me. I know there is tool.getStrVsBlock, but thant only returns tool efficiency if the block in can be properly harvested by the tool. Is there still a way how to get tool efficiency in 1.12.1? If not, then the new minecraft version sucks. Thanks for any help
  11. Do not try to modify entity motion. If you want to make it move faster/slower, apply attribute modifier to it's movement speed attribute. Use entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).applyModifier(new AttributeModifier((UUID idIn, String nameIn, double amountIn, int operationIn))); to apply attribute modifier and entity.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).removeModifier(UUID idIn) to remove the modifier, when you don't need it. If you don't understand, look at https://minecraft.gamepedia.com/Attribute to see how attributes and modifiers work.
  12. Hello, what is the best way to attach my own NBT data to vanilla items? I tried to my own capability for that, but I am having some issues with it (see ). It looks like the data get attached to the item, but in fsct they don't. Should I use a different way? Thanks for any help.
  13. So nobody knows, what is wrong?
  14. Hello Is there any way, how to rotate and translate item held in player's hand without modifying item model files? For example when I want to make item move and rotate when being used. Thanks for any help
  15. This is not in bow code. Whenever a player is using an item, it's movement speed is reduced. Unfortunately, it looks like something, than can not be changed.
  16. Oh, and now it works. I don't know what I' ve been doing wrong all the time.
  17. Try watching this video.
  18. Hello, I have created a capability for item to allow players to apply potion effects on swords. However it doesn't work. Everything seems to be OK, but I'm not able to apply my capability to any item. What's the problem? Capability: public class Poison implements IPoison{ private PotionType type; private List<PotionEffect> effects = new ArrayList<PotionEffect>(); private int remaininghits; @Override public void setHitsRemaining(int hits) { this.remaininghits = hits; } @Override public void removehits(int hits) { this.remaininghits -= hits; if (this.remaininghits<=0) { this.type = null; this.setEffects(new ArrayList<PotionEffect>()); System.out.println("Out of hits"); } } @Override public int getHitsRemaining() { return this.remaininghits; } @Override public void setType(PotionType type) { this.type = type; } @Override public void setEffects(List<PotionEffect> effects) { this.effects = effects; } @Override public List<PotionEffect> getEffects() { if (this.effects.isEmpty() && type != null) { return type.getEffects(); } return effects; } @Override public PotionType getType() { return this.type; } @Override public List<PotionEffect> getEffectList() { return this.effects; } } Interface: public interface IPoison { public void setType (PotionType type); public void setEffects (List<PotionEffect> effects); public void setHitsRemaining (int hits); public void removehits (int hits); public PotionType getType(); public List<PotionEffect> getEffectList(); public int getHitsRemaining(); public List<PotionEffect> getEffects(); } Provider: public class PoisonProvider implements ICapabilitySerializable<NBTTagCompound>{ @CapabilityInject(IPoison.class) public static final Capability<IPoison> POISON_CAP = null; private IPoison instance = POISON_CAP.getDefaultInstance(); @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == POISON_CAP; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == POISON_CAP ? POISON_CAP.<T> cast(this.instance) : null; } @Override public NBTTagCompound serializeNBT() { return (NBTTagCompound) POISON_CAP.getStorage().writeNBT(POISON_CAP, this.instance, null); } @Override public void deserializeNBT(NBTTagCompound nbt) { POISON_CAP.getStorage().readNBT(POISON_CAP, instance, null, nbt); } } Storage: public class PoisonStorage implements IStorage<IPoison>{ @Override public NBTTagCompound writeNBT(Capability<IPoison> capability, IPoison instance, EnumFacing side) { NBTTagCompound compound = new NBTTagCompound(); if (instance.getType() != null) { ResourceLocation resourcelocation = (ResourceLocation)PotionType.REGISTRY.getNameForObject(instance.getType()); compound.setString("Type", resourcelocation.toString()); } if (!instance.getEffectList().isEmpty()) { NBTTagList nbttaglist = new NBTTagList(); for (PotionEffect potioneffect : instance.getEffects()) { nbttaglist.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound())); } compound.setTag("CustomPotionEffects", nbttaglist); } compound.setInteger("RemainingHits", instance.getHitsRemaining()); return compound; } @Override public void readNBT(Capability<IPoison> capability, IPoison instance, EnumFacing side, NBTBase nbt) { NBTTagCompound compound = (NBTTagCompound) nbt; if (compound.hasKey("Potion")) { instance.setType(PotionUtils.getPotionTypeFromNBT(compound)); } if (compound.hasKey("CustomPotionEffects")) { instance.setEffects(PotionUtils.getEffectsFromTag(compound)); } instance.setHitsRemaining(((NBTTagCompound)nbt).getInteger("RemainingHits")); } } Event Handler: public class ModWeaponHandler { public static final ResourceLocation POISON_CAP = new ResourceLocation(Reference.MOD_ID, "poison"); @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(AnvilUpdateEvent event) { if(event.getLeft().getItem() instanceof ItemSword && event.getRight().getItem() instanceof ItemPotion && event.getOutput() == ItemStack.EMPTY) { ItemStack output = event.getLeft().copy(); IPoison poison = output.getCapability(PoisonProvider.POISON_CAP, null); poison.setType(PotionUtils.getPotionFromItem(event.getRight())); if (event.getRight().getTagCompound().hasKey("CustomPotionEffects")) { poison.setEffects(PotionUtils.getEffectsFromStack(event.getRight())); } poison.setHitsRemaining(64); event.setCost(1); event.setOutput(output); } } @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(ItemTooltipEvent event) { if (event.getItemStack().getItem() instanceof ItemSword) { IPoison poison = event.getItemStack().getCapability(PoisonProvider.POISON_CAP, null); if (!poison.getEffects().isEmpty()) { for (PotionEffect effect : poison.getEffects()) { String name = effect.getPotion().getName(); if (effect.getDuration()!=0) { String s1 = I18n.translateToLocal(name).trim(); if (effect.getAmplifier() > 0) { s1 = s1 + " " + I18n.translateToLocal("potion.potency." + effect.getAmplifier()).trim(); } if (effect.getDuration() > 20) { s1 = s1 + " (" + Potion.getPotionDurationString(effect, 1) + ")"; } event.getToolTip().add(TextFormatting.RED + s1); } event.getToolTip().add(poison.getHitsRemaining() + " hits remaining"); } } } } @SubscribeEvent(priority=EventPriority.HIGHEST, receiveCanceled=true) public void onEvent(LivingAttackEvent event) { if (event.getSource().getSourceOfDamage() !=null) { if (event.getSource().getSourceOfDamage() instanceof EntityLivingBase) { EntityLivingBase attacker = (EntityLivingBase) event.getSource().getSourceOfDamage(); if (attacker.getHeldItemMainhand().getItem() instanceof ItemSword && !attacker.world.isRemote) { IPoison poison = attacker.getHeldItemMainhand().getCapability(PoisonProvider.POISON_CAP, null); System.out.println(poison.getEffects()); System.out.println(poison.getHitsRemaining()); if (!poison.getEffects().isEmpty() && event.getEntityLiving().hurtResistantTime<10) { for (PotionEffect effect : poison.getEffects()) { if (effect.getPotion().isInstant()) { effect.getPotion().affectEntity(null, event.getSource().getSourceOfDamage(), event.getEntityLiving(), effect.getAmplifier(), 1/6D); event.getEntityLiving().hurtResistantTime = 0; } else { event.getEntityLiving().addPotionEffect(new PotionEffect(effect)); } } poison.removehits(1); } } } } } @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(AttachCapabilitiesEvent.Item event) { if (event.getItemStack().getItem() instanceof ItemSword) { if (!event.getItemStack().hasCapability(PoisonProvider.POISON_CAP, null)) { event.addCapability(POISON_CAP, new PoisonProvider()); } } } } I can combine sword and potion in the anvil, but the output doesn't have any capability attached. Capability is registered in preInit by CapabilityManager.INSTANCE.register(IPoison.class, new PoisonStorage(), Poison.class); Event handler is registered in Init by MinecraftForge.EVENT_BUS.register(new ModWeaponHandler()); I have already created a very similar cap in the past and it worked perfectly, I don't know what is the problem now. Thanks for any help.
  19. Thanks you, it works. However I am currently in 1.11 and I don't have any problems with hiding thetexture.
  20. Hello, I have spent many hours trying to figure out how to rotate palyer's arm. I have already asked on forum, but it seems nobody knows how to do it. Now it seems I have found a solution, but there is a different problem. @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderPlayerEvent.Pre event) { event.getRenderer().getMainModel().bipedRightArm.isHidden=true; } @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderPlayerEvent.Post event) { EntityPlayer player = event.getEntityPlayer(); event.getRenderer().getMainModel().bipedRightArm.isHidden=false; event.getRenderer().getMainModel().bipedRightArm.rotationPointZ = -MathHelper.sin((float) Math.toRadians(player.renderYawOffset)) * 5.0F; event.getRenderer().getMainModel().bipedRightArm.rotationPointY = 20; event.getRenderer().getMainModel().bipedRightArm.rotationPointX = -MathHelper.cos((float) Math.toRadians(player.renderYawOffset)) * 5.0F; event.getRenderer().getMainModel().bipedRightArm.rotateAngleX = (float) X; event.getRenderer().getMainModel().bipedRightArm.rotateAngleY = (float) -Math.toRadians(player.renderYawOffset); event.getRenderer().getMainModel().bipedRightArm.rotateAngleZ = (float) Z; event.getRenderer().getMainModel().bipedRightArm.renderWithRotation(0.0625F); event.getRenderer().getMainModel().bipedRightArm.rotationPointY = 2; } It only works if player's hand is empty. If player is holding any item, texture of the arm starts to look realy wierd. Does anyone know why is this happening and how to fix it? Thanks for any help.
  21. I have tried messing with the values and it seems the arm now renders in the right spot. @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderPlayerEvent.Pre event) { event.getRenderer().getMainModel().bipedRightArm.isHidden=true; } @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderPlayerEvent.Post event) { EntityPlayer player = event.getEntityPlayer(); event.getRenderer().getMainModel().bipedRightArm.isHidden=false; event.getRenderer().getMainModel().bipedRightArm.rotationPointZ = -MathHelper.sin((float) Math.toRadians(player.renderYawOffset)) * 5.0F; event.getRenderer().getMainModel().bipedRightArm.rotationPointY = 20; event.getRenderer().getMainModel().bipedRightArm.rotationPointX = -MathHelper.cos((float) Math.toRadians(player.renderYawOffset)) * 5.0F; event.getRenderer().getMainModel().bipedRightArm.rotateAngleX = (float) X; event.getRenderer().getMainModel().bipedRightArm.rotateAngleY = (float) -Math.toRadians(player.renderYawOffset); event.getRenderer().getMainModel().bipedRightArm.rotateAngleZ = (float) Z; event.getRenderer().getMainModel().bipedRightArm.renderWithRotation(0.0625F); event.getRenderer().getMainModel().bipedRightArm.rotationPointY = 2; } However, it only works if player's hand is empty. If player is holding any item, texture of the arm starts to look realy wierd.
  22. I made sme progress in it. @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderPlayerEvent.Post event) { EntityPlayer player = event.getEntityPlayer(); if (player.getHeldItemMainhand() == ItemStack.EMPTY) { event.getRenderer().getMainModel().bipedRightArm.isHidden=false; event.getRenderer().getMainModel().bipedRightArm.rotateAngleX = X; event.getRenderer().getMainModel().bipedRightArm.rotateAngleY = Y; event.getRenderer().getMainModel().bipedRightArm.rotateAngleZ = Z; event.getRenderer().getMainModel().bipedRightArm.renderWithRotation(0.0625F); } } @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderPlayerEvent.Pre event) { EntityPlayer player = event.getEntityPlayer(); if (player.getHeldItemMainhand() == ItemStack.EMPTY) { event.getRenderer().getMainModel().bipedRightArm.isHidden=true; } } Now it seems I can mess with the angles. Unfortunately, the arm is being rendered in wrong spot and I don't know, how to fix it.
  23. Hello, I am trying to render my custom projectile, but it seems to not load the texture. This is my code. package com.mujmajnkraft.bettersurvival.client.render; import javax.annotation.Nonnull; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import com.mujmajnkraft.bettersurvival.entities.EntityFlyingSpear; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; public class RenderFlyingSpear extends Render<EntityFlyingSpear> { public RenderFlyingSpear(RenderManager renderManager) { super(renderManager); } @Override public void doRender(@Nonnull EntityFlyingSpear entity, double x, double y, double z, float entityYaw, float partialTicks) { // preface: Remember that the rotations are applied in reverse order. // the rendering call does not apply any transformations. // That'd screw things up, since it'd be applied before our transformations // So remember to read this from the rendering call up to this line // can be overwritten in customRendering //toolCoreRenderer.setDepth(1/32f); ItemStack item = entity.getSpear(); GL11.glPushMatrix(); GL11.glEnable(GL12.GL_RESCALE_NORMAL); // last step: translate from 0/0/0 to correct position in world GL11.glTranslated(x, y, z); // mkae it smaller GL11.glScalef(0.5F, 0.5F, 0.5F); customRendering(entity, x, y, z, entityYaw, partialTicks); // arrow shake float f11 = (float) entity.arrowShake - partialTicks; if(f11 > 0.0F) { float f12 = -MathHelper.sin(f11 * 3.0F) * f11; GL11.glRotatef(f12, 0.0F, 0.0F, 1.0F); } if(renderManager == null || renderManager.renderEngine == null) { return; } // draw correct texture. not some weird block fragments. renderManager.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); if(item != null) { Minecraft.getMinecraft().getRenderItem().renderItem(item, ItemCameraTransforms.TransformType.NONE); } else { ItemStack dummy = new ItemStack(Items.STICK); Minecraft.getMinecraft().getRenderItem().renderItem(dummy, Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager().getMissingModel()); } GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); } public void customRendering(EntityFlyingSpear entity, double x, double y, double z, float entityYaw, float partialTicks) { // flip it, flop it, pop it, pull it, push it, rotate it, translate it, TECHNOLOGY // rotate it into the direction we threw it GL11.glRotatef(entity.rotationYaw, 0f, 1f, 0f); GL11.glRotatef(-entity.rotationPitch, 1f, 0f, 0f); // adjust "stuck" depth if(entity.isInGround()) { GL11.glTranslated(0, 0, 0); } customCustomRendering(entity, x, y, z, entityYaw, partialTicks); // rotate it so it faces forward GL11.glRotatef(-90f, 0f, 1f, 0f); // rotate the projectile it so it faces upwards GL11.glRotatef(-45, 0f, 0f, 1f); } /** If you just want to rotate it or something but the overall "have it heading towards the target" should stay the same */ protected void customCustomRendering(EntityFlyingSpear entity, double x, double y, double z, float entityYaw, float partialTicks) {} @Override protected ResourceLocation getEntityTexture(EntityFlyingSpear entity) { return TextureMap.LOCATION_MISSING_TEXTURE; } } This is mostly copied from https://github.com/SlimeKnights/TinkersConstruct/blob/master/src/main/java/slimeknights/tconstruct/library/client/renderer/RenderProjectileBase.java. However the entity looks like black and pink box, not like an item. Other thinks like rotation seem to be fine. Thanks for any help.
  24. Hello, Is there any way how to rotate player arms without creating custom player model? I am sure there has to be some way, because I think Quark mod does exactly that during emote animations. I already tried this: @SideOnly(Side.CLIENT) @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true) public void onEvent(RenderPlayerEvent.Post event) { EntityPlayer player = event.getEntityPlayer(); if (player.getActiveItemStack().getItem() instanceof ItemSpear) { event.getRenderer().getMainModel().bipedRightArm.rotateAngleX = 5; } } It seems everything is right, but it does not do anything. Thanks for help.
  25. I am sorry, I dn't know how could I overlook it so many times, it realy is there.
×
×
  • Create New...

Important Information

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