Jump to content

JimiIT92

Members
  • Posts

    867
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JimiIT92

  1. I'm trying to create a wand that when right clicked will give a potion effect to the entity the player is looking at. But for some reason the effect is not applied Here's the code i'm using right now package com.mw.items; import com.mw.MW; import com.mw.core.MWTabs; import com.mw.utils.EnumWands; import com.mw.utils.Utils; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.MobEffects; import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumHand; import net.minecraft.util.SoundCategory; import net.minecraft.world.World; public class ItemWand extends Item{ private EnumWands type; public ItemWand(EnumWands typeIn) { this.setCreativeTab(MWTabs.TOOLS); this.maxStackSize = 1; this.setMaxDamage(256); this.type = typeIn; } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { if(!worldIn.isRemote) { if(this.type == EnumWands.CORRUPTER || this.type == EnumWands.HEALER) { Entity pointed = Utils.getLookingEntity(); if(pointed != null && pointed instanceof EntityLiving) { Potion potion; int effect = MW.RANDOM.nextInt(5); if(this.type == EnumWands.CORRUPTER) { switch(effect) { case 0: default: potion = MobEffects.POISON; break; case 1: potion = MobEffects.BLINDNESS; break; case 2: potion = MobEffects.LEVITATION; break; case 3: potion = MobEffects.SLOWNESS; break; case 4: potion = MobEffects.WEAKNESS; break; } worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_ENDERMITE_AMBIENT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); } else { switch(effect) { case 0: default: potion = MobEffects.REGENERATION; break; case 1: potion = MobEffects.RESISTANCE; break; case 2: potion = MobEffects.ABSORPTION; break; case 3: potion = MobEffects.INSTANT_HEALTH; break; case 4: potion = MobEffects.STRENGTH; break; } worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); } ((EntityLiving)pointed).addPotionEffect(new PotionEffect(potion, 30 * 20)); ItemStack itemstack = playerIn.getHeldItem(handIn); if (!playerIn.capabilities.isCreativeMode) { itemstack.damageItem(1, playerIn); } Utils.setCooldown(playerIn, this, 3); } } } return super.onItemRightClick(worldIn, playerIn, handIn); } } I'm sure the code got called because the wand goes in cooldown and the sound is played, it's just the effect doesn't apply to the mob (and both effect and entity are corrects). How can i fix this?
  2. I made a custom chest but the rendering is giving some gltiches. First of all the chest is not rendering though the tileentity is registered. This is the TileEntityCode package com.mw.entities.tileentity; import com.mw.blocks.BlockChestMW; import com.mw.utils.EnumDimensions; import net.minecraft.block.Block; import net.minecraft.block.BlockChest; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; public class TileEntityChestCorrupted extends TileEntityChest{ /** * Get the name of this object. For players this returns their username */ public String getName() { return this.hasCustomName() ? super.getName() : "container.chest.corrupted"; } protected TileEntityChest getAdjacentChest(EnumFacing side) { BlockPos blockpos = this.pos.offset(side); if (this.isChestAt(blockpos)) { TileEntity tileentity = this.world.getTileEntity(blockpos); if (tileentity instanceof TileEntityChestCorrupted) { TileEntityChestCorrupted tileentitychest = (TileEntityChestCorrupted)tileentity; tileentitychest.getNeighbor(this, side.getOpposite()); return tileentitychest; } } return null; } @SuppressWarnings("incomplete-switch") private void getNeighbor(TileEntityChest chestTe, EnumFacing side) { if (chestTe.isInvalid()) { this.adjacentChestChecked = false; } else if (this.adjacentChestChecked) { switch (side) { case NORTH: if (this.adjacentChestZNeg != chestTe) { this.adjacentChestChecked = false; } break; case SOUTH: if (this.adjacentChestZPos != chestTe) { this.adjacentChestChecked = false; } break; case EAST: if (this.adjacentChestXPos != chestTe) { this.adjacentChestChecked = false; } break; case WEST: if (this.adjacentChestXNeg != chestTe) { this.adjacentChestChecked = false; } } } } private boolean isChestAt(BlockPos posIn) { if (this.world == null) { return false; } else { Block block = this.world.getBlockState(posIn).getBlock(); return block instanceof BlockChestMW && ((BlockChestMW)block).getDimension() == EnumDimensions.CORRUPTED; } } } And this is how i register the TileEntity addTileEntity(TileEntityChestCorrupted.class, new RenderTileEntityChestMW(EnumDimensions.CORRUPTED)); private static void addTileEntity(Class<? extends TileEntity> tileEntity, TileEntitySpecialRenderer specialRenderer) { ClientRegistry.registerTileEntity(tileEntity, MW.MODID + ":" + tileEntity.getSimpleName().toLowerCase(), specialRenderer); } The rendering class is this package com.mw.renders.tileentity; import com.mw.MW; import com.mw.blocks.BlockChestMW; import com.mw.utils.EnumDimensions; import net.minecraft.block.Block; import net.minecraft.block.BlockChest; import net.minecraft.client.model.ModelChest; import net.minecraft.client.model.ModelLargeChest; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class RenderTileEntityChestMW extends TileEntitySpecialRenderer<TileEntityChest> { private static ResourceLocation TEXTURE_NORMAL_DOUBLE = new ResourceLocation("textures/entity/chest/normal_double.png"); private static ResourceLocation TEXTURE_NORMAL = new ResourceLocation("textures/entity/chest/normal.png"); private final ModelChest simpleChest = new ModelChest(); private final ModelChest largeChest = new ModelLargeChest(); private EnumDimensions dimension; public RenderTileEntityChestMW(EnumDimensions dimension) { this.dimension = dimension; } public void render(TileEntityChest te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { TEXTURE_NORMAL_DOUBLE = new ResourceLocation(MW.MODID, "textures/entity/chest/" + this.dimension.getName() + "_double.png"); TEXTURE_NORMAL = new ResourceLocation(MW.MODID, "textures/entity/chest/" + this.dimension.getName() + ".png"); GlStateManager.enableDepth(); GlStateManager.depthFunc(515); GlStateManager.depthMask(true); int i; if (te.hasWorld()) { Block block = te.getBlockType(); i = te.getBlockMetadata(); if (block instanceof BlockChestMW) { ((BlockChestMW)block).checkForSurroundingChests(te.getWorld(), te.getPos(), te.getWorld().getBlockState(te.getPos())); i = te.getBlockMetadata(); } te.checkForAdjacentChests(); } else { i = 0; } if (te.adjacentChestZNeg == null && te.adjacentChestXNeg == null) { ModelChest modelchest; if (te.adjacentChestXPos == null && te.adjacentChestZPos == null) { modelchest = this.simpleChest; if (destroyStage >= 0) { this.bindTexture(DESTROY_STAGES[destroyStage]); GlStateManager.matrixMode(5890); GlStateManager.pushMatrix(); GlStateManager.scale(4.0F, 4.0F, 1.0F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.matrixMode(5888); } else { this.bindTexture(TEXTURE_NORMAL); } } else { modelchest = this.largeChest; if (destroyStage >= 0) { this.bindTexture(DESTROY_STAGES[destroyStage]); GlStateManager.matrixMode(5890); GlStateManager.pushMatrix(); GlStateManager.scale(8.0F, 4.0F, 1.0F); GlStateManager.translate(0.0625F, 0.0625F, 0.0625F); GlStateManager.matrixMode(5888); } else { this.bindTexture(TEXTURE_NORMAL_DOUBLE); } } GlStateManager.pushMatrix(); GlStateManager.enableRescaleNormal(); if (destroyStage < 0) { GlStateManager.color(1.0F, 1.0F, 1.0F, alpha); } GlStateManager.translate((float)x, (float)y + 1.0F, (float)z + 1.0F); GlStateManager.scale(1.0F, -1.0F, -1.0F); GlStateManager.translate(0.5F, 0.5F, 0.5F); int j = 0; if (i == 2) { j = 180; } if (i == 3) { j = 0; } if (i == 4) { j = 90; } if (i == 5) { j = -90; } if (i == 2 && te.adjacentChestXPos != null) { GlStateManager.translate(1.0F, 0.0F, 0.0F); } if (i == 5 && te.adjacentChestZPos != null) { GlStateManager.translate(0.0F, 0.0F, -1.0F); } GlStateManager.rotate((float)j, 0.0F, 1.0F, 0.0F); GlStateManager.translate(-0.5F, -0.5F, -0.5F); float f = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks; if (te.adjacentChestZNeg != null) { float f1 = te.adjacentChestZNeg.prevLidAngle + (te.adjacentChestZNeg.lidAngle - te.adjacentChestZNeg.prevLidAngle) * partialTicks; if (f1 > f) { f = f1; } } if (te.adjacentChestXNeg != null) { float f2 = te.adjacentChestXNeg.prevLidAngle + (te.adjacentChestXNeg.lidAngle - te.adjacentChestXNeg.prevLidAngle) * partialTicks; if (f2 > f) { f = f2; } } f = 1.0F - f; f = 1.0F - f * f * f; modelchest.chestLid.rotateAngleX = -(f * ((float)Math.PI / 2F)); modelchest.renderAll(); GlStateManager.disableRescaleNormal(); GlStateManager.popMatrix(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); if (destroyStage >= 0) { GlStateManager.matrixMode(5890); GlStateManager.popMatrix(); GlStateManager.matrixMode(5888); } } } } The chest is rendering in inventory as well but when placed down i can only see the bounding box. Also i've noticed that if i place a vanilla chest near my chest the vanilla chest is also rendered as invisible. How can i fix this?
  3. If you don't care about the generated one but only the placed one you can catch the onBlockPlaced event and set your block instead of vanilla one (like i do with my custom flower pot)
  4. In my mod i have a block that is a custom fire, wich class is just this public class BlockFireMW extends BlockFire{ public BlockFireMW() { super(); } } Nothing special. But in game i got 2 main problems. The first is that i can't break it. If i click on it to "break" or ignite, it will break the block underneath instead of just ignite the fire (like vanilla fire does). The second one is that an entity walking on this fire will not burn or get damage. So how can i fix those since in the main class i didn't found anything related to this?
  5. I solved this looking at the EntityEnderPearl class and basically adding this functon to my entity class public void onUpdate() { EntityLivingBase entitylivingbase = this.getThrower(); if (entitylivingbase != null && entitylivingbase instanceof EntityPlayer && !entitylivingbase.isEntityAlive()) { this.setDead(); } else { super.onUpdate(); } } Hope that works too for you
  6. *facepalm* Forgot to add that method to the entity class. I don't know how but in 1.10 that works too without the onUpdate method BTW is fixed now, thank you for your help
  7. How can i check that?
  8. Yes the Entity is registered and it does stay alive becaus on impact it cause an explosion. Is created server side like Ender Pearls public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack itemstack = playerIn.getHeldItem(handIn); if (!playerIn.capabilities.isCreativeMode) { itemstack.shrink(1); } worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_PLAYER_HURT_ON_FIRE, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); Utils.setCooldown(playerIn, this, 2); if (!worldIn.isRemote) { EntityGranade entitygranade = new EntityGranade(worldIn, playerIn); entitygranade.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F); worldIn.spawnEntity(entitygranade); } playerIn.addStat(StatList.getObjectUseStats(this)); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack); } The RenderSnowball class i noticed that sometimes is called (using a breakpoint in that class) and sometimes is not, but i don't understand why this happen
  9. As by title, i have an entity that acts like a snowball (so it's throwable) but is not rendering when fired. This is how i register the rendering in my client proxy RenderingRegistry.registerEntityRenderingHandler(EntityGranade.class, new EntityGranadeFactory()); //The Entity Class public class EntityGranade extends EntityThrowable { private EntityLivingBase thrower; public EntityGranade(World worldIn) { super(worldIn); } public EntityGranade(World worldIn, EntityLivingBase throwerIn) { super(worldIn, throwerIn); this.thrower = throwerIn; } @SideOnly(Side.CLIENT) public EntityGranade(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } protected void onImpact(RayTraceResult result) { if(this.getThrower() != null && this.getThrower() instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP)this.getThrower(); if(player.connection.getNetworkManager().isChannelOpen() && player.world == this.world) { EntityTNTPrimed tnt = new EntityTNTPrimed(player.world); tnt.world.createExplosion(tnt, this.posX, this.posY, this.posZ, 2.0F, true); } } this.setDead(); } } //The Factory Class public class EntityGranadeFactory implements IRenderFactory<EntityGranade>{ @Override public Render<? super EntityGranade> createRenderFor(RenderManager manager) { return new RenderSnowball<EntityGranade>(manager, MWItems.GRANADE, Minecraft.getMinecraft().getRenderItem()); } } I have other things registerd like this (like custom TNT) and they all works as well, is just this that is not rendering. So why this happen and how can be fixed?
  10. I created a custom biome extended from the HIlls Biome. When i register this biome i don't add it to the villages biomes, but for some reason villages still spawns in my biome. How can i avoid this? This is the code for the biome package com.mw.world.biome; import java.util.Iterator; import java.util.Random; import com.mw.MW; import com.mw.core.MWBlocks; import com.mw.world.gen.feature.WorldGenVolcano; import net.minecraft.entity.monster.EntityMagmaCube; import net.minecraft.entity.monster.EntityPolarBear; import net.minecraft.entity.monster.EntitySkeleton; import net.minecraft.entity.monster.EntityStray; import net.minecraft.init.Biomes; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.BiomeHills; import net.minecraft.world.chunk.ChunkPrimer; import net.minecraft.world.gen.feature.WorldGenIceSpike; import net.minecraft.world.gen.feature.WorldGenLakes; import net.minecraftforge.common.BiomeManager.BiomeType; public class BiomeVolcano extends BiomeHills{ private WorldGenLakes LAKES = new WorldGenLakes(Blocks.LAVA); public BiomeVolcano() { super(BiomeHills.Type.NORMAL, new BiomeProperties("Volcano").setTemperature(10.0F).setBaseHeight(1.0F).setHeightVariation(0.1F)); this.topBlock = Blocks.COAL_BLOCK.getDefaultState(); this.fillerBlock = MWBlocks.LAVA_ROCK.getDefaultState(); this.spawnableCreatureList.clear(); this.spawnableMonsterList.add(new Biome.SpawnListEntry(EntityMagmaCube.class, 10, 1, 4)); } @Override public int getSkyColorByTemp(float currentTemperature) { return 0xFF0000; } @Override public void decorate(World worldIn, Random rand, BlockPos pos) { super.decorate(worldIn, rand, pos); if(net.minecraftforge.event.terraingen.TerrainGen.decorate(worldIn, rand, pos, net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.LAKE_WATER)) if (rand.nextInt(5) == 0) { int i = rand.nextInt(16) + 8; int j = rand.nextInt(16) + 8; BlockPos blockpos = worldIn.getHeight(pos.add(i, 0, j)).up(); LAKES.generate(worldIn, rand, blockpos); } if (rand.nextInt(2) == 0) { int i = rand.nextInt(16) + 8; int j = rand.nextInt(16) + 8; BlockPos blockpos = worldIn.getHeight(pos.add(i, 0, j)).up(); new WorldGenVolcano().generate(worldIn, rand, blockpos); } } public void genTerrainBlocks(World worldIn, Random rand, ChunkPrimer chunkPrimerIn, int x, int z, double noiseVal) { this.generateBiomeTerrain(worldIn, rand, chunkPrimerIn, x, z, noiseVal); } } And this is how i register it public static Biome VOLCANO; VOLCANO = new BiomeVolcano(); VOLCANO.setRegistryName("volcano"); //In the registration event event.getRegistry().register(VOLCANO); //In the registration event BiomeManager.addBiome(BiomeType.DESERT, new BiomeManager.BiomeEntry(VOLCANO, 5));
  11. If you want to override a vanilla loot table you can also make your own loot table (wich is a copy of the vanilla one + the items of your mod) and then in that event set your loot table as the table of the event. For example, i do this to override the vanilla mineshaft chest loot table. I create my own mineshaft chest loot table by doing this public static ResourceLocation CHESTS_ABANDONED_MINESHAFT; CHESTS_ABANDONED_MINESHAFT = LootTableList.register(new ResourceLocation(MW.MODID, "abandoned_mineshaft")); and i call this from the init method in main mod file. This will assume that in your assets folder you have a folder called "loot_tables" and inside that folder you have the loot table you're looking for (in this case "abandoned_mineshaft"). That will be the replaced loot table (so the game will load this instead of the vanilla one). For example look at this loot table { "pools": [ { "name": "abandoned_mineshaft_1", "rolls": 1, "entries": [ { "type": "item", "entryName": "golden_apple", "name": "minecraft:golden_apple", "weight": 20 }, { "type": "item", "entryName": "enchanted_golden_apple", "name": "minecraft:golden_apple", "weight": 1, "functions": [ { "function": "set_data", "data": 1 } ] }, { "type": "item", "name": "minecraft:name_tag", "weight": 30 }, { "type": "item", "name": "minecraft:book", "weight": 10, "functions": [ { "function": "enchant_randomly" } ] }, { "type": "item", "name": "minecraft:iron_pickaxe", "weight": 5 }, { "type": "item", "name": "mw:ruby", "weight": 20, "functions": [ { "function": "set_count", "count": { "min": 1, "max": 4 } } ] }, { "type": "item", "name": "mw:sapphire", "weight": 20, "functions": [ { "function": "set_count", "count": { "min": 1, "max": 4 } } ] }, { "type": "empty", "weight": 5 } ] }, { "name": "abandoned_mineshaft_2", "rolls": { "min": 2, "max": 4 }, "entries": [ { "type": "item", "name": "minecraft:iron_ingot", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 5 } } ], "weight": 10 }, { "type": "item", "name": "minecraft:gold_ingot", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 3 } } ], "weight": 5 }, { "type": "item", "name": "minecraft:redstone", "functions": [ { "function": "set_count", "count": { "min": 4, "max": 9 } } ], "weight": 5 }, { "type": "item", "name": "minecraft:dye", "functions": [ { "function": "set_data", "data": 4 }, { "function": "set_count", "count": { "min": 4, "max": 9 } } ], "weight": 5 }, { "type": "item", "name": "minecraft:diamond", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 2 } } ], "weight": 3 }, { "type": "item", "name": "minecraft:coal", "functions": [ { "function": "set_count", "count": { "min": 3, "max": 8 } } ], "weight": 10 }, { "type": "item", "name": "minecraft:bread", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 3 } } ], "weight": 15 }, { "type": "item", "name": "minecraft:melon_seeds", "functions": [ { "function": "set_count", "count": { "min": 2, "max": 4 } } ], "weight": 10 }, { "type": "item", "name": "minecraft:pumpkin_seeds", "functions": [ { "function": "set_count", "count": { "min": 2, "max": 4 } } ], "weight": 10 }, { "type": "item", "name": "minecraft:beetroot_seeds", "functions": [ { "function": "set_count", "count": { "min": 2, "max": 4 } } ], "weight": 10 } ] }, { "name": "abandoned_mineshaft_3", "rolls": 3, "entries": [ { "type": "item", "name": "minecraft:rail", "functions": [ { "function": "set_count", "count": { "min": 4, "max": 8 } } ], "weight": 20 }, { "type": "item", "name": "minecraft:golden_rail", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 4 } } ], "weight": 5 }, { "type": "item", "name": "minecraft:detector_rail", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 4 } } ], "weight": 5 }, { "type": "item", "name": "minecraft:activator_rail", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 4 } } ], "weight": 5 }, { "type": "item", "name": "minecraft:torch", "functions": [ { "function": "set_count", "count": { "min": 1, "max": 16 } } ], "weight": 15 } ] } ] } This is the vanilla abandoned_mineshaft loot table plus some rolls for my mod items, so in game in mineshafts i can find mod items too in chests. Finally, to load this table instead of the vanilla one you'll have to catch the LootTableLoadEvent and set the table to your own table. public void onLootTableLoad(LootTableLoadEvent event) { if(event.getName().equals(LootTableList.CHESTS_ABANDONED_MINESHAFT)) { event.setTable(event.getLootTableManager().getLootTableFromLocation(MWLootTables.CHESTS_ABANDONED_MINESHAFT)); } } In game, when you'll open a mineshaft chest it will load your loot table (the one showed up) instead of the vanilla one and so yuour mod items will have a chance to be in that cehst. Hope this is clear :)
  12. That's unfortunate, i hope there will be a way to specify the Recipe Book tab too soon for any block/item that is not in the vanilla creative tabs
  13. Thank you. Infact having this file { "type": "minecraft:crafting_shaped", "pattern": [ "AAA", "ASA", "AAA" ], "key": { "S": { "item": "mw:ruby" }, "A": { "item": "minecraft:stone", "data": 0 } }, "result": { "item": "mw:ruby_ore", "data": 0 } } Now the recipe work. But i've noticed is not going in the proper tab on the recipe book. For example, this recipe refers to a building block, how can i display it in that tab and not only in the "all recipes" tab?
  14. Ok, so if a block has a variant but you don't want to use a specific one you still need to specify it? That means, if the block has 10 variants, that you have to specify 10 recipes changing the data value every time?
  15. Woops. By the way that comma was not the problem, i removed that but the recipe is still not working. I guess i must register it before but can't figure out how
  16. Yes, i said "modid" to be generic, but the actual path is assets/mw/recipes (since mw is my mod id). Other things like blocks and items works as well so i guess is not a wrong folder path
  17. I have this json recipe in assets/modid/recipes folder { "type": "minecraft:crafting_shaped", "pattern": [ "AAA", "ASA", "AAA" ], "key": { "S": { "item": "mw:ruby" }, "A": [ { "item": "minecraft:stone", }, ] }, "result": { "item": "mw:ruby_ore", "data": 0 } } But in game is not working, so i guess i have to register it. So how can i register a crafting recipe in 1.12? :)
  18. Ok, i get it But there is at least a way to get the mod id of the dimension's mod? So i can make that string by my own?
  19. Pretty self explaining: how can i get the dimension name based on the provider or the id? I know that doing getDimensionType().getName() i can have something like "Overworld", but what i want is something like "minecraft:overworld" or "somemod:dimension" (if is a dimension from a mod). How can i do that?
  20. I have a GUI with some buttons in it, and when i click those buttons i want the gui to change appearance (basically some buttons will be replaced with others). How can i do so that the gui automatically refresh without closing it and reopening it to see the changes? Also i've noticed that the gui repaint itself when i resize the window, doing something like this How can i made so the gui doesn't do this every time i resize? This is my gui code, thanks in advance to everyone who will help me understand these problems package com.cf.gui; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import org.lwjgl.opengl.GL11; import com.cf.CoreFaction; import com.cf.network.GuiCoreAddExpansionServerMessage; import com.cf.network.GuiCoreRemoveServerMessage; import com.cf.network.GuiCoreSaveServerMessage; import com.cf.utils.Settings; import com.cf.utils.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.init.MobEffects; import net.minecraft.potion.Potion; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class GuiCore extends GuiScreen { private static final ResourceLocation BG = new ResourceLocation(CoreFaction.MODID, "textures/gui/core.png"); private String territory; private String faction; private int coreLevel; private int expansions; private int primaryEffect; private int secondaryEffect; private int primaryLevel; private int secondaryLevel; private GuiCore.UpgradeButton upgradeCoreButton; private GuiCore.ExpansionButton expansionButton; private GuiCore.RemoveButton removeButton; private int guiLeft; private int guiTop; private int xSize = 256; private int ySize = 181; private ArrayList<AllyEffectButton> allyButtons = new ArrayList<AllyEffectButton>(); private ArrayList<EnemyEffectButton> enemyButtons = new ArrayList<EnemyEffectButton>(); private ArrayList<AllyActiveEffectButton> allyActiveButtons = new ArrayList<AllyActiveEffectButton>(); private ArrayList<EnemyActiveEffectButton> enemyActiveButtons = new ArrayList<EnemyActiveEffectButton>(); private ArrayList<Potion> allyEffects = new ArrayList<Potion>(); private ArrayList<Potion> enemyEffects = new ArrayList<Potion>(); private int maxCoreLevel = 10; public GuiCore(String t, String f, int l, int e, int e1, int e2, int l1, int l2) { this.territory = t; this.faction = f; this.coreLevel = l; this.expansions = e; this.primaryEffect = e1; this.secondaryEffect = e2; this.primaryLevel = l1; this.secondaryLevel = l2; } @Override public void initGui() { this.guiLeft = (this.width - xSize) / 2; this.guiTop = (this.height - ySize) / 2; this.upgradeCoreButton = new GuiCore.UpgradeButton(-1, this.guiLeft + 19, this.guiTop + 144); this.expansionButton = new GuiCore.ExpansionButton(-2, this.guiLeft + 116, this.guiTop + 144); this.removeButton = new GuiCore.RemoveButton(-3, this.guiLeft + 213, this.guiTop + 144); this.buttonList.add(upgradeCoreButton); this.buttonList.add(expansionButton); this.buttonList.add(removeButton); this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.JUMP_BOOST))); this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.SPEED))); this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.RESISTANCE))); this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.HASTE))); this.allyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.ABSORPTION))); this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.HUNGER))); this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.WEAKNESS))); this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.SLOWNESS))); this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.BLINDNESS))); this.enemyEffects.add(Potion.getPotionById(Potion.getIdFromPotion(MobEffects.MINING_FATIGUE))); for (int i = 0; i < 5; i++) { this.allyButtons.add( new AllyEffectButton(i, this.guiLeft + 11 + 5, this.guiTop + 20 + (24 * i), allyEffects.get(i), 0)); this.allyActiveButtons.add(new AllyActiveEffectButton(i, this.guiLeft + 11 + 5, this.guiTop + 20 + (24 * i), allyEffects.get(i), 0)); this.enemyButtons.add(new EnemyEffectButton(i + 5, this.guiLeft + (this.xSize - 106 - 11 - 5), this.guiTop + 20 + (24 * i), enemyEffects.get(i), 0)); this.enemyActiveButtons.add(new EnemyActiveEffectButton(i + 5, this.guiLeft + (this.xSize - 106 - 11 - 5), this.guiTop + 20 + (24 * i), enemyEffects.get(i), 0)); } this.buttonList.addAll(allyButtons); this.buttonList.addAll(enemyButtons); } @Override public void updateScreen() { if (this.primaryLevel != -999) { for (int i = 0; i < allyEffects.size(); i++) { if (Potion.getIdFromPotion(allyEffects.get(i)) == this.primaryEffect) { this.buttonList.remove(allyButtons.get(i)); this.buttonList.add(allyActiveButtons.get(i)); } } for (int i = 0; i < enemyEffects.size(); i++) { if (Potion.getIdFromPotion(enemyEffects.get(i)) == this.primaryEffect) { this.buttonList.remove(enemyEffects.get(i)); this.buttonList.add(enemyActiveButtons.get(i)); } } } if (this.secondaryLevel != -999) { for (int i = 0; i < enemyEffects.size(); i++) { if (Potion.getIdFromPotion(enemyEffects.get(i)) == this.secondaryEffect) { this.buttonList.remove(enemyButtons.get(i)); this.buttonList.add(enemyActiveButtons.get(i)); } } for (int i = 0; i < enemyEffects.size(); i++) { if (Potion.getIdFromPotion(enemyEffects.get(i)) == this.secondaryEffect) { this.buttonList.remove(enemyEffects.get(i)); this.buttonList.add(enemyActiveButtons.get(i)); } } } super.updateScreen(); } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); this.mc.getTextureManager().bindTexture(getBg()); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 256, 181); String terr = Utils.getTranslation("gui.core.territory", TextFormatting.GREEN); terr += ": " + territory; if (terr.length() >= 38) { if (coreLevel == maxCoreLevel) { this.fontRendererObj.drawString(terr.substring(0, 37) + "...", this.guiLeft + 19, this.guiTop + 10, 4210752); this.fontRendererObj.drawString(" | " + Utils.getTranslation("gui.core.level", TextFormatting.GOLD) + ": " + String.valueOf(coreLevel), this.guiLeft + this.xSize - 64, this.guiTop + 10, 4210752); } else { this.fontRendererObj.drawString(terr.substring(0, 38) + "...", this.guiLeft + 19, this.guiTop + 10, 4210752); this.fontRendererObj.drawString(" | " + Utils.getTranslation("gui.core.level", TextFormatting.GOLD) + ": " + String.valueOf(coreLevel), this.guiLeft + this.xSize - 58, this.guiTop + 10, 4210752); } } else { this.fontRendererObj.drawString(terr, this.guiLeft + 19, this.guiTop + 10, 4210752); this.fontRendererObj.drawString( " | " + Utils.getTranslation("gui.core.level", TextFormatting.GOLD) + ": " + String.valueOf(coreLevel), coreLevel == maxCoreLevel ? this.guiLeft + this.xSize - 64 : this.guiLeft + this.xSize - 58, this.guiTop + 10, 4210752); } for (int i = 0; i < this.buttonList.size(); ++i) { ((GuiButton) this.buttonList.get(i)).drawButton(this.mc, mouseX, mouseY); } for (int i = 0; i < this.buttonList.size(); ++i) { if (this.buttonList.get(i) instanceof AllyActiveEffectButton || this.buttonList.get(i) instanceof AllyEffectButton) this.drawString(Minecraft.getMinecraft().fontRendererObj, Utils.getTranslation(((HoverEffectButton) this.buttonList.get(i)).getEffect()) + " " + (((HoverEffectButton) this.buttonList.get(i)).getTier() == 0 ? "" : (((HoverEffectButton) this.buttonList.get(i)).getTier() + 1)), ((HoverEffectButton) this.buttonList.get(i)).xPosition + 25, ((HoverEffectButton) this.buttonList.get(i)).yPosition + 7, 0xFFFFFF); else if (this.buttonList.get(i) instanceof EnemyActiveEffectButton || this.buttonList.get(i) instanceof EnemyEffectButton) this.drawString(Minecraft.getMinecraft().fontRendererObj, Utils.getTranslation(((HoverEffectButton) this.buttonList.get(i)).getEffect()) + " " + (((HoverEffectButton) this.buttonList.get(i)).getTier() == 0 ? "" : (((HoverEffectButton) this.buttonList.get(i)).getTier() + 1)), ((HoverEffectButton) this.buttonList.get(i)).xPosition + 5, ((HoverEffectButton) this.buttonList.get(i)).yPosition + 7, 0xFFFFFF); } this.mc.getTextureManager().bindTexture(getBg()); if (coreLevel < Settings.expansionLevel || expansions >= Settings.maxPurchasableExpansions) this.expansionButton.setEnabled(false); if (coreLevel == maxCoreLevel) this.upgradeCoreButton.setEnabled(false); if (this.coreLevel < 2) { this.drawTexturedModalRect(this.allyButtons.get(0).xPosition + 3, this.allyButtons.get(0).yPosition + 2, 0, 192, 18, 18); this.drawTexturedModalRect(this.enemyButtons.get(0).xPosition + 84, this.enemyButtons.get(0).yPosition + 2, 0, 192, 18, 18); this.allyButtons.get(0).setEnabled(false); this.enemyButtons.get(0).setEnabled(false); } if (this.coreLevel < 4) { this.drawTexturedModalRect(this.allyButtons.get(1).xPosition + 3, this.allyButtons.get(1).yPosition + 2, 0, 192, 16, 18); this.drawTexturedModalRect(this.enemyButtons.get(1).xPosition + 84, this.enemyButtons.get(1).yPosition + 2, 0, 192, 16, 18); this.allyButtons.get(1).setEnabled(false); this.enemyButtons.get(1).setEnabled(false); } if (this.coreLevel < 6) { this.drawTexturedModalRect(this.allyButtons.get(2).xPosition + 3, this.allyButtons.get(2).yPosition + 2, 0, 192, 16, 18); this.drawTexturedModalRect(this.enemyButtons.get(2).xPosition + 84, this.enemyButtons.get(2).yPosition + 2, 0, 192, 16, 18); this.allyButtons.get(2).setEnabled(false); this.enemyButtons.get(2).setEnabled(false); } if (this.coreLevel < { this.drawTexturedModalRect(this.allyButtons.get(3).xPosition + 3, this.allyButtons.get(3).yPosition + 2, 0, 192, 16, 18); this.drawTexturedModalRect(this.enemyButtons.get(3).xPosition + 84, this.enemyButtons.get(3).yPosition + 2, 0, 192, 16, 18); this.allyButtons.get(3).setEnabled(false); this.enemyButtons.get(3).setEnabled(false); } if (this.coreLevel < 10) { this.drawTexturedModalRect(this.allyButtons.get(4).xPosition + 3, this.allyButtons.get(4).yPosition + 2, 0, 192, 16, 18); this.drawTexturedModalRect(this.enemyButtons.get(4).xPosition + 84, this.enemyButtons.get(4).yPosition + 2, 0, 192, 16, 18); this.allyButtons.get(4).setEnabled(false); this.enemyButtons.get(4).setEnabled(false); } for (GuiButton button : this.buttonList) { if (button.isMouseOver()) { if (button instanceof HoverEffectButton) { this.zLevel = 100; if (button.enabled) { this.drawCreativeTabHoveringText(((HoverEffectButton) button).getHoverText(), mouseX, mouseY); } else { if (button.id == 0 || button.id == 5) this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.2"), mouseX, mouseY); else if (button.id == 1 || button.id == 6) this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.4"), mouseX, mouseY); else if (button.id == 2 || button.id == 7) this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.6"), mouseX, mouseY); else if (button.id == 3 || button.id == this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.8"), mouseX, mouseY); else if (button.id == 4 || button.id == 9) this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.unlock.10"), mouseX, mouseY); } this.zLevel = 0; } else { if (button.id == -1) { if (coreLevel < maxCoreLevel) { int g = Settings.baseUpgradeCost * coreLevel; String up = Utils.getTranslation("gui.core.upgrade", TextFormatting.GOLD) + " " + String.valueOf(coreLevel + 1); String down = (g != 0 ? String.valueOf(g) + Utils.getTranslation("gui.core.gemstones", TextFormatting.LIGHT_PURPLE) : ""); this.drawHoveringText(Arrays.<String>asList(up, down), mouseX, mouseY); } else this.drawCreativeTabHoveringText( Utils.getTranslation("gui.core.upgrade.max", TextFormatting.RED), mouseX, mouseY); } else if (button.id == -2) { if (coreLevel >= Settings.expansionLevel) { if (this.expansions < Settings.maxPurchasableExpansions) { int g = Settings.expansionBaseCost.getGold() * (expansions + 1); int s = Settings.expansionBaseCost.getSilver() * (expansions + 1); int c = Settings.expansionBaseCost.getCopper() * (expansions + 1); String up = Utils.getTranslation("gui.core.expansion", TextFormatting.GREEN) + " (" + Utils.getTranslation("gui.core.purchased") + ": " + String.valueOf(expansions) + "/" + String.valueOf(Settings.maxPurchasableExpansions) + ")"; String down = (g != 0 ? String.valueOf(g) + Utils.getTranslation("gui.core.golds", TextFormatting.YELLOW) : "") + (s != 0 ? String.valueOf(s) + Utils.getTranslation("gui.core.silvers", TextFormatting.GRAY) : "") + (c != 0 ? String.valueOf(c) + Utils.getTranslation("gui.core.coppers", TextFormatting.DARK_RED) : ""); this.drawHoveringText(Arrays.<String>asList(up, down), mouseX, mouseY); } else this.drawCreativeTabHoveringText( Utils.getTranslation("gui.core.expansion.max", TextFormatting.RED), mouseX, mouseY); } else this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.expansion.locked") + " " + String.valueOf(Settings.expansionLevel), mouseX, mouseY); } else if (button.id == -3) { String up = Utils.getTranslation("gui.core.remove", TextFormatting.RED); String down = Utils.getTranslation("gui.core.remove.back"); this.drawHoveringText(Arrays.<String>asList(up, down), mouseX, mouseY); } } } } } @Override protected void actionPerformed(GuiButton button) throws IOException { if (button.enabled) { int id = button.id; if (id == -1) { int g = Settings.baseUpgradeCost * coreLevel; if (Utils.canPayGemstones(this.mc.thePlayer, g) && coreLevel < 10) { Utils.payGemstones(this.mc.thePlayer, g); coreLevel++; if (coreLevel >= maxCoreLevel / 2 && coreLevel < maxCoreLevel) { primaryLevel = 2; secondaryLevel = 2; } else if (coreLevel == maxCoreLevel) { primaryLevel = 3; secondaryLevel = 3; } Utils.sendMessage(this.mc.thePlayer, Utils.getTranslation("gui.core.upgrade.success", TextFormatting.GREEN)); CoreFaction.NETWORK.sendToServer(new GuiCoreSaveServerMessage(this.territory, String.valueOf(this.coreLevel), String.valueOf(this.expansions), String.valueOf(this.primaryEffect), String.valueOf(this.secondaryEffect), String.valueOf(this.primaryLevel), String.valueOf(this.secondaryLevel))); } else Utils.sendMessage(this.mc.thePlayer, Utils.getTranslation("gui.core.upgrade.fail", TextFormatting.RED)); this.mc.displayGuiScreen((GuiScreen)null); } else if (id == -2) { int g = Settings.expansionBaseCost.getGold() * expansions; int s = Settings.expansionBaseCost.getSilver() * expansions; int c = Settings.expansionBaseCost.getCopper() * expansions; if (Utils.canPay(this.mc.thePlayer, g, s, c) && coreLevel >= Settings.expansionLevel && this.expansions < Settings.maxPurchasableExpansions) { Utils.pay(this.mc.thePlayer, g, s, c); CoreFaction.NETWORK.sendToServer(new GuiCoreAddExpansionServerMessage(territory)); expansions++; Utils.sendMessage(this.mc.thePlayer, Utils.getTranslation("gui.core.expansion.success", TextFormatting.GREEN)); } else { this.mc.displayGuiScreen((GuiScreen)null); Utils.sendMessage(this.mc.thePlayer, Utils.getTranslation("gui.core.expansion.fail", TextFormatting.RED)); } } else if (id == -3) { CoreFaction.NETWORK.sendToServer(new GuiCoreRemoveServerMessage(territory, faction)); Utils.sendMessage(this.mc.thePlayer, Utils.getTranslation("gui.core.remove.success", TextFormatting.RED)); this.mc.displayGuiScreen((GuiScreen) null); return; } else if (id == 0) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(0)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(0)) ? -999 : Potion.getIdFromPotion(allyEffects.get(0)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(0)) ? -999 : Potion.getIdFromPotion(allyEffects.get(0)); } } else if (id == 1) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(1)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(1)) ? -999 : Potion.getIdFromPotion(allyEffects.get(1)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(1)) ? -999 : Potion.getIdFromPotion(allyEffects.get(1)); } } else if (id == 2) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(2)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(2)) ? -999 : Potion.getIdFromPotion(allyEffects.get(2)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(2)) ? -999 : Potion.getIdFromPotion(allyEffects.get(2)); } } else if (id == 3) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(3)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(3)) ? -999 : Potion.getIdFromPotion(allyEffects.get(3)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(3)) ? -999 : Potion.getIdFromPotion(allyEffects.get(3)); } } else if (id == 4) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(allyEffects.get(4)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(allyEffects.get(4)) ? -999 : Potion.getIdFromPotion(allyEffects.get(4)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(allyEffects.get(4)) ? -999 : Potion.getIdFromPotion(allyEffects.get(4)); } } else if (id == 5) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(0)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(0)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(0)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(0)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(0)); } } else if (id == 6) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(1)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(1)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(1)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(1)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(1)); } } else if (id == 7) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(2)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(2)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(2)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(2)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(2)); } } else if (id == { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(3)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(3)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(3)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(3)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(3)); } } else if (id == 9) { if(this.primaryEffect != -999 && this.primaryEffect != Potion.getIdFromPotion(enemyEffects.get(4)) && coreLevel == maxCoreLevel) { this.secondaryEffect = this.secondaryEffect == Potion.getIdFromPotion(enemyEffects.get(4)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(4)); } else { this.primaryEffect = this.primaryEffect == Potion.getIdFromPotion(enemyEffects.get(4)) ? -999 : Potion.getIdFromPotion(enemyEffects.get(4)); } } CoreFaction.NETWORK.sendToServer(new GuiCoreSaveServerMessage(this.territory, String.valueOf(this.coreLevel), String.valueOf(this.expansions), String.valueOf(this.primaryEffect), String.valueOf(this.secondaryEffect), String.valueOf(this.primaryLevel), String.valueOf(this.secondaryLevel))); } super.actionPerformed(button); } @Override public boolean doesGuiPauseGame() { return false; } public static ResourceLocation getBg() { return BG; } @SideOnly(Side.CLIENT) class UpgradeButton extends ActionButton { public UpgradeButton(int buttonId, int x, int y) { super(buttonId, x, y, GuiCore.getBg(), 0, 237); } public void drawButtonForegroundLayer(int mouseX, int mouseY) { GuiCore.this.drawCreativeTabHoveringText( Utils.getTranslation("gui.core.upgrade", TextFormatting.GOLD) + "\n" + "Test", mouseX, mouseY); } } @SideOnly(Side.CLIENT) class ExpansionButton extends ActionButton { public ExpansionButton(int buttonId, int x, int y) { super(buttonId, x, y, GuiCore.getBg(), 0, 237); } public void drawButtonForegroundLayer(int mouseX, int mouseY) { GuiCore.this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.expansion", TextFormatting.GREEN), mouseX, mouseY); } } @SideOnly(Side.CLIENT) class RemoveButton extends ActionButton { public RemoveButton(int buttonId, int x, int y) { super(buttonId, x, y, GuiCore.getBg(), 23, 210); } public void drawButtonForegroundLayer(int mouseX, int mouseY) { GuiCore.this.drawCreativeTabHoveringText(Utils.getTranslation("gui.core.remove", TextFormatting.RED), mouseX, mouseY); } } }
  21. Woops, my bad Changed that and now it sends the message, hope everything works as intended now EDIT: Yes, it works now, thanks everybody for your help
  22. Ok, so i send a message from the onBlockActivated method to the server, but server crash with this error [00:10:31] [Server thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught java.lang.RuntimeException: Missing at net.minecraftforge.fml.server.FMLServerHandler.getClientToServerNetworkManager(FMLServerHandler.java:281) ~[FMLServerHandler.class:?] at net.minecraftforge.fml.common.FMLCommonHandler.getClientToServerNetworkManager(FMLCommonHandler.java:545) ~[FMLCommonHandler.class:?] at net.minecraftforge.fml.common.network.FMLOutboundHandler$OutboundTarget$8.selectNetworks(FMLOutboundHandler.java:245) ~[FMLOutboundHandler$OutboundTarget$8.class:?] at net.minecraftforge.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:293) ~[FMLOutboundHandler.class:?] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:658) ~[AbstractChannelHandlerContext.class:4.0.23.Final] at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:716) ~[AbstractChannelHandlerContext.class:4.0.23.Final] at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:651) ~[AbstractChannelHandlerContext.class:4.0.23.Final] at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:112) ~[MessageToMessageEncoder.class:4.0.23.Final] at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.0.23.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:658) ~[AbstractChannelHandlerContext.class:4.0.23.Final] at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:716) ~[AbstractChannelHandlerContext.class:4.0.23.Final] at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:706) ~[AbstractChannelHandlerContext.class:4.0.23.Final] at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:741) ~[AbstractChannelHandlerContext.class:4.0.23.Final] at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:895) ~[DefaultChannelPipeline.class:4.0.23.Final] at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:240) ~[AbstractChannel.class:4.0.23.Final] at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(SimpleNetworkWrapper.java:294) [SimpleNetworkWrapper.class:?] at com.cf.blocks.BlockCore.onBlockActivated(BlockCore.java:105) [BlockCore.class:?] at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:477) [PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processRightClickBlock(NetHandlerPlayServer.java:706) [NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) [CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) [CPacketPlayerTryUseItemOnBlock.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) [PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_131] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_131] at net.minecraft.util.Util.runTask(Util.java:28) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:743) [MinecraftServer.class:?] at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:408) [DedicatedServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:688) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:537) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_131] This is the message class package com.cf.network; import com.cf.CoreFaction; import com.cf.faction.Faction; import com.cf.faction.Territory; import com.cf.utils.TerritoryUtils; import io.netty.buffer.ByteBuf; import net.minecraft.util.IThreadListener; import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class GuiCoreServerMessage implements IMessage{ private String name; public GuiCoreServerMessage() { } public GuiCoreServerMessage(String n) { this.name = n; } @Override public void fromBytes(ByteBuf buf) { this.name = ByteBufUtils.readUTF8String(buf); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, name); } public static class Handler implements IMessageHandler<GuiCoreServerMessage, IMessage> { @Override public IMessage onMessage(final GuiCoreServerMessage message, final MessageContext ctx) { IThreadListener mainThread = CoreFaction.PROXY.getListener(ctx); mainThread.addScheduledTask(new Runnable() { @Override public void run() { Territory t = TerritoryUtils.getTerritoryByName(message.name); if(t != null) { Faction f = TerritoryUtils.getFaction(t); if(f != null) System.out.println(f.getName()); } } }); return null; } } } This is how i register the message and the channel public static SimpleNetworkWrapper NETWORK; @EventHandler public void preInit(FMLPreInitializationEvent event) { NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MODID); NETWORK.registerMessage(GuiCoreServerMessage.Handler.class, GuiCoreServerMessage.class, 0, Side.SERVER); } and this is how i send the message from the block @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if(!worldIn.isRemote) { TileEntity te = worldIn.getTileEntity(pos); if(te instanceof TileEntityCore) { CoreFaction.NETWORK.sendToServer(new GuiCoreServerMessage(((TileEntityCore)te).getName())); } } return true; } What am i missing? :/
  23. So i should just send a message (via SimpleNetworkWrapper) to the client with all the necessary informations (taken from the server) and inside the message decide if open the Gui or not?
×
×
  • Create New...

Important Information

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