• 0

    posted a message on Game crash on armor tick
    Basically, I am trying to make a scuba mask and tank that will give the player water breathing when both are equipped. However, it seems whenever I use player.inventory.armorItemInSlot(1).getItem() to get the item the player is wearing, it crashes upon putting on the armor. Help?

    Scuba tank class:

    package com.webs.geckistudios.armormod;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemArmor;
    import net.minecraft.item.ItemStack;
    import net.minecraft.potion.Potion;
    import net.minecraft.potion.PotionEffect;
    import net.minecraft.world.World;
    public class ItemScubaTank extends ItemArmor {
    public ItemScubaTank(ArmorMaterial material, int renderIndex,
    int armorType) {
    super(material, renderIndex, armorType);
    }
    @Override
    public void onArmorTick (World world, EntityPlayer player, ItemStack itemStack)
    {
    System.out.println(player.inventory.armorItemInSlot(3).getItem());
    if (player.inventory.armorItemInSlot(3).getItem() == ArmorMod.ItemScubaMask)
    {
    player.addPotionEffect(new PotionEffect(Potion.waterBreathing.id, 1, 0));
    }
    }
    }
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    Oh. I got it to work without that though, but thanks to everyone who helped me!
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    I have gotten access to EntityPlayer through the packet, but can't use it because ctx.getServerHandler.playerEntity.inventory.armorItemInSlot(1) returns type ItemStack, so when I try use it in an if statement with my Item, it doesn't work. How could I go about casting it to Item, or something similiar that would work?
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    I know how to code (though not expertly). I managed to make it send the packet (confirmed with an output line), but how do I put in the handler class to lower the durability/increased velocity? I can't very well use onArmorTick...
    And for ohnousagain, I thought of using a seperate system, but thats more complicated, and my programming knowledge isn't quite that vast.
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    I've added that: nothing. I think I'm not actually telling the packet to do anything: I'm not sure.



    PacketMessage.java


    package com.webs.geckistudios.muffinmod;

    import io.netty.buffer.ByteBuf;
    import cpw.mods.fml.common.network.ByteBufUtils;
    import cpw.mods.fml.common.network.simpleimpl.IMessage;
    import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
    import cpw.mods.fml.common.network.simpleimpl.MessageContext;

    public class PacketMessage implements IMessage{

    private String text;

    public PacketMessage() { }

    public PacketMessage(String text) {
    this.text = text;
    }
    @Override
    public void fromBytes(ByteBuf buf) {
    text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects
    }
    @Override
    public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeUTF8String(buf, text);
    }
    public static class Handler implements IMessageHandler<PacketMessage, IMessage>{
    @Override
    public IMessage onMessage(PacketMessage message, MessageContext ctx) {
    System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName()));
    return null; // no response in this case
    }
    }
    }



    ItemMuffinJetpack.java


    package com.webs.geckistudios.muffinmod;

    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemArmor;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.ItemArmor.ArmorMaterial;
    import net.minecraft.world.World;

    public class ItemMuffinJetpack extends ItemArmor {

    public ItemMuffinJetpack(ArmorMaterial armourMaterial, int renderIndex,
    int armourType) {
    super(armourMaterial, renderIndex, armourType);
    this.maxStackSize = 1;
    }
    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){

    return "mm:textures/models/armor/jetpackArmor.png";
    }
    @Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
    player.fallDistance = 0;
    if (world.isRemote && Minecraft.getMinecraft().gameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindJump)) {
    {
    if (itemStack.getItemDamage() < 239) {
    player.addVelocity(0, 0.13, 0);
    itemStack.damageItem(1, player);
    for (int i = 0; i < 8; ++i)
    {
    MuffinMod.proxy.spawnParticle(player.worldObj, player.posX, player.posY - 1, player.posZ, "muffinpoof");
    }
    //MuffinMod.Network.sendToServer(message);
    }
    }
    }

    }
    }



    ClientProxy.java


    package com.webs.geckistudios.muffinmod;

    import cpw.mods.fml.common.eventhandler.SubscribeEvent;
    import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.particle.EntityBreakingFX;
    import net.minecraft.client.particle.EntityFX;
    import net.minecraft.init.Items;
    import net.minecraft.world.World;

    public class ClientProxy extends CommonProxy
    {
    @SubscribeEvent
    public void onKeyPress(KeyInputEvent event) {
    if (Minecraft.getMinecraft().gameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindJump)) {
    MuffinMod.Network.sendToServer(new PacketMessage());
    }
    }
    @Override
    public void spawnParticle(World world, double posX, double posY, double posZ, String type)
    {
    Minecraft minecraft = Minecraft.getMinecraft();

    if (minecraft != null && minecraft.renderViewEntity != null && minecraft.effectRenderer != null)
    {
    int particleSetting = minecraft.gameSettings.particleSetting;

    if (particleSetting == 1 && world.rand.nextInt(3) == 0)
    {
    particleSetting = 2;
    }

    double entityX = minecraft.renderViewEntity.posX - posX;
    double entityY = minecraft.renderViewEntity.posY - posY;
    double entityZ = minecraft.renderViewEntity.posZ - posZ;

    if (entityX * entityX + entityY * entityY + entityZ * entityZ > 16.0D * 16.0D)
    {
    return;
    }
    else if (particleSetting > 1)
    {
    return;
    }
    else
    {
    EntityFX particle = null;

    if (type.equals("muffinpoof"))
    {
    particle = new EntityBreakingFX(world, posX, posY, posZ, MuffinMod.itemMuffinChocolateChip);
    }
    else if (type.equals("rainbowmuffinpoof"))
    {
    particle = new EntityBreakingFX(world, posX, posY, posZ, MuffinMod.itemMuffinRainbow);
    }

    if (particle != null)
    {
    minecraft.effectRenderer.addEffect(particle);
    }
    }
    }
    }
    }

    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    Which class do I put the code in? I'm confused.
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    Fixed that. Now PacketHandler in public class line says must inherit abstract method fromBytes, and fromBytes and toBytes still want to remove the @Override
    Wait: never mind. Forgot to put the fromBytes and toBytes in the class function.

    EDIT: Now how do I add it in my jetpack class to send the packet?
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    Simply put, my package handler class is full if errors. The Handler class claims to have illegal modifiers (public and static), and the fromBytes and toBytes want to have the @Override annotation removed.




    package com.webs.geckistudios.muffinmod;

    import io.netty.buffer.ByteBuf;
    import cpw.mods.fml.common.network.ByteBufUtils;
    import cpw.mods.fml.common.network.simpleimpl.IMessage;
    import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
    import cpw.mods.fml.common.network.simpleimpl.MessageContext;

    public class PacketMessage implements IMessage{

    private String text;

    public PacketMessage() { }

    public PacketMessage(String text) {
    this.text = text;

    public static class Handler implements IMessageHandler<PacketMessage, IMessage>{
    @Override
    public IMessage onMessage(PacketMessage message, MessageContext ctx) {
    System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName()));
    return null; // no response in this case
    }

    @Override
    public void fromBytes(ByteBuf buf) {
    // TODO Auto-generated method stub
    text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects

    }

    @Override
    public void toBytes(ByteBuf buf) {
    // TODO Auto-generated method stub
    ByteBufUtils.writeUTF8String(buf, text);
    }

    }
    }
    }

    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    The code that would work in my situation. I understand the concepts behind it, but can't seem to make it work correctly.
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    Whew! Looks complicated. My programming knowledge is quite limited (I'm working on it), but an example would be greatly appreciated!
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    Oh. That makes sense. I never really could figure out how to send packets: could you tell me how please? Thanks!
    Posted in: Modification Development
  • 0

    posted a message on Armor durability resetting upon taking off armor
    I'm making a jetpack, and am using the durability as the fuel amount. The fuel system works fine, just when I use up fuel (lower durability), and then take the armor off, the durability returns to the value it was before I put it on. I really need to fix this; any help will be appreciated!



    Jetpack File:


    package com.webs.geckistudios.muffinmod;

    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemArmor;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.ItemArmor.ArmorMaterial;
    import net.minecraft.world.World;

    public class ItemMuffinJetpack extends ItemArmor {

    public ItemMuffinJetpack(ArmorMaterial armourMaterial, int renderIndex,
    int armourType) {
    super(armourMaterial, renderIndex, armourType);
    this.maxStackSize = 1;
    }
    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type){

    return "mm:textures/models/armor/jetpackArmor.png";
    }
    @Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
    player.fallDistance = 0;
    if (world.isRemote && Minecraft.getMinecraft().gameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindJump)) {
    {
    if (itemStack.getItemDamage() < 239) {
    player.addVelocity(0, 0.13, 0);
    itemStack.damageItem(1, player);
    for (int i = 0; i < 8; ++i)
    {
    MuffinMod.proxy.spawnParticle(player.worldObj, player.posX, player.posY - 1, player.posZ, "muffinpoof");
    }
    }
    }
    }

    }
    }

    Posted in: Modification Development
  • 0

    posted a message on Testing for custom item is held or not
    It works! However, when I try to switch items (or when the if statement returns false), the game crashes, saying there was an error ticking entity.

    Crash Report:

    Posted in: Modification Development
  • 0

    posted a message on Testing for custom item is held or not
    I see. However, now entity.getCurrentEquippedItem and entity.addPotionEffect fail to work, asking for a cast to something. Help?
    Posted in: Modification Development
  • 0

    posted a message on Testing for custom item is held or not
    Doesn't work. No crash reports or anything. Just won't gimme a potion effect. Its for 1.7.10.
    Posted in: Modification Development
  • To post a comment, please or register a new account.