Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ArmamentHaki

Members
  • Joined

  • Last visited

Everything posted by ArmamentHaki

  1. I added a repo, although it is untidy. It contains all the files in the src folder so that should be enough. https://github.com/Oeku/RPG-Mod
  2. In that case, why does this keep on happening ingame? Everytime i send the packet, it works and my values are set correctly but still, my log gives me an exception
  3. How can the player be null if I am performing a check before sending the packets? Look at sendUpdatePackets() in the Health Skill class
  4. Changing the health system is not really complicated as most times the LivingHurtEvent is called. You could simply make a Capability that stores your entities health and substract the given amount. Then you set the amount to something near 0 so that the actual health doesnt matter. But I think this is to complicated for this simple thing. Or as Major Tuvok said subscribe to LivingHurtEvent, test if your conditions are given and then multiply the amount by something smaller than 1.
  5. This is my Packet Class package net.zeldadungeons.network.message; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; import net.minecraftforge.fml.relauncher.Side; import net.zeldadungeons.client.gui.overlay.GuiOverlay; public class PacketHealthValues implements IMessage { public static HandlerPacketHealthValues handler = new HandlerPacketHealthValues(); private double maxHealth; private double currentHealth; private double share; private int level; public PacketHealthValues(double currentHealth, double maxHealth, int level, double share) { this.currentHealth = currentHealth; this.maxHealth = maxHealth; this.share = share; this.level = level; } public PacketHealthValues() { } @Override public void fromBytes(ByteBuf buf) { this.currentHealth = buf.readDouble(); this.maxHealth = buf.readDouble(); this.share = buf.readDouble(); this.level = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeDouble(currentHealth); buf.writeDouble(maxHealth); buf.writeDouble(share); buf.writeInt(level); } static class HandlerPacketHealthValues implements IMessageHandler<PacketHealthValues, IMessage> { @Override public IMessage onMessage(PacketHealthValues message, MessageContext ctx) { if (ctx.side == Side.CLIENT) { GuiOverlay.renderCurrentHealth = message.currentHealth; GuiOverlay.renderMaxHealth = message.maxHealth; /*Minecraft.getMinecraft().addScheduledTask(new Runnable() { public void run() { processMessage(message); } });*/ } return null; } void processMessage(PacketHealthValues message) { GuiOverlay.renderCurrentHealth = message.currentHealth; GuiOverlay.renderMaxHealth = message.maxHealth; } } } And this is my NetworkHandler: package net.zeldadungeons.network; import net.zeldadungeons.ZeldaDungeons; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; import net.zeldadungeons.network.message.PacketDemo; import net.zeldadungeons.network.message.PacketHealthValues; import net.zeldadungeons.network.message.PacketPressureSwitch; import net.zeldadungeons.network.message.PacketStaminaValues; public class NetworkHandler { private static SimpleNetworkWrapper INSTANCE; public static void init() { setInstance(NetworkRegistry.INSTANCE.newSimpleChannel(ZeldaDungeons.MODID)); getInstance().registerMessage(PacketDemo.handler, PacketDemo.class, 0, Side.SERVER); getInstance().registerMessage(PacketPressureSwitch.handler, PacketPressureSwitch.class, 0, Side.SERVER); getInstance().registerMessage(PacketHealthValues.handler, PacketHealthValues.class, 0, Side.CLIENT); getInstance().registerMessage(PacketStaminaValues.handler, PacketStaminaValues.class, 0, Side.CLIENT); } public static SimpleNetworkWrapper getInstance() { return INSTANCE; } public static void setInstance(SimpleNetworkWrapper iNSTANCE) { INSTANCE = iNSTANCE; } } I know the NetworkHandler isn't efficient and I will Change it soon, but first I Need to solve this Problem. I am writing Capability Data: package net.zeldadungeons.skill; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.zeldadungeons.capability.playerlevels.CapabilityPlayerLevels; import net.zeldadungeons.event.EventManager; import net.zeldadungeons.network.NetworkHandler; import net.zeldadungeons.network.message.PacketHealthValues; public class SkillHealth extends Skill { private int maxHealth; private int currentHealth; /** * @param level the starting level of this skill * @param totalExp the total exp of this skill */ public SkillHealth(int level, int totalExp) { this.maxLevel = 1000; this.setLevel(level); this.totalExp = totalExp; this.expToNext = this.calculateExp(level + 1); this.calculateMaxHealth(level); this.currentHealth = this.maxHealth; } /** * sets the level, called from levelup() to increase the level. also updates * the maxhealth that goes along with the new level. */ @Override public void setLevel(int level) { super.setLevel(level); this.sendUpdatePackets(player); calculateMaxHealth(level); } /** * Calculates the maximum health for the given level. * * @param level */ public void calculateMaxHealth(int level) { int j = 10 * level; for (int i = level; i > 0; i--) { j += i * 1; } this.setMaxHealth(j); } /** * Called to damage the player. * * @param i */ public void setCurrentHealth(int i) { i = EventManager.onSetCurrentSkill(this, i, this.player); this.currentHealth = i; if (i <= 0) { if (player != null) player.setHealth(0F); this.currentHealth = 0; } this.sendUpdatePackets(player); } /** * Set the maxHealth. * * @param i */ public void setMaxHealth(int i) { this.maxHealth = i; this.sendUpdatePackets(player); } public int getMaxHealth() { return this.maxHealth; } public int getCurrentHealth() { return this.currentHealth; } public void setPlayer(EntityPlayer player) { this.player = player; this.sendUpdatePackets(player); } @Override public void sendUpdatePackets(EntityPlayer player) { if (player != null && !player.world.isRemote && player instanceof EntityPlayerMP) NetworkHandler.getInstance().sendTo(new PacketHealthValues(this.currentHealth, this.maxHealth, this.level, (double) currentHealth / (double) maxHealth), (EntityPlayerMP) player); } public void damagePlayer(boolean withArmor, int amount){ SkillCombat combatSkill = this.player.getCapability(CapabilityPlayerLevels.PLAYER_LEVELS_CAPABILITY, CapabilityPlayerLevels.DEFAULT_FACING).getCombatSkill(); } public boolean fullHealth() { if(this.getCurrentHealth() == this.getMaxHealth())return true; else return false; } public boolean willDamageKill(int i){ if(i >= this.currentHealth)return true; else return false; } } An instance of each skill is stored in my main Capability class. Also, this is how I write the nbt(although nbt doesn't seem to be the Problem as I also get an exception whilst ingame): package net.zeldadungeons.capability.playerlevels; import net.zeldadungeons.ZeldaDungeons; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.CapabilityManager; import net.zeldadungeons.skill.SkillCombat; import net.zeldadungeons.skill.SkillHealth; import net.zeldadungeons.skill.SkillStamina; public class CapabilityPlayerLevels { @CapabilityInject(IPlayerLevels.class) public static final Capability<IPlayerLevels> PLAYER_LEVELS_CAPABILITY = null; public static final EnumFacing DEFAULT_FACING = null; public static final ResourceLocation ID = new ResourceLocation(ZeldaDungeons.MODID, "player_levels"); public static void register() { CapabilityManager.INSTANCE.register(IPlayerLevels.class, new Capability.IStorage<IPlayerLevels>() { @Override public NBTBase writeNBT(Capability<IPlayerLevels> capability, IPlayerLevels instance, EnumFacing side) { SkillHealth hS = instance.getHealthSkill(); SkillStamina sS = instance.getStaminaSkill(); SkillCombat cS = instance.getCombatSkill(); int[] health = { hS.getLevel(), hS.getTotalExp(), hS.getCurrentHealth(), hS.getMaxHealth() }; int[] stamina = { sS.getLevel(), sS.getTotalExp(), sS.getCurrentStamina(), sS.getMaxStamina() }; int[] combat = { cS.getLevel(), cS.getTotalExp(), cS.getDamage() }; NBTTagCompound compound = new NBTTagCompound(); compound.setIntArray("health", health); compound.setIntArray("stamina", stamina); compound.setIntArray("combat", combat); return compound; } @Override public void readNBT(Capability<IPlayerLevels> capability, IPlayerLevels instance, EnumFacing side, NBTBase nbt) { NBTTagCompound compound = ((NBTTagCompound) nbt); int[] health = compound.getIntArray("health"); int[] stamina = compound.getIntArray("stamina"); int[] combat = compound.getIntArray("combat"); SkillHealth hS = new SkillHealth(health[0], health[1]); hS.setMaxHealth(health[3]); hS.setCurrentHealth(health[2]); instance.setHealthSkill(hS); SkillStamina sS = new SkillStamina(stamina[0], stamina[1]); sS.setMaxStamina(stamina[3]); sS.setCurrentStamina(stamina[2]); instance.setStaminaSkill(sS); SkillCombat cS = new SkillCombat(combat[0], combat[1]); cS.setDamage(combat[2]); } }, () -> new PlayerLevels(null)); } }
  6. Hello, I have been without Problems for quite a while, but now again, I Need to ask something. I was using packets in order to update Rendering. However, everytime the NetworkHandler is used, I get an exception. Although it doesn't Crash the game and the Messages are working, it is nasty to have and could cause bugs. Here is my Crash Report:
  7. Every Item is "wrapped by an ItemStack", isnt it? That means that values cannot be changed while ingame. For example, if I wanted to change the maximum durability of a Tool while ingame, it wouldn't work because every Item is defined and cannot be changed individually... In my case, I want to set the Attack Damage of a Weapon, depending on a capability value of the player who created it... But Minecraft would simply do something like this on creating an Item, wouldn't it? new ItemStack(ModItems.EXAMPLE) EXAMPLE would then be an instance of an Item, but this would have the same value for every ItemStack that is created. So this wont Work for me.
  8. It doesn't work yet. Do I have to pay attention to something while exporting an obj file? Like, how big is it or how to properly unwrap the model? I would post a screenshot but it is simply invisible in my inventory... That means that forge somehow loads it but not the right way, doesn't it?
  9. Why dont you define your Maxhealth in the constructor? Please post some code to help us understand
  10. I did a tutorial on this some time ago and although its a bad one, you may find some ideas there on how you will do it. Mine was pretty much hard coded though
  11. You would have to test if the mouseX and Y position are outside your GUI in mouseClicked(). However, your Gui will rescale when different settigs are used by other players, so that you would have to figure out a general way to calculate the borders of your Gui.
  12. bump, i cant get it to work yet
  13. Instead of that, I could also just disable player rendering and replace it with another model.
  14. Huh, still invisible both on ground and in inventory. { "forge_marker": 1, "variants": { "inventory": [{ "model": "zeldadungeons:small_key.obj" }] } }
  15. I was making an item and not a block. Aren't items supported? They should be.
  16. I already called it, in the Log I posted it says "added zeldadungeons as a domain". Maybe it is a problem with the model itself?
  17. It crashes when I do so: This is what I changed: package net.zeldadungeons.init; import net.zeldadungeons.ZeldaDungeons; import net.zeldadungeons.init.blocks.BlockPressureSwitch; import net.zeldadungeons.util.MeshDefinitionFix; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.obj.OBJLoader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; @Mod.EventBusSubscriber(value = Side.CLIENT, modid = ZeldaDungeons.MODID) public class Modelizer { public static final Modelizer INSTANCE = new Modelizer(); @SubscribeEvent public static void registerAll(final ModelRegistryEvent e) { INSTANCE.registerItemModels(); INSTANCE.registerBlockModels(); } private void registerItemModels() { registerItemModel(Itemizer.FAIRY_SLINGSHOT); registerItemObjModel(Itemizer.SMALL_KEY); } private void registerBlockModels() { registerBlockItemModel(Blockizer.PRESSURE_SWITCH.getDefaultState()); } private void registerItemModel(Item item) { final ModelResourceLocation resource = new ModelResourceLocation(item.getRegistryName(), "inventory"); ModelLoader.setCustomModelResourceLocation(item, 0, resource); } private void registerBlockItemModel(final IBlockState state) { final Block block = state.getBlock(); final Item item = Item.getItemFromBlock(block); if (item != Items.AIR) { registerItemModel(item); } } private void registerItemObjModel(Item item) { final ModelResourceLocation resource = new ModelResourceLocation(item.getRegistryName(), "inventory"); OBJLoader.INSTANCE.loadModel(resource); } }
  18. I looked at how Minecraft renders the player and realized that cancelling the event would cancel way more that shouldn't be cancelled. I can modify rotation angles of the models, but they are resetted in the render method itself, so that won't work for me. The only option would be to render everything that Minecraft does by my Mod and set them manually there. But that would be a ton of stuff that I actually want to keep my hands off
  19. My Entity still keeps moving a tiny bit weird when I throw it. I am not sure if ist normal or due to its small Rendering size, but sometimes when I throw it, it moves up or down by a small distance. public void onUpdate() { super.onUpdate(); BlockPos blockpos = new BlockPos(this.posX, this.posY, this.posZ); IBlockState iblockstate = this.world.getBlockState(blockpos); Block block = iblockstate.getBlock(); if (iblockstate.getMaterial() != Material.AIR) { AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos); if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).contains(new Vec3d(this.posX, this.posY, this.posZ))) { this.inGround = true; motionX = 0; motionY = 0; motionZ = 0; int j = block.getMetaFromState(iblockstate); if (!this.world.collidesWithAnyBlock(this.getEntityBoundingBox().grow(0.05D))) { this.inGround = false; this.ticksInGround = 0; this.ticksInAir = 0; } else { ++this.ticksInGround; this.doBlockCollisions(); } } } double j = 0; if (!this.inGround) { ticksInAir++; } this.posX += this.motionX; this.posY += this.motionY; this.posZ += this.motionZ; float f1 = 0.99F; this.motionX *= (double) f1; this.motionY *= (double) f1; this.motionZ *= (double) f1; this.motionY -= 0.05000000074505806D; this.updatePos(posX, posY, posZ); this.removeEntity(); } public void updatePos(double d1, double d2, double d3) { this.setPosition(d1, d2, d3); } public void removeEntity() { if (this.ticksInGround >= 10) { this.setDead(); this.world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX, this.posY + 0.5D, this.posZ, 1.0D, 0.0D, 1.0D, 10); } }
  20. No, I haven't. In fact, I do not even know where I should call it? Do I Need to do it in the class that Registers my models? package net.zeldadungeons.init; import net.zeldadungeons.ZeldaDungeons; import net.zeldadungeons.init.blocks.BlockPressureSwitch; import net.zeldadungeons.util.MeshDefinitionFix; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.obj.OBJLoader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; @Mod.EventBusSubscriber(value = Side.CLIENT, modid = ZeldaDungeons.MODID) public class Modelizer { public static final Modelizer INSTANCE = new Modelizer(); @SubscribeEvent public static void registerAll(final ModelRegistryEvent e) { INSTANCE.registerItemModels(); INSTANCE.registerBlockModels(); } private void registerItemModels() { registerItemModel(Itemizer.FAIRY_SLINGSHOT); registerItemModel(Itemizer.SMALL_KEY); } private void registerBlockModels() { registerBlockItemModel(Blockizer.PRESSURE_SWITCH.getDefaultState()); } private void registerItemModel(Item item) { final ModelResourceLocation resource = new ModelResourceLocation(item.getRegistryName(), "inventory"); ModelLoader.setCustomModelResourceLocation(item, 0, resource); } private void registerBlockItemModel(final IBlockState state) { final Block block = state.getBlock(); final Item item = Item.getItemFromBlock(block); if (item != Items.AIR) { registerItemModel(item); } } } I already added the Domain of my Mod to the ObjLoader.
  21. Hey, I have encountered another Problem whilst trying to render an custom OBJ Model as Item. The console once again tells me no Errors, but my Item wont Show up in the Game. Blockstate File (this should be right, as I got missing Location Errors until I added this): { "forge_marker": 1, "defaults": { "textures":{}, "model": "zeldadungeons:small_key.obj" }, "display":{} } I wont include the obj model file as it is 6000 lines Long. This is the .mtl file, referencing my texture: # Blender MTL File: 'None' # Material Count: 1 newmtl Material.001 Ns 94.117647 Ka 1.000000 1.000000 1.000000 Kd 0.125947 0.125947 0.125947 Ks 0.022227 0.022227 0.022227 Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2 map_Kd zeldadungeons:items/small_key
  22. Yeah, I know that but can I just modify them? If so, how do I prevent Minecraft from controlling the player model?
  23. All right, I will just ask this straight ahead, are there common ways of creating different Modes for players which also can change the Model animation? I could use capabilities to add this, but how can I directly influence Minecrafts usual player animations? Also, I need certain abilities that the player has in this modes (e.g pulling an entity), but that will be rather easy.
  24. At least show us your latest log, it could be anything
  25. I was only tracking every 20 ticks. It does work now.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.