-
Posts
141 -
Joined
-
Last visited
Everything posted by Koward
-
Hi. Please correct my story if I say something weird. I have a block (let's call it "fancybrick"), with 2 variants (I'll use "blue" and "red" here), I want an item per variant. Easy, probably. I create the Block instance (only one, it's not like ores which are each a registered new instance of BlockOre). This Block has a registry name "fancybrick". I register this way : private static Block registerBlock(Block block) { GameRegistry.register(block); GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName())); return block; } This has for result two block&item pairs with registry name "fancybrick". I would rather like "fancybrick_blue" and "fancybrick_red". Unlike rendering and ModelLoader.setCustomModelResourceLocation() I don't have a way to give the meta as a parameter for registering. A solution I can see is dropping completely from meta (the stone-like solution) and going to separate instances (the ore-like solution), maybe it would look cleaner and produce a code easier to maintain. But I would like to understand a bit what I'm doing and not copy pasting any snippet out there. There must be a reason these two ways coexist.
-
Hi again, First of all, here's the code I'm updating right now : /** * Cancel the FOV decrease caused by the decreasing speed due to player penalties. * @param event */ @SubscribeEvent public void onFOVUpdate(FOVUpdateEvent event) { EntityPlayer player = event.getEntity(); PenaltyManager penalty = new PenaltyManager(player);//It's just a set of methods that give info about the player, not important float f = 1.0F; if (player.capabilities.isFlying) { f *= 1.1F; } IAttributeInstance iattributeinstance = player .getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); f = (float) ((double) f * (((iattributeinstance.getAttributeValue() / penalty .getHealthAndExhaustionModifier()) / (double) player.capabilities.getWalkSpeed() + 1.0D) / 2.0D)); if (player.capabilities.getWalkSpeed() == 0.0F || Float.isNaN(f) || Float.isInfinite(f)) { f = 1.0F; } if (player.isHandActive() && player.getActiveItemStack().getItem() == Items.BOW) { int i = player.getItemInUseDuration();// FIXME Does not exist anymore ? float f1 = (float) i / 20.0F; if (f1 > 1.0F) { f1 = 1.0F; } else { f1 *= f1; } f *= 1.0F - f1 * 0.15F; } event.setNewfov(f); } Since 1.9 I believe, all EntityLivingBase can use items, so I naturally searched through it to find replacements for my methods. I found some, but not for getItemInUseDuration(). I used it to know for how long the bow is being used. If anyone has a workaround or found a replacement, I would be very grateful.
-
Thank you. This is the most stupid and confusing thing I have ever seen in a while. It explains a lot of what I have seen elsewhere in the source.
-
Hi, I would like to set Hardness for my block depending on its current variant. Previously I used this code : @Override public float getBlockHardness(World world, BlockPos pos) { IBlockState bs = world.getBlockState(pos); // Vanilla Bug Fix @author JeffryFisher boolean alreadyBroken = (bs.getBlock() == Blocks.AIR); float default_h = super.blockHardness; if (alreadyBroken) return default_h; switch (this.getMetaFromState(bs)) { case 0: return 3.0F; case 1: return 4.5F; default: return default_h; } } @Override public float getPlayerRelativeBlockHardness(EntityPlayer playerIn, World worldIn, BlockPos pos) { float default_f = ForgeHooks.blockStrength(worldIn.getBlockState(pos), playerIn, worldIn, pos); ItemStack s = playerIn.getCurrentEquippedItem(); if (s != null) { boolean canHarvest = ForgeHooks .canToolHarvestBlock(worldIn, pos, s); if (!canHarvest) { return default_f / 3; } } return default_f; } Now it has somehow moved to the IBlockState level, but I don't know how I could set it. An idea ?
-
My "make furnace run twice as fast" was an example and in fact I would probably do the opposite to make some upgrades more meaningful if I feel that Mojang or some Mod Creators doesn't properly balance their content. But I get your point, I think I'll probably go for stand alones if I start any project in the future. Thank you for your answers.
-
I wasn't aware that it could be the origin of big conflicts, really, my bad. But anyway it makes me wonder if modding (or at least, modding with Forge) should be just about adding content ? Do you promote editing vanilla mechanics ? These days I see a couple of APIs (like AppleCore for food&hunger systems) editing fundamental mechanics of the original game, there is a fresh will to "fix" the unbalanced parts. Keeping compatibility between this kind of mods sounds of course a bit harder than keep Obsidian tools and Emerald tools together, but is it even possible, and are you even looking for it or do you consider the actual trend of creating small Coremods more fit to handle that ?
-
[Note] This post is partially copied from the thread I started in the Modder Support section here : Hi ! I wanted to mod the vanilla furnace a bit, but it seems, unlike its Crafting Table cousin, it doesn't got much attention. Basically, there is no hook that could allow us to do something when an item is placed in whatever furnace slot, or when it starts to smelt. An ItemSmelted event is triggered when smelting is over but no in between. Example of situations where they could be used : - I want to burn fuels in furnaces as soon as I put them. - I want to speed up the furnace by a 2x factor. Seems equals to dividing the burning "value" of fuels by 2 and divide the burning speed of to-be-cooked items by 2 too. To do that we need access to the items. Where an event should be triggered : - Item put in Slot In/Fuel/Out As Choonster stated, "the furnace uses TileEntityFurnace#func_174904_a to determine the cook time of the item being smelted, but this always returns 200. It doesn't look like Forge provides any hooks for changing this value".
-
Even when I manually light up the sound, it's not triggered. Try for yourself, with any tool. I see absolutely no link between damaging an item and preventing all sounds and particles to be displayed. I am looking for an event solution to allow using it on Vanilla or other mods tools.
-
This : @SubscribeEvent public void breakWoodenPickaxe(BreakEvent event) { if ((event.getPlayer().getHeldItem() != null) && (event.getPlayer().getHeldItem().getItem() == Items.wooden_pickaxe)) { event.getPlayer().getHeldItem() .damageItem(Integer.MAX_VALUE, event.getPlayer()); } } Seems to work well, I have yet to find the problems with this method. Well, I have a problem, the particle&sound are not displayed when I break the tool now, but I don't think it's related. I have to check. EDIT : It is related. The item disappear, but no sound and effect can be seen. WTF ?
-
I thought I had solved the problem but the OnCrafting event doesn't seem to be always called, resulting in unpredictable behavior and sometimes two uses pickaxes. Raaaah ! I'm thinking about an event when a block is broken but I wonder what is the best method to destroy a tool without those annoying effects mentioned by EverythingGames.
-
The saving now works perfectly, thank you. Back to the GUI displaying, my little method which should hide the original hunger bar and display mine just hide the original. Currently, my custom hunger bar is the vanilla one (I will tweak it once it works). http://hastebin.com/umiwedupic.java Maybe I should play with Pre and Post events ? I tried to cancel in Pre and display in Post but it was still the same problem.
-
Then I have two solutions : Read from the Minecraft compound tag; Read&Write on a Forge compound tag. But I don't know how to access any of these compound tags if this method doesn't work. EDIT : Fixed. I now write on the EntityPlayer.getEntityData() compound at logout with an event.
-
My actual problem is that during the EntityJoinWorld event, player.getEntityData() returns an empty NBTTagCompound. Does this make sense ? How can I read from it then ? The readNBT isn't called magically, and all the information on the web is about TileEntities.. Note I have to call readNBT somewhere myself, because at the time getFoodStats().readNBT(compound) is originally called in EntityPlayer, it still has the old class. I did a workaround by getting values from the vanilla class. But I can't keep it, as not all values have public getters..
-
That's already what I did. Initially I was using the vanilla "foodLevel" NBT tag so I thought it was the problem. Made a custom one, no changes. That's really strange. I will look if there is some kind of NBT viewer out there. EDIT : I found one and after a few experiments it seems the writing works well but the reading doesn't work. In my method public void readNBT(NBTTagCompound p_75112_1_) { System.out.println("Started reading NBT tags..."); if (p_75112_1_.hasKey("foodLevel")) { System.out.println("NBT Tag found !"); this.foodLevel = p_75112_1_.getInteger("foodLevel"); this.foodTimer = p_75112_1_.getInteger("foodTickTimer"); this.foodSaturationLevel = p_75112_1_.getFloat("foodSaturationLevel"); this.foodExhaustionLevel = p_75112_1_.getFloat("foodExhaustionLevel"); } } "Started reading..." is printed but not "NBT Tag found !" so .hasKey("foodLevel") never worked. I don't get it because NBTExplorer clearly show the value exist in the save.
-
So I will search when and how these methods are called and mimic the vanilla system. Thanks. EDIT : Called in the EntityPlayer class. I need a way to use NBTTagCompound, something like a getNBTfromEntity()... Very interesting.
-
But the instance can't be "renewed". Even in Vanilla. I mean, there is the foodLevel in there. When you renew it, it gets back to max (initial value). Let's assume a new foodStats instance is automatically created at each EntityJoinWorld, and it seems to be the case, how does vanilla save its food level value ?
-
How so? Well, HardFoodStats extends FoodStats. Therefore my logic is HardFoodStats instanceof FoodStats == true,, FoodStats instanceof FoodStats == true, HardFoodStats instanceof HardFoodStats == true but FoodStats instanceof HardFoodStats == false. So if the part of my code under !(getFoodStats instanceof HardFoodStats) is loaded each time (each logging, for the same player) that means each time I log in my player.getFoodStats is NOT the HardFoodStats instance I previously assigned.
-
It seems my condition if(!(player.getFoodStats() instanceof HardFoodStats)) is always true and so, at each relogging the foodStats is a new instance. That makes absolutely no sense. Here is my most recent code : http://hastebin.com/idasoyimiq.java
-
I still need some way to create a new instance for each player, but not each time it appears in the world like I would in my current code.
-
I improved my code to look only once through fields to find the right one. I'm not sure how player related variables can be made yet : (hashmap maybe ? Or an event is triggered at the "character creation" ?) but I will find out as it's probably something people always ask.
-
Okay, I wasn't aware of GuiIngameForge. I should have looked where the event was fired. I added an other question in my OP regarding the way I replace the food handling class (which I think I should take the multiplayer in account since there are individual food counters in there, but I'm not sure I do since I think the data get stored in only one place which sounds awefully wrong). PS : I know I'm unleashing incompatibility and bad things by starting to use reflection but I had no choice, Forge just doesn't allow to safely modify much about Food and other real game mechanics.
-
Hi ! I overhauled the standard FoodStats system and increased the maximum hunger beyond 20. Unfortunately, the GUI still only shows the last 20 points. So I have to remake the Hunger bar so it changes the way hunger level are displayed. But : 1. The original code looks very obfuscated, do you know any working example of something that sounds a bit like what I'm trying to do ? 2. I can disable the original with RenderGameOverlayEvent, but I don't see how to create the new GUI from here. There's no access to the player or the world. 3. I suspect my code to be functional for only one player. Here is the code replacing the FoodStats class : http://hastebin.com/awopohuzef.java Am I right ? Anybody ever played with those things ? EDIT : I will use a PlayerTickEvent to show the GUI, but that doesn't answer all my questions.
-
Hi ! I wanted to mod the vanilla furnace a bit, but it seems, unlike its Crafting Table cousin, it doesn't got much attention from the other newbies, therefore not appearing on many threads and even less on standard places of Forge documentation. Basically, there is no event that could allow me to do something when an item is placed in whatever furnace slot, or when it starts to smelt. An ItemSmelted event is triggered when everything is over but no in between. A concrete example would be : I want to speed up the furnace by a 2x factor. Seems equals to dividing the burning "value" of fuels by 2 and divide the burning speed of to-be-cooked items by 2 too. We could imagine other manipulations like that. Well, I reviewed many events that seems impossible to me so there is probably something I completely missed. Can you help me ?
-
After a few bugfixes, it seems to work, thank you. I have now a generic class allowing me to create shapeless recipes that uses whatever tool I want. Fantastic.
-
Yeah it doesn't crash anymore but there is nothing left in the left area. The condition is never satisfied because everything is consumed in the crafting inventory and I don't know how to change that.