Jump to content

Eria8

Members
  • Posts

    68
  • Joined

  • Last visited

Everything posted by Eria8

  1. This is the weirdest problem I've ever had when modding. I'm trying to make a gui that renders text over a texture in the corner of the screen. There are four parts of the texture that I'm rendering separately, since if the player doesn't have something I don't want that part to render. It all works perfectly, except the third and fourth parts SOMEHOW are losing my texture and instead it's rendering what looks like the default Minecraft font texture at more than double resolution? Pictures: And this is the code: @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) { if (event.getType() != ElementType.EXPERIENCE) { return; } IEchoesCapability echoes = mc.thePlayer.getCapability(EchoesManager.ECHOES, null); if (echoes == null) { return; } this.mc.getTextureManager().bindTexture(hud); int y = 0; int y1 = 4; if (echoes.getEchoes() > 0) // The rune-like symbol. Works. { this.drawTexturedModalRect(1, y, 0, 0, 136, 29); drawString(mc.fontRendererObj, TextFormatting.WHITE + "" + echoes.getEchoes(), 16, y1, colour); y += 30; y1 += 15; } if (echoes.getInsight() > 0) // The eye symbol. Works. { this.drawTexturedModalRect(1, y, 0, 29, 136, 29); drawString(mc.fontRendererObj, TextFormatting.WHITE + "" + echoes.getInsight(), 16, y1, colour); y += 30; y1 += 15; } int bullets = 0; for (ItemStack stack : mc.thePlayer.inventory.mainInventory) { if (stack.getItem() == Registry.quickSilverBullet) { bullets += stack.func_190916_E(); } } if (bullets > 0) // The bullet symbol. Does NOT work, renders alphabet instead. { this.drawTexturedModalRect(1, y, 0, 58, 91, 29); // TODO draw amount y += 30; y1 += 15; } if (echoes.getCords() > 0) // The spiral-like symbol. Does NOT work, renders alphabet instead. { this.drawTexturedModalRect(1, y, 0, 87, 91, 29); if (echoes.getCords() >= 3) { // TODO alternate cords icon } // TODO draw amount y += 30; y1 += 15; } if (echoes.hasAsh()) { // TODO alternate bullet icon } } How on earth does this happen and how do I fix it? And for the record, I tried adding: this.mc.getTextureManager().bindTexture(hud); pretty much anywhere before it starts displaying the alphabet to try to fix it, but the result is that what ever drawTexturedModalRect() came next just doesn't get called at all.
  2. Nope, if this is what you mean, it still doesn't work. They still all get knocked back in one same direction. for (Entity e : entities) { if (e instanceof EntityLiving && !(e instanceof INPC)) { double x = e.posX - player.posX; // ??? double z = e.posZ - player.posZ; // ??? ((EntityLiving) e).knockBack(e, 4, x, z); } }
  3. The vanilla method just knocks them toward the direction the player is facing.
  4. Distance is simple. And irrelevant to the problem...
  5. No, it's something to do with rotation. Like, as if the player is facing that direction, the entity is knocked backwards in that direction. I assume it's a 360 degree circle converted into a float. No idea if that would make 0.0f the world's North or the direction the player is facing at the time, if that's even correct. But I cannot figure out how to get that rotation in comparison to any entity the player isn't directly facing. Someone do correct me if I'm wrong.
  6. Like the title says, I'm trying to knock back all living entities near the player. But I don't understand how to get the x and z vectors for the knockback. Can someone help with this? // Get all entities within a 5 block [horizontal] radius of the player AxisAlignedBB aoe = player.getEntityBoundingBox().expand(5, 2, 5); List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, aoe); for (Entity e : entities) { // Ignore any entity that isn't living or that is an NPC if (e instanceof EntityLiving && !(e instanceof INPC)) { // These I don't understand how to get: int x = ???; // int z = ???; // ((EntityLiving) e).knockBack(e, 4, x, z); } } The knockback() description for reference if needed: void net.minecraft.entity.EntityLivingBase.knockBack(Entity entityIn, float strenght, double xRatio, double zRatio) Constructs a knockback vector from the given direction ratio and magnitude and adds it to the entity's velocity. If it is on the ground (i.e. this.onGround), the Y-velocity is increased as well, clamping it to .4. The entity's existing horizontal velocity is halved, and if the entity is on the ground the Y-velocity is too. Parameters: strenght Magnitude of the knockback vector, and also the Y-velocity to add if the entity is on the ground. xRatio The X part of the direction ratio of the knockback vector. zRatio The Z part of the direction ratio of the knockback vector. entityIn
  7. This is what I was looking for. I thought that was something else, didn't see that it extended the EntityAIMeleeAttack which apparently now gives mobs the AI to actually attack. Now just have to fix its glitchy movement... Thanks!
  8. Anyone?
  9. Okay that helped fix what I was doing wrong with attributes, but it still does not fix the problem. It's even more evidence that the problem has nothing to do with attributes...
  10. @Override protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(50); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.01); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4); } If I do it that way, every time I try to spawn the mob it cancels the spawn and spams this error: "Caused by: java.lang.IllegalArgumentException: Attribute is already registered!". So I completely removed the method, so that it should all be default attributes, and it still changed nothing. The mob still doesn't target the player. Attributes are not the problem.
  11. I'm doing everything in that method that's in all super methods, so that shouldn't matter...
  12. I only see that in EntityZombie. It seems to be pretty useless and it's not in a super class, so why would I use it?
  13. My mob won't attack or even acknowledge the player. It should have everything else it needs from extending EntityMob, and I don't see any classes like EntityZombie, etc, doing anything special... Is setting its AI not enough? public class Hunter extends EntityMob { public Hunter(World world) { super(world); this.experienceValue = 30; this.setSize(0.5F, 1.8F); } @Override protected void applyEntityAttributes() { this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(50); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.01); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_SPEED); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.FOLLOW_RANGE); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.LUCK); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS); } @Override protected void initEntityAI() { this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true)); } protected boolean canEquipItem(ItemStack stack) { return stack.getItem() instanceof ItemSword || stack.getItem() instanceof MeleeWeapon; } @Nullable public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD)); return livingdata; } public float getEyeHeight() { return 1.75F; } protected boolean isValidLightLevel() { return true; } }
  14. I don't understand what's causing this. The crash log only references vanilla code, so I can't figure out what on earth is null. And it happens very randomly. Both times it happened was a second or two after killing my custom mob. However, I've tried killing my mob the same exact way (just whacking it with a diamond sword in a superflat world) about a dozen other times without causing a crash or error, and it hasn't happened with any vanilla entities. I don't know how to find the problem when it just happens at random. This is the crash: And this is the entity: public class Hunter extends EntityMob implements IBBMob { public Hunter(World worldIn) { super(worldIn); this.experienceValue = 30; this.setSize(0.6F, 1.95F); } @Override protected void applyEntityAttributes() { this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(4); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(50); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(0.01); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR); this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS); } protected void initEntityAI() { this.tasks.addTask(0, new EntityAISwimming(this)); this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D)); this.tasks.addTask(7, new EntityAIWanderAvoidWater(this, 1.0D)); this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false)); this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[] { Hunter.class })); this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true)); } protected boolean canEquipItem(ItemStack stack) { return stack.getItem() instanceof ItemSword || stack.getItem() instanceof MeleeWeapon; } @Nullable public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata) { setEquipment(); return livingdata; } protected void setEquipment() { int i = this.rand.nextInt(5); switch (i) { case 0: this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD)); break; case 1: this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Registry.hunterAxe)); break; case 2: this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Registry.threadedCane)); break; case 3: this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Registry.sawCleaver)); break; case 4: this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(Registry.kirkHammer)); break; } } public float getEyeHeight() { return 1.74F; } protected boolean isValidLightLevel() { return true; } @Override public int getEchoes() { return 100; } @Override public ItemStack getCommonDrop() { int i = rand.nextInt(100); int amount = i % 3 == 0 ? 1 : i % 6 == 0 ? 2 : 0; return new ItemStack(Registry.bloodVial, rand.nextInt(2)); } @Override public ItemStack getRareDrop() { int i = rand.nextInt(100); Item item = i % 4 == 0 ? Registry.bloodStoneShard : i % 6 == 0 ? Registry.twinBloodStoneShards : i % 10 == 0 ? Registry.madmansKnowledge : Registry.coldbloodDew; return new ItemStack(item); } }
  15. Items all show up, but blocks don't. The block is definitely being registered, and so is its model (I know because I finally got it to stop giving block model errors by renaming the file), but it just won't appear in my creative tab. I'm probably just overlooking something stupid again, but I can't figure out what. Registry public static Block quickSilverOre; public static Block[] blocks = new Block[] { quickSilverOre = new BloodBlock("quickSilverOre", Material.ROCK).setTool("pickaxe", 2) }; public static void load() { for (Block block : blocks) { GameRegistry.register(block); } } public static void registerRenderers() { int i = Main.MODID.length() + 1; for (Block block : blocks) { Main.proxy.registerBlockRenderer(block, 0, block.getRegistryName().toString().substring(i)); } } Main @EventHandler public void preInit(FMLPreInitializationEvent event) { Registry.load(); proxy.init(); } ClientProxy @Override public void init() { Registry.registerRenderers(); } @Override public void registerBlockRenderer(Block item, int meta, String name) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(item), meta, new ModelResourceLocation(Main.MODID + ":" + name, "inventory")); } And JSONs (I don't know if these are even relevant to the problem, but it saves the trouble of asking) // BlockState { "variants": { "normal": { "model": "bloodborne:quicksilverore" } } } // Model { "parent": "block/cube_all", "textures": { "all": "bloodborne:blocks/quickilverore" } } // Item { "parent": "bloodborne:block/quicksilverore" }
  16. Okay, I didn't know that. So does that mean all jsons have to be lowercase?
  17. Apparently all registry names are lower-cased? It's causing any items with a capital letter in their name to have missing model/textures. I have three items at the moment. public static Item bloodVial, antidote, sedative; They are initialised here: public static Item[] items = new Item[] { bloodVial = new BloodVial("bloodVial", 0.4f, "Consumable").addInfo("Restores 40% HP."), antidote = new Restorative("antidote", MobEffects.POISON, "Consumable").addInfo("Cures poison."), sedative = new Restorative("sedative", MobEffects.WITHER, "Consumable").addInfo("Cures wither."), }; Antidote and Sedative are displaying normal in-game with their actual textures, because their names are already lower-case. Blood Vial, however, is somehow having its name changed from "bloodVial" to "bloodvial" according to the console when trying to load its model. This is how I'm registering them: public static void load() { for (Item item : items) { System.out.println(item.getRegistryName()); // This always returns "bloodvial" instead of the defined "bloodVial". GameRegistry.register(item); } } How am I supposed to get the name that I actually gave it?
  18. Wonderful, all that trouble for just another dumb mistake. Thanks for pointing that out. Now the only trouble is that when I first log in, it's always at 0. It's not until I kill something to gain echoes that it updates. I assume that would be fixed just by sending a packet to the client when the player logs in? Would I need to do the same thing when the player enters a dimension?
  19. It's all way more complicated than it needs to be... I understand that everything important exists on the server, and it needs to send packets to update the client. Right? What I do not understand is how exactly that happens, and how exactly I'm supposed to use that for my specific needs. All tutorials/documentation that I've found are either outdated, missing important parts, or just plain vague. The server has been successfully counting my echoes and they're being saved to NBT, I just don't understand how exactly to send the information to the client. Are you saying addEchoes is supposed to be like this? @Override public void addEchoes(EntityPlayer player, int amount) { this.echoes = echoes + amount > maxEchoes ? maxEchoes : echoes + amount; PacketHandler.net.sendTo(new UpdateEchoes(this), (EntityPlayerMP) player); } This is where I'm rendering it. @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) { if (event.getType() != ElementType.EXPERIENCE) { return; } IEchoesCapability echoes = mc.thePlayer.getCapability(EchoesManager.ECHOES, null); if (echoes != null) { drawString(mc.fontRendererObj, TextFormatting.RED + "Blood Echoes: " + TextFormatting.WHITE + echoes.getEchoes(), 5, 5, colour); } } I added lines to print the amount of echoes the player has inside of addEchoes() and the UpdateEchoes() contructor, and both of them fire with the correct amount of echoes gained in total. But none of the printouts in the onMessage() method are ever being called. public static class Message implements IMessageHandler<UpdateEchoes, IMessage> { @Override public IMessage onMessage(final UpdateEchoes message, MessageContext ctx) { // This is never called. Logger.getLogger(Main.MODID).log(Level.INFO, "onMessage starting"); Minecraft.getMinecraft().addScheduledTask(new Runnable() { public void run() { // This is never called. Logger.getLogger(Main.MODID).log(Level.INFO, "Processing packet"); IEchoesCapability cap = Minecraft.getMinecraft().thePlayer.getCapability(EchoesManager.ECHOES, null); cap.setEchoes(message.echoes); cap.setInsight(message.insight); // This is never called. Logger.getLogger(Main.MODID).log(Level.INFO, "Packet Processed... Echoes: " + cap.getEchoes() + ", Insight: " + cap.getInsight()); } }); return null; } }
  20. I don't understand. I tried changing it to what I think you mean, but it's still not working. EventHandler if (echoes > 0) { IEchoesCapability cap = ((EntityPlayer) event.getSource().getSourceOfDamage()) .getCapability(EchoesManager.ECHOES, null); cap.addEchoes(echoes); PacketHandler.net.sendTo(new UpdateEchoes(cap), (EntityPlayerMP) event.getSource().getSourceOfDamage()); } UpdateEchoes public UpdateEchoes(IEchoesCapability cap) { this.echoes = cap.getEchoes(); this.insight = cap.getInsight(); } public static class Message implements IMessageHandler<UpdateEchoes, IMessage> { @Override public IMessage onMessage(final UpdateEchoes message, MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(new Runnable() { public void run() { IEchoesCapability cap = Minecraft.getMinecraft().thePlayer.getCapability(EchoesManager.ECHOES, null); cap.setEchoes(message.echoes); cap.setInsight(message.insight); } }); return null; } }
  21. Okay I admit that was stupid. But changing it to PacketHandler.net.sendTo(new UpdateEchoes(echoes, 0) (EntityPlayerMP) event.getSource().getSourceOfDamage()); doesn't work either. And isn't the fact that I need to send it to the client because that it's already and only on the server? How would I do that otherwise?
  22. I'm trying to send a packet to update a variable that's being rendered on the player's screen. When a mob dies, a specific amount is supposed to be added to the variable. But it always renders as 0, so it's just not updating. There are no errors given in the console. EventHandler @SubscribeEvent public void die(LivingDeathEvent event) { int echoes = 0; if (event.getSource().getEntity() != null && event.getSource().getEntity() instanceof EntityPlayer) { EntityLivingBase entity = event.getEntityLiving(); if (entity instanceof EntitySlime) { System.out.println("Killed mob"); // This does print, so the event is definitely registered. echoes = 5; } if (echoes > 0) { PacketHandler.net.sendTo(new UpdateEchoes(), (EntityPlayerMP) event.getSource().getSourceOfDamage()); } } } PacketHandler public static final SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(Main.MODID); public static int id = 0; // This is called from the main mod class' FMLInitializationEvent public static void init() { net.registerMessage(UpdateEchoes.Message.class, UpdateEchoes.class, id++, Side.SERVER); } UpdateEchoes implements IMessage private int echoes, insight; public UpdateEchoes(){} public UpdateEchoes(int echoes, int insight) { this.echoes = echoes; this.insight = insight; } @Override public void toBytes(ByteBuf buf) { buf.writeInt(echoes); buf.writeInt(insight); } @Override public void fromBytes(ByteBuf buf) { echoes = buf.readInt(); insight = buf.readInt(); } public static class Message implements IMessageHandler<UpdateEchoes, IMessage> { @Override public IMessage onMessage(final UpdateEchoes message, MessageContext ctx) { final EntityPlayerMP player = ctx.getServerHandler().playerEntity; Minecraft.getMinecraft().addScheduledTask(new Runnable() { public void run() { process(player, message.echoes, message.insight); } }); return null; } public void process(EntityPlayerMP player, int echoes, int insight) { player.getCapability(EchoesManager.ECHOES, null) .setEchoes(player.getCapability(EchoesManager.ECHOES, null).getEchoes() + echoes); player.getCapability(EchoesManager.ECHOES, null) .setInsight(player.getCapability(EchoesManager.ECHOES, null).getInsight() + insight); } }
  23. Thank you so much, I totally overlooked that.
  24. They're both ints. IEchoesCapability echoes = mc.thePlayer.getCapability(EchoesManager.ECHOES, null); if (echoes == null) return; This always returns when trying to render. So the capability itself is null, not any of the variables inside it.
×
×
  • Create New...

Important Information

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