• 0

    posted a message on [Forge][1.6.4 - 1.8] Custom Inventories in Items and Players
    How to keep the inventory after death?
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] Custom Inventories in Items and Players
    Quote from coolAlias
    Not unless you write your own DataWatcher class or use ASM to modify the bytecode of the Minecraft class, no. Just learn about packets (1.7.2) or packets (1.6.4), it's not that hard and is a much better solution for what you want to do than DataWatcher.

    You can tell how to make your DataWatcher?
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] EventHandler and IExtendedEntityProperties
    Hello again! I found the spelling in the code!
    For example, consider saving variables through DataWatcher.
    If after we have died and we came GUI (GuiGameOver) close Minecraft! IMPORTANT! DO NOT press "RESPAWN"! If you re-enter the game, the variables will be reset.
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] Custom Inventories in Items and Players
    Is it possible to exceed this limit?
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] Custom Inventories in Items and Players
    Hi! I keep all the variables in DataWatcher. How do I store inventory too DataWatcher?? And also how to keep things new slots after death? Maximum in DataWatcher ID = 31 and the number of slots is much greater. = (
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] EventHandler and IExtendedEntityProperties
    Thank you! It really helped!
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] EventHandler and IExtendedEntityProperties
    Quote from coolAlias

    Move this line from saveNBTData to loadNBTData:
    this.player.getDataWatcher().updateObject(levelID, properties.getInteger("newLevel"));
    // and remove this line, as it's not needed anymore:
    this.level = properties.getInteger("newLevel");

    Also, since you are using DataWatcher to track your level, you don't need to send a packet or worry about syncing anything at this point.

    I changed the code as you said, but it did not help.
    @Override
    public void saveNBTData(NBTTagCompound compound) {
    NBTTagCompound properties = new NBTTagCompound();
    properties.setInteger("newLevel", this.player.getDataWatcher().getWatchableObjectInt(levelID));
    compound.setTag(EXT_PROP_NAME, properties);
    }
    
    @Override
    public void loadNBTData(NBTTagCompound compound) {
    NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
    this.player.getDataWatcher().updateObject(levelID, properties.getInteger("newLevel"));
    System.out.println("[NBT] Level from NBT: " + this.level);
    }
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] EventHandler and IExtendedEntityProperties
    Hello again! Here, look. I did everything as written in the tutorial, but I do now when killing creatures is not given "my new level" (although it should be given). What's wrong with this code wrong?
    package example;

    import net.minecraft.client.Minecraft;
    import net.minecraftforge.common.MinecraftForge;
    import cpw.mods.fml.common.FMLCommonHandler;
    import cpw.mods.fml.common.Mod;
    import cpw.mods.fml.common.Mod.EventHandler;
    import cpw.mods.fml.common.SidedProxy;
    import cpw.mods.fml.common.event.FMLInitializationEvent;
    import cpw.mods.fml.common.event.FMLPostInitializationEvent;
    import cpw.mods.fml.common.event.FMLPreInitializationEvent;
    import cpw.mods.fml.common.network.NetworkMod;

    @Mod(modid = "TestID", name = "Test", version = "Version Test 1.0")
    @NetworkMod(clientSideRequired = true, serverSideRequired = true, channels = { ExtendedPlayer.EXT_PROP_NAME }, packetHandler = TutorialPacketHandler.class)
    public class Main {
    private static Main instance;

    @SidedProxy(clientSide = "example.ClientProxy", serverSide = "example.CommonProxy")
    public static CommonProxy proxy;

    public Main() {
    instance = this;
    }

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
    }

    @EventHandler
    public void onInit(FMLInitializationEvent event) {
    MinecraftForge.EVENT_BUS.register(new TutEventHandler());
    }

    public static Main getInstance() {
    return instance;
    }
    }
    package example;

    public class ClientProxy extends CommonProxy {
    }
    package example;

    import java.util.HashMap;
    import java.util.Map;

    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.world.World;
    import cpw.mods.fml.common.network.IGuiHandler;

    public class CommonProxy implements IGuiHandler {
    /**
    * Used to store IExtendedEntityProperties data temporarily between player
    * death and respawn
    */
    private static final Map<String, NBTTagCompound> extendedEntityData = new HashMap<String, NBTTagCompound>();

    public void registerRenderers() {
    }

    @Override
    public Object getServerGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z) {
    return null;
    }

    @Override
    public Object getClientGuiElement(int guiId, EntityPlayer player, World world, int x, int y, int z) {
    return null;
    }

    /**
    * Adds an entity's custom data to the map for temporary storage
    *
    * @param compound
    * An NBT Tag Compound that stores the IExtendedEntityProperties
    * data only
    */
    public static void storeEntityData(String name, NBTTagCompound compound) {
    extendedEntityData.put(name, compound);
    }

    /**
    * Removes the compound from the map and returns the NBT tag stored for name
    * or null if none exists
    */
    public static NBTTagCompound getEntityData(String name) {
    return extendedEntityData.remove(name);
    }

    /**
    * Makes it look nicer in the methods save/loadProxyData
    */
    private static String getSaveKey(EntityPlayer player) {
    return player.username + ":" + ExtendedPlayer.EXT_PROP_NAME;
    }

    /**
    * Does everything I did in onLivingDeathEvent and it's static, so you now
    * only need to use the following in the above event:
    * ExtendedPlayer.saveProxyData((EntityPlayer) event.entity));
    */
    public static void saveProxyData(EntityPlayer player) {
    ExtendedPlayer playerData = ExtendedPlayer.get(player);
    NBTTagCompound savedData = new NBTTagCompound();
    playerData.saveNBTData(savedData);
    CommonProxy.storeEntityData(getSaveKey(player), savedData);
    }

    /**
    * This cleans up the onEntityJoinWorld event by replacing most of the code
    * with a single line: ExtendedPlayer.loadProxyData((EntityPlayer)
    * event.entity));
    */
    public static void loadProxyData(EntityPlayer player) {
    ExtendedPlayer playerData = ExtendedPlayer.get(player);
    NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player));

    if (savedData != null) {
    playerData.loadNBTData(savedData);
    }

    playerData.sync();
    }
    }
    package example;

    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;

    import net.minecraft.entity.Entity;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.network.packet.Packet250CustomPayload;
    import net.minecraft.world.World;
    import net.minecraftforge.common.IExtendedEntityProperties;
    import cpw.mods.fml.common.network.PacketDispatcher;
    import cpw.mods.fml.common.network.Player;

    public class ExtendedPlayer implements IExtendedEntityProperties {
    public final static String EXT_PROP_NAME = "Level";
    private final EntityPlayer player;
    private int level;
    public static final int levelID = 20;

    public ExtendedPlayer(EntityPlayer player) {
    this.player = player;
    this.player.getDataWatcher().addObject(levelID, this.level);
    }

    /**
    * Used to register these extended properties for the player during
    * EntityConstructing event This method is for convenience only; it will
    * make your code look nicer
    */
    public static final void register(EntityPlayer player) {
    player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player));
    }

    /**
    * Returns ExtendedPlayer properties for player This method is for
    * convenience only; it will make your code look nicer
    */
    public static final ExtendedPlayer get(EntityPlayer player) {
    return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);
    }

    @Override
    public void saveNBTData(NBTTagCompound compound) {
    NBTTagCompound properties = new NBTTagCompound();
    properties.setInteger("newLevel", this.player.getDataWatcher().getWatchableObjectInt(levelID));
    this.player.getDataWatcher().updateObject(levelID, properties.getInteger("newLevel"));
    compound.setTag(EXT_PROP_NAME, properties);
    }

    @Override
    public void loadNBTData(NBTTagCompound compound) {
    NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
    this.level = properties.getInteger("newLevel");
    System.out.println("[NBT] Level from NBT: " + this.level);
    }

    @Override
    public void init(Entity entity, World world) {
    }

    /**
    * Sends a packet to the client containing information stored on the server
    * for ExtendedPlayer
    */
    public final void sync() {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(4);
    DataOutputStream outputStream = new DataOutputStream(bos);

    try {
    outputStream.writeInt(this.level);
    } catch (Exception ex) {
    ex.printStackTrace();
    }

    Packet250CustomPayload packet = new Packet250CustomPayload(EXT_PROP_NAME, bos.toByteArray());

    if (!player.worldObj.isRemote) {
    EntityPlayerMP player1 = (EntityPlayerMP) player;
    PacketDispatcher.sendPacketToPlayer(packet, (Player) player1);
    }
    }

    public void setLevel(int par1) {
    this.level = par1;
    this.sync();
    }

    public final int getLevel() {
    return this.player.getDataWatcher().getWatchableObjectInt(levelID);
    }

    public static void saveProxyData(EntityPlayer entity) {
    Main.proxy.saveProxyData(entity);
    }
    }
    package example;

    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.EntityPlayerMP;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraftforge.event.ForgeSubscribe;
    import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
    import net.minecraftforge.event.entity.EntityJoinWorldEvent;
    import net.minecraftforge.event.entity.living.LivingDeathEvent;

    public class TutEventHandler {
    @ForgeSubscribe
    public void onEntityConstructing(EntityConstructing event) {
    if (event.entity instanceof EntityPlayer) {
    ExtendedPlayer exp = ExtendedPlayer.get((EntityPlayer) event.entity);

    if (exp == null) {
    ExtendedPlayer.register((EntityPlayer) event.entity);
    }
    }
    }

    @ForgeSubscribe
    public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayerMP) {
    ExtendedPlayer exp = ExtendedPlayer.get((EntityPlayer) event.entity);

    NBTTagCompound playerData = Main.proxy.getEntityData(((EntityPlayer) event.entity).username);

    if (playerData != null) {
    exp.loadNBTData(playerData);
    }

    exp.sync();
    }
    }

    @ForgeSubscribe
    public void onLivingDeathEvent(LivingDeathEvent event) {
    if (!event.entity.worldObj.isRemote) {
    if (event.entity instanceof EntityPlayerMP) {
    ExtendedPlayer exp = ExtendedPlayer.get((EntityPlayer) event.entity);
    NBTTagCompound playerData = new NBTTagCompound();
    exp.saveNBTData(playerData);
    Main.proxy.storeEntityData(((EntityPlayer) event.entity).username, playerData);
    ExtendedPlayer.saveProxyData((EntityPlayer) event.entity);
    }

    if (event.source.getEntity() instanceof EntityPlayerMP) {
    ExtendedPlayer exp = ExtendedPlayer.get((EntityPlayer) event.source.getEntity());
    exp.setLevel(exp.getLevel() + 1);
    exp.sync();
    }

    }
    }
    }
    package example;

    import java.io.ByteArrayInputStream;
    import java.io.DataInputStream;
    import java.io.IOException;

    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.network.INetworkManager;
    import net.minecraft.network.packet.Packet250CustomPayload;
    import cpw.mods.fml.common.network.IPacketHandler;
    import cpw.mods.fml.common.network.Player;

    public class TutorialPacketHandler implements IPacketHandler {
    public TutorialPacketHandler() {
    }

    @Override
    public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
    if (packet.channel.equals(ExtendedPlayer.EXT_PROP_NAME)) {
    handleExtendedProperties(packet, player);
    }
    }

    private void handleExtendedProperties(Packet250CustomPayload packet, Player player) {
    DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
    ExtendedPlayer props = ExtendedPlayer.get((EntityPlayer) player);

    try {
    props.setLevel(inputStream.readInt());
    } catch (IOException e) {
    e.printStackTrace();
    return;
    }

    System.out.println("[PACKET] Level from packet: " + props.getLevel());
    }
    }
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] EventHandler and IExtendedEntityProperties
    Prompt in what file to write the code from lesson?
    // save player data:
    proxy.storeEntityData(((EntityPlayer) event.entity).username + ExtendedPlayer.EXT_PROP_NAME, playerData);
    // save living data:
    proxy.storeEntityData(((EntityPlayer) event.entity).username + ExtendedLiving.EXT_PROP_NAME, playerData);
    // load player data:
    NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).username + ExtendedPlayer.EXT_PROP_NAME);
    // load living data
    NBTTagCompound playerData = proxy.getEntityData(((EntityPlayer) event.entity).username + ExtendedLiving.EXT_PROP_NAME);
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] EventHandler and IExtendedEntityProperties
    Hi! I did everything according to the tutorial and I everything works fine! But when I die, all variables are reset. Could you tell me how to make variables persist after death?
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] Custom Inventories in Items and Players
    I read your tutorial again and found a bug! Now all works for me! Thanks!


    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Forge][1.6.4 - 1.8] Custom Inventories in Items and Players
    I did everything as written in the tutorial, but I will not open inventory when I press O.
    Posted in: Mapping and Modding Tutorials
  • 0

    posted a message on [Help] "scalac is not found on the PATH
    It can not be that I'm the one person on earth who has this problem. I pointed out all the way to the PATH and installed JDK 7u25. What's the problem again? What is the general "scalac"???
    Posted in: Modification Development
  • 0

    posted a message on [Help] "scalac is not found on the PATH
    Quote from Nexusrightsi

    Spamming help me won't do any good, I'm afraid. just go to your java JDK installation directory(it should returns with a version number). then you copy that dir url. then right click computer, and select properties. go to advanced system settings, on the tab advanced there should be an option for environmental variables. Click on it, then at system variables press new. use JAVA_HOME as the name and the installation directory url as the value of the variable. click ok, now look up Path in the system variables select and click edit. Go all the way to the end of the variable value and add a ; then once again paste in the java jdk installation directory url but don't forget to add \bin after it. keep clicking ok until you have no screens left. There you go, you just set your path.

    I added as you said,


    And I added the path:



    But the error is all the same remains. As it is now possible to remove? (I have Windows 7 x64)
    Posted in: Modification Development
  • To post a comment, please .