Jump to content

CactusCoffee

Members
  • Posts

    30
  • Joined

  • Last visited

Converted

  • Gender
    Male

CactusCoffee's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Hi, Having an issue with an entity that extends EntityThrowable. Sometimes, especially if the thrower is moving forwards, the projectile will register a hit as soon as it spawns, but only on the client side. If the player catches up with the projectile, this can continue to occur, often without triggering a hit on the server side. I thought I had found a way to consistently prevent this, but this solution seems to have stopped working. The vanilla projectiles don't seem to have any logic to prevent this, and yet don't have the issue. I'm not sure what the deciding difference is between my projectile and the vanilla ones. The projectile class: public class EntityMagicOrb extends EntityThrowable implements IEntityAdditionalSpawnData { private SpellProjectile spell; public byte data; private int ignoreTime; public EntityMagicOrb(World world) { super(world); } public EntityMagicOrb(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } public EntityMagicOrb(World world, EntityPlayer player, SpellProjectile spell) { super(world, player); this.ignoreEntity = player; this.spell = spell; } @Override protected void onImpact(@Nonnull RayTraceResult result) { boolean kill = false; if (result.typeOfHit == RayTraceResult.Type.ENTITY) { if (!result.entityHit.isDead) { Entity targetEntity = result.entityHit; MultiPartEntityPart part = null; if (targetEntity instanceof MultiPartEntityPart) { part = (MultiPartEntityPart) targetEntity; IEntityMultiPart ientitymultipart = part.parent; if (ientitymultipart instanceof EntityLivingBase) { targetEntity = (EntityLivingBase) ientitymultipart; } } if (spell.projectileEffectOnEntity(this, (EntityPlayer) this.getThrower(), targetEntity, this.getEntityWorld(), part)) { kill = true; } } } else if (result.typeOfHit == RayTraceResult.Type.BLOCK) { if (spell.projectileEffectOnBlock(this, (EntityPlayer) this.getThrower(), this.getEntityWorld(), result.getBlockPos(), result.sideHit)) { kill = true; } } else { spell.projectileEffect(this, (EntityPlayer) this.getThrower(), this.getEntityWorld()); kill = true; } if (kill && !world.isRemote) { this.setDead(); } } @Override public void onUpdate() { if (spell == null) { setDead(); } else { spell.projectileTick(this, this.world); } } public void adjustStartPos() { this.posX += motionX; this.posY += motionY; this.posZ += motionZ; } public Element getElement() { return spell.getElement(); } @Override protected float getGravityVelocity() { return 0.02F; } @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setByte("Spell", (byte) spell.getIndex()); nbt.setByte("Data", data); return nbt; } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); spell = (SpellProjectile) Spells.getFromList(nbt.getByte("Spell")); data = nbt.getByte("Data"); } @Override public void writeSpawnData(ByteBuf buffer) { if (spell != null) { buffer.writeInt(spell.getIndex()); } else { buffer.writeInt(-1); } buffer.writeByte(data); } @Override public void readSpawnData(ByteBuf additionalData) { spell = (SpellProjectile) Spells.getFromList(additionalData.readInt()); data = additionalData.readByte(); } public void processProjectile() { if (this.ticksExisted > 100 || this.inGround) { this.setDead(); } else { this.lastTickPosX = this.posX; this.lastTickPosY = this.posY; this.lastTickPosZ = this.posZ; if (!this.world.isRemote) { this.setFlag(6, this.isGlowing()); } this.onEntityUpdate(); 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); } 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; boolean flag = false; for (Entity entity1 : list) { if (entity1.canBeCollidedWith()) { if (entity1 == this.ignoreEntity) { flag = true; } else if (this.thrower != null && this.ticksExisted < 2 && this.ignoreEntity == null) { this.ignoreEntity = entity1; flag = true; } else { flag = false; AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().grow(0.3D); RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, vec3d1); if (raytraceresult1 != null) { double d1 = vec3d.squareDistanceTo(raytraceresult1.hitVec); if (d1 < d0 || d0 == 0.0D) { entity = entity1; d0 = d1; } } } } } if (this.ignoreEntity != null) { if (flag) { this.ignoreTime = 2; } else if (this.ignoreTime-- <= 0) { this.ignoreEntity = null; } } if (entity != null) { raytraceresult = new RayTraceResult(entity); } if (raytraceresult != null) { if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && this.world.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.PORTAL) { this.setPortal(raytraceresult.getBlockPos()); } else if (!net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) { this.onImpact(raytraceresult); } } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI)); 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; if (!this.hasNoGravity()) { this.motionY -= this.getGravityVelocity(); } this.setPosition(this.posX, this.posY, this.posZ); } } } Note: processProjectile() is mostly copied from the superclass onUpdate(), but modified to remove collision with water. I've tested with both this method and the normal onUpdate(), it's not the source of the issue. And here's the code that spawns the projectile: public boolean spawnProjectile(EntityPlayer player, World world) { if (!world.isRemote) { EntityMagicOrb entity = new EntityMagicOrb(world, player, this); entity.setNoGravity(true); onProjectileShoot(entity, player); entity.adjustStartPos(); world.spawnEntity(entity); return true; } return false; }
  2. Seems like it sorted itself out after a PC restart.
  3. I did this, it still did not work. Gradle tasks are no longer present, and I can't run anything.
  4. Hi, getting back into modding with an existing project. Again. I just hit the "Detach Gradle" button in Intellij due to a misclick and it seems to have irrevocably trashed my entire project structure. Right now I am trying to restart by pasting the source code into a fresh forge project, but I am running into trouble when trying to resolve the standard external libraries in the new project. I have redownloaded forge MDK, run setupDecompWorkspace, cleaned out gradle folder in my user home to be safe, double checked tutorials to make sure I'm not forgetting anything. But standard external libraries including the decompiled base game source are not generated, only "compileDummy.jar" and "providedDummy.jar", so I can't continue. Any idea what is going wrong so I can start fresh?
  5. Found the problem. It wasn't getting called because registerEntities wasn't static, since I'm using @Mod.EventBusSubscriber. I knew this would be something stupid, but I didn't think it would be something that stupid. Thank you.
  6. It looks like my entity registration method isn't being called at all. The entity registration itself may be wrong too. Here's the registration method: @SubscribeEvent public void registerEntities(RegistryEvent.Register<EntityEntry> event) { System.out.println("Registering Mod Entities"); EntityEntry entry = EntityEntryBuilder.create() .entity(EntityMagicOrb.class) .id(new ResourceLocation(MagicMod.MODID, "magic_orb"), 0) .name("magic_orb") .tracker(64, 20, true) .build(); event.getRegistry().register(entry); }
  7. Ah. I did have a feeling it wasn't quite right - i noticed after i marked this solved that the explosion caused by the projectile on impact was slightly off from where it appeared to hit. Thanks for calling that out. The World constructor in the entity class didn't do it, though. Here are the constructors I added: public EntityMagicOrb(World world) { super(world); } public EntityMagicOrb(World world, SpellProjectile spell) { super(world); this.spell = spell; }
  8. It actually ended up being something even dumber that I overlooked. In the code I copied from 1.7.10 for spawning the projectile, I had an if (!world.isRemote) check before spawning the entity. So of course the entity didn't appear client-side. Getting rid of that check fixed the issue. Not sure why it worked in 1.7.10, but whatever. Thank you.
  9. Hi, I'm working on updating my old mod from 1.7.10 to 1.12.2. I'm having trouble updating one of my entities (a projectile similar to a snowball). The entity itself works fine, but I haven't been able to get it to render; it's invisible. I've looked around tutorials and this forum for a while but haven't found anything that worked. Here's my entity renderer class: public class RenderMagicOrb extends Render<EntityMagicOrb> { private static ResourceLocation TEXTURE_RED = new ResourceLocation(MagicMod.MODID, "textures/entity/magic_orb_red.png"); private static ResourceLocation TEXTURE_YELLOW = new ResourceLocation(MagicMod.MODID, "textures/entity/magic_orb_yellow.png"); private static ResourceLocation TEXTURE_GREEN = new ResourceLocation(MagicMod.MODID, "textures/entity/magic_orb_green.png"); private static ResourceLocation TEXTURE_BLUE = new ResourceLocation(MagicMod.MODID, "textures/entity/magic_orb_blue.png"); private static ResourceLocation TEXTURE_BLACK = new ResourceLocation(MagicMod.MODID, "textures/entity/magic_orb_black.png"); private static ResourceLocation TEXTURE_WHITE = new ResourceLocation(MagicMod.MODID, "textures/entity/magic_orb_white.png"); public RenderMagicOrb(RenderManager renderManagerIn) { super(renderManagerIn); } public void doRender(@Nonnull EntityMagicOrb entity, double x, double y, double z, float entityYaw, float partialTicks) { GlStateManager.pushMatrix(); bindEntityTexture(entity); GlStateManager.translate((float)x, (float)y, (float)z); GlStateManager.enableRescaleNormal(); GlStateManager.scale(2.0F, 2.0F, 2.0F); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); GlStateManager.rotate(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * -this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F); if (renderOutlines) { GlStateManager.enableColorMaterial(); GlStateManager.enableOutlineMode(this.getTeamColor(entity)); } bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL); bufferbuilder.pos(-0.5D, -0.25D, 0.0D).tex(0.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); bufferbuilder.pos(0.5D, -0.25D, 0.0D).tex(1.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); bufferbuilder.pos(0.5D, 0.75D, 0.0D).tex(1.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); bufferbuilder.pos(-0.5D, 0.75D, 0.0D).tex(0.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex(); tessellator.draw(); if (renderOutlines) { GlStateManager.disableOutlineMode(); GlStateManager.disableColorMaterial(); } GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); super.doRender(entity, x, y, z, entityYaw, partialTicks); } @Override protected ResourceLocation getEntityTexture(@Nonnull EntityMagicOrb entity) { switch (entity.getElement()) { case RED: return TEXTURE_RED; case YELLOW: return TEXTURE_YELLOW; case GREEN: return TEXTURE_GREEN; case BLUE: return TEXTURE_BLUE; case BLACK: return TEXTURE_BLACK; case WHITE: return TEXTURE_WHITE; } //Default, should never happen return TEXTURE_RED; } } And here's my ClientProxy: @Mod.EventBusSubscriber(Side.CLIENT) public class ClientProxy extends CommonProxy { @Override public void preInit(FMLPreInitializationEvent e) { super.preInit(e); RenderingRegistry.registerEntityRenderingHandler(EntityMagicOrb.class, new IRenderFactory<EntityMagicOrb>() { @Override public Render<? super EntityMagicOrb> createRenderFor(RenderManager manager) { return new RenderMagicOrb(manager); } }); } @SubscribeEvent public static void registerModels(ModelRegistryEvent event) { } @Override public void registerItemRenderer(Item item, int meta, String id) { ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(MagicMod.MODID + ":" + id, "inventory")); } } Here's the entity class itself, though I don't think it's the problem public class EntityMagicOrb extends EntityThrowable implements IEntityAdditionalSpawnData { private SpellProjectile spell; private float gravity = 0.03F; public EntityMagicOrb(World world, EntityPlayer player, SpellProjectile spell) { super(world, player); this.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F); this.spell = spell; } @Override protected void onImpact(RayTraceResult result) { spell.projectileEffect(this, (EntityPlayer) this.getThrower(), this.getEntityWorld()); if (!this.world.isRemote) { this.world.setEntityState(this, (byte)3); this.setDead(); } } @Override public void onUpdate() { super.onUpdate(); if (this.ticksExisted > 400) setDead(); } public Element getElement() { return spell.getElement(); } @Override protected float getGravityVelocity() { return gravity; } @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setByte("Spell", (byte) Spells.getPlaceInList(spell)); return nbt; } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); spell = (SpellProjectile) Spells.getFromList(nbt.getByte("Spell")); } @Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(Spells.getPlaceInList(spell)); } @Override public void readSpawnData(ByteBuf additionalData) { spell = (SpellProjectile) Spells.getFromList(additionalData.readInt()); } } What am I missing?
  10. ...Well I'm dumbfounded. Changed it so it got the list from a function instead of a parameter, and added all the blocks. It works just fine. I could swear I tried that before and still got an error. But I guess it doesn't matter, it works. Current status: still incompetent Thanks for your help.
  11. I thought that was the case. My list currently contains only the items. When I try adding one of the blocks (using Item.getItemFromBlock()), however, I get a nullPointerException: java.lang.NullPointerException: null key in entry: null=0 at com.google.common.collect.CollectPreconditions.checkEntryNotNull(CollectPreconditions.java:31) at com.google.common.collect.ImmutableMap.entryOf(ImmutableMap.java:135) at com.google.common.collect.ImmutableMap$Builder.put(ImmutableMap.java:206) at com.google.common.collect.ExplicitOrdering.buildRankMap(ExplicitOrdering.java:56) at com.google.common.collect.ExplicitOrdering.<init>(ExplicitOrdering.java:32) at com.google.common.collect.Ordering.explicit(Ordering.java:162) at com.finneyt.simplymagic.main.SimplyMagicMod.preInit(SimplyMagicMod.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513) at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239) at net.minecraft.client.Minecraft.startGame(Minecraft.java:522) at net.minecraft.client.Minecraft.run(Minecraft.java:931) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source)
  12. It's me again. So I want to sort my mod's creative tab so it isn't a jumbled mess like the vanilla ones, and so I don't have to change item IDs every time I add new stuff to keep the tab neat. I've attempted to follow diesieben07's tutorial on the matter: http://www.minecraftforge.net/forum/index.php/topic,23782.msg120743.html#msg120743 However, I get this error: com.google.common.collect.Ordering$IncomparableValueException: Cannot compare value: net.minecraft.item.ItemBlock@509e4bc4 at com.google.common.collect.ExplicitOrdering.rank(ExplicitOrdering.java:46) at com.google.common.collect.ExplicitOrdering.compare(ExplicitOrdering.java:40) at com.google.common.collect.ByFunctionOrdering.compare(ByFunctionOrdering.java:46) at java.util.TimSort.countRunAndMakeAscending(Unknown Source) at java.util.TimSort.sort(Unknown Source) at java.util.Arrays.sort(Unknown Source) at java.util.ArrayList.sort(Unknown Source) at java.util.Collections.sort(Unknown Source) at com.finneyt.simplymagic.main.SimplyMagicMod$1.displayAllReleventItems(SimplyMagicMod.java:100) at net.minecraft.client.gui.inventory.GuiContainerCreative.setCurrentCreativeTab(GuiContainerCreative.java:508) at net.minecraft.client.gui.inventory.GuiContainerCreative.mouseMovedOrUp(GuiContainerCreative.java:482) at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:354) at net.minecraft.client.gui.inventory.GuiContainer.handleMouseInput(GuiContainer.java) at net.minecraft.client.gui.inventory.GuiContainerCreative.handleMouseInput(GuiContainerCreative.java:598) at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:313) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1720) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) at net.minecraft.client.Minecraft.run(Minecraft.java:951) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) Here's the relevant code: import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import com.google.common.base.Function; import com.google.common.collect.Ordering; public class Mod... { private static Comparator<ItemStack> tabComp; public static final CreativeTabs tab = new CreativeTabs(MODID + "_" + "tab") { @Override @SideOnly(Side.CLIENT) public void displayAllReleventItems(List items) { super.displayAllReleventItems(items); Collections.sort(items, tabComp); } }; @EventHandler public void preInit(FMLPreInitializationEvent event) { tabComp = Ordering.explicit(ModItems.ITEM_ORDER).onResultOf(new Function<ItemStack, Item>() { @Override public Item apply(ItemStack i) { return i.getItem(); } }); } } Please let me know what I'm doing wrong, I don't like being incompetent
  13. So I've looked at ScratchForFun's tutorial on the NEI API and did everything as he did - but I get an error. I have the dev & source versions of CCC and NEI, set up the build paths, got them in the mods folder, but nothing's working. Checked the source code and the class it's looking for doesn't seem to be there. Do I need a different version or something?
  14. I have a few technical blocks and items in my mod that I would like to prevent from being spawnable via mods like NEI and ideally via commands as well. Is there any way to make this possible?
×
×
  • Create New...

Important Information

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