Jump to content

zerofall

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by zerofall

  1. Great! That works. Now how do I tell that event to only render when right-click is being held? On the onRightClick method I set a flag to true, but how do I set it to false when right-click isn't being held any more?
  2. I'm actually trying to go for something that behaves more like this: https://youtu.be/IjVQVAt7j0U?t=38 Does that give a better idea?
  3. I would like to learn how to render a block in the world (a set distance from the player) when a player holds right-click on an item. Can anybody point me in the right direction? Here is what I have so far: @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { Vec3d look = playerIn.getLookVec(); float distance = 10.0F; double dx = playerIn.posX + (look.xCoord * distance); double dy = playerIn.posY + (look.yCoord * distance); double dz = playerIn.posZ + (look.zCoord * distance); BlockPos position = new BlockPos(dx, dy, dz); //RENDER THE BLOCK AT THE POSITION ABOVE return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); }
  4. Thanks! Here are some snippets of code I used to get this working: private static Method dropFewItems; private static Method dropEquipment; private static Method addRandomDrop; Boolean deobf = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); dropFewItems = EntityLivingBase.class.getDeclaredMethod(deobf ? "dropFewItems" : "func_70628_a", boolean.class, int.class); dropEquipment = EntityLivingBase.class.getDeclaredMethod(deobf ? "dropEquipment" : "func_82160_b", boolean.class, int.class); addRandomDrop = EntityLivingBase.class.getDeclaredMethod(deobf ? "addRandomDrop" : "func_82164_bB"); dropFewItems.setAccessible(true); dropEquipment.setAccessible(true); addRandomDrop.setAccessible(true);
  5. Great advice, its working great now. I should add that I had to call getDeclaredMethod on EntityLivingBase.class, not the mob's class (if anybody else runs into this same problem). The only thing left is: addRandomDrop. I checked methods.csv on the most recent MCP, and I can't find it. I found another mod that uses is, and decompiled to find func_82164_bB... but after some googling, I feel like that maps to something regarding armor. Am I missing something here?
  6. I am trying to change a mob's drops as if they were killed with Looting, but without using an enchanted item. The best I could come up with is to hook into LivingDropsEvent, and do this: if (!mob.isChild() && mob.worldObj.getGameRules().getBoolean("doMobLoot")) { mob.capturedDrops.clear(); mob.captureDrops = true; try { Method dropFewItems = mob.getClass().getMethod("dropFewItems", boolean.class, int.class); Method dropEquipment = mob.getClass().getMethod("dropEquipment", boolean.class, int.class); Method addRandomDrop = mob.getClass().getMethod("addRandomDrop"); dropFewItems.invoke(mob, true, customLootingLevel); dropEquipment.invoke(mob, true, customLootingLevel); if (mob.worldObj.rand.nextFloat() < 0.025F + (float)customLootingLevel* 0.01F) { addRandomDrop.invoke(mob); } mob.captureDrops = false; event.drops.clear(); event.drops.addAll(mob.capturedDrops); } I now have 2 probems: 1. I am getting this error: java.lang.NoSuchMethodException: net.minecraft.entity.passive.EntityChicken.dropFewItems(boolean, int) 2. I realized this might break when its re-obfuscated because the method names change. What is the best way to do this?
  7. Sure, ya registry name would work. I guess I'm hoping for something like this: anyItem.json: { "parent":"test:item/standard_item", "textures": { "layer0":"test:items/#this.registryName#" } }
  8. Thanks for the tips. So I can use 1 JSON file with 100 lines instead of 100 JSON files... but I am still wondering if there is a way to have 1 short, dynamic JSON file that passes in the unlocalized name instead? Or maybe a way to do this that goes around JSON files all together?
  9. I'm not sure if I understand what you mean, but I think I am already doing this. Example JSON files: standard_item.json { "parent":"builtin/generated", "display": { "thirdperson": { "rotation": [ -90, 0, 0 ], "translation": [ 0, 1, -3 ], "scale": [ 0.55, 0.55, 0.55 ] }, "firstperson": { "rotation": [ 0, -135, 25 ], "translation": [ 0, 4, 2 ], "scale": [ 1.7, 1.7, 1.7 ] } } } exampleItem1.json: { "parent":"test:item/standard_item", "textures": { "layer0":"test:items/exampleItem1" } } Code used to register model: public static void registerRenderer(Item item) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.modId + ":" + item.getUnlocalizedName().substring(5), "inventory")); } My problem is that for the "exampleItem1.json" file... I have tons of them... and SURELY there is a way around that. Is there a way that I can have them all use the same JSON file, and pass in the unlocalized name as a variable into the JSON file (or something like that)?
  10. I am working on a mod that has LOTS of items (not blocks), and I am getting tired of creating so many JSON item model files. They are all the EXACT same, except for the "layer0" path (and the image names are all the same as the unlocalized names). Is there a way around this so I don't have a hundred JSON files that are almost identical?
  11. That worked! Thanks so much. Here is the code that worked for me: ResourceLocation fluidTexture = FluidRegistry.LAVA.getStill(); TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluidTexture.toString()); Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); this.drawTexturedModalRect(0, 0, sprite, 16, 16);
  12. I tried this: ResourceLocation fluidTexture = FluidRegistry.LAVA.getStill(); TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluidTexture.toString()); Minecraft.getMinecraft().renderEngine.bindTexture(fluidTexture); this.drawTexturedModalRect(0, 0, sprite, 16, 16); I also tried to bring over the 1.7.10 code you pointed me to, but GL and rendering are my weakest areas, so I wasn't sure how to update it.
  13. Just tried what you described, and I'm still seeing the "no texture" texture (although I may be doing it wrong). I also looked at the link you provided, and I don't think it will work for 1.8. I think things like Tesselator and startDrawingQuads are gone now. Do you have a working code example for 1.8? Or know where I could find one?
  14. How do I render lava in my GUI? I tried this: ResourceLocation fluidTexture = FluidRegistry.LAVA.getStill(); Minecraft.getMinecraft().renderEngine.bindTexture(fluidTexture); this.drawModalRectWithCustomSizedTexture(0, 0, 0, 0, 16, 16, 16, 16); But I just get a square with "no texture". What is the right way to do this in 1.8.x?
  15. Ya, but vanilla classes don't use the optimized JSON stuff that forge has set up right?
  16. Anybody know how to make a block placeable on any surface? I currently have the block rendering, and it appears on the top-side of a block when I place it down. I want to be able to place it on walls/ceiling/etc., like a lever. How do I do this?
  17. When you run forge/mc from eclipse, everything is deobfuscated. This means that it doesn't play nice with normal mods (which are obfuscated). You need deobfuscated jar files for any mod you want in your eclipse run directory. Not all devs provide this, but some do.
  18. I am upgrading my 1.8 mod to 1.8.8... but it uses the NEI api. Anybody know if there is currently a way to use NEI with 1.8.8?
  19. Hmmm... that would imply that the combinations of properties is limited to 16 (the possible metadata values) right? I thought that was the point of properties/blockstates, to overcome that restriction?
  20. Sure, here is basic_generator.json: { "parent": "block/orientable", "textures": { "top": "autotech:blocks/machine_top", "front": "autotech:blocks/generator_front", "side": "autotech:blocks/machine_side" } } and here is basic_generator_active1.json: { "parent": "block/orientable", "textures": { "top": "autotech:blocks/machine_top", "front": "autotech:blocks/generator_front_active1", "side": "autotech:blocks/machine_side" } }
  21. Both of the things you mentioned are things I picked of from the vanilla BlockFurnace/TileEntityFurnace, and you are right, they are probably unnecessary. But, they shouldn't effect the actual problem I am having. Also, yes I am sure the JSONs are pointing to the right things. If I change the first 4 lines in my blockstate file to "autotech:basic_generator_active1", and the last 4 to "autotech:basic_generator", I have the same problem, just in reverse (texture is always "on", won't go "off"). Does anybody know of a simple example where this is being done somewhere the right way?
  22. I have been really struggling with blockstates. All I want to do is change a block's texture when its "active". Here is what I have: Block class: public class BlockTest extends BlockContainer { public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public static final PropertyBool ACTIVE = PropertyBool.create("active"); private static boolean keepInventory; int GUIid = -1; public BlockTest(String name, String guiName) { super(Material.rock); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, false)); setUnlocalizedName(name); GUIid = Autotech.proxy.registerGui(guiName); } public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(ModBlocks.test); } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.setDefaultFacing(worldIn, pos, state); } private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { Block block = worldIn.getBlockState(pos.north()).getBlock(); Block block1 = worldIn.getBlockState(pos.south()).getBlock(); Block block2 = worldIn.getBlockState(pos.west()).getBlock(); Block block3 = worldIn.getBlockState(pos.east()).getBlock(); EnumFacing enumfacing = (EnumFacing) state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock()) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock()) { enumfacing = EnumFacing.NORTH; } else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock()) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock()) { enumfacing = EnumFacing.WEST; } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing).withProperty(ACTIVE, false), 2); } } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return true; } else { if (GUIid>=0) { FMLNetworkHandler.openGui(playerIn, Autotech.instance, GUIid, worldIn, pos.getX(), pos.getY(), pos.getZ()); } } return true; } @Override public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { TileEntityTest generator = (TileEntityTest)world.getTileEntity(pos); boolean active = generator.isBurning(); return state.withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, active); } public static void setState(boolean active, World worldIn, BlockPos pos) { IBlockState iblockstate = worldIn.getBlockState(pos); TileEntity tileentity = worldIn.getTileEntity(pos); keepInventory = true; if (active) { System.out.println("Setting active"); worldIn.setBlockState(pos, ModBlocks.test.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ACTIVE,true), 3); worldIn.setBlockState(pos, ModBlocks.test.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ACTIVE,true), 3); } else { worldIn.setBlockState(pos, ModBlocks.test.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ACTIVE,false), 3); worldIn.setBlockState(pos, ModBlocks.test.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)).withProperty(ACTIVE,false), 3); } keepInventory = false; if (tileentity != null) { tileentity.validate(); worldIn.setTileEntity(pos, tileentity); } } public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityTest(); } public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2); } public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { if (!keepInventory) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityTest) { InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityTest) tileentity); worldIn.updateComparatorOutputLevel(pos, this); } } super.breakBlock(worldIn, pos, state); } public boolean hasComparatorInputOverride() { return true; } public int getComparatorInputOverride(World worldIn, BlockPos pos) { return Container.calcRedstone(worldIn.getTileEntity(pos)); } @SideOnly(Side.CLIENT) public Item getItem(World worldIn, BlockPos pos) { return Item.getItemFromBlock(ModBlocks.test); } public int getRenderType() { return 3; } public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getFront(meta); if (enumfacing.getAxis() == EnumFacing.Axis.Y) { enumfacing = EnumFacing.NORTH; } return this.getDefaultState().withProperty(FACING, enumfacing); } public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getIndex(); } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { FACING, ACTIVE }); } @SideOnly(Side.CLIENT) static final class SwitchEnumFacing { static final int[] FACING_LOOKUP = new int[EnumFacing.values().length]; private static final String __OBFID = "CL_00002111"; static { try { FACING_LOOKUP[EnumFacing.WEST.ordinal()] = 1; } catch (NoSuchFieldError var4) { ; } try { FACING_LOOKUP[EnumFacing.EAST.ordinal()] = 2; } catch (NoSuchFieldError var3) { ; } try { FACING_LOOKUP[EnumFacing.NORTH.ordinal()] = 3; } catch (NoSuchFieldError var2) { ; } try { FACING_LOOKUP[EnumFacing.SOUTH.ordinal()] = 4; } catch (NoSuchFieldError var1) { ; } } } } TileEntity Class: public class TileEntityTest extends TileEntity implements IInventory, IUpdatePlayerListBox { private ItemStack[] slots = new ItemStack[1]; private int furnaceBurnTime = 0; public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); NBTTagList nbttaglist = compound.getTagList("Items", 10); this.slots = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); byte b0 = nbttagcompound1.getByte("Slot"); if (b0 >= 0 && b0 < this.slots.length) { this.slots[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } this.furnaceBurnTime = compound.getShort("BurnTime"); } public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setShort("BurnTime", (short)this.furnaceBurnTime); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.slots.length; ++i) { if (this.slots[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.slots[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } compound.setTag("Items", nbttaglist); } /* Inventory methods */ @Override public int getSizeInventory() { return slots.length; } @Override public ItemStack getStackInSlot(int slot) { return slots[slot]; } @Override public ItemStack decrStackSize(int slot, int amt) { if (slots[slot] != null) { ItemStack newStack; if (slots[slot].stackSize <= amt) { newStack = slots[slot]; slots[slot] = null; } else { newStack = slots[slot].splitStack(amt); if (slots[slot].stackSize == 0) { slots[slot] = null; } } return newStack; } return null; } @Override public ItemStack getStackInSlotOnClosing(int slot) { if (slots[slot]!=null) { ItemStack stack = slots[slot]; slots[slot] = null; return stack; } return null; } @Override public void setInventorySlotContents(int slot, ItemStack stack) { slots[slot] = stack; if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } } @Override public String getName() { return null; } @Override public boolean hasCustomName() { return false; } @Override public IChatComponent getDisplayName() { return null; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return worldObj.getTileEntity(getPos()) == this && player.getDistanceSq(getPos().getX() + 0.5, getPos().getY() + 0.5, getPos().getZ() + 0.5) < 64; } @Override public void openInventory(EntityPlayer playerIn) {} @Override public void closeInventory(EntityPlayer playerIn) {} /* ISided Stuff */ @Override public boolean isItemValidForSlot(int slot, ItemStack stack) { return true; } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { } @Override public void update() { boolean flag = this.isBurning(); boolean flag1 = false; if (this.isBurning()) { --this.furnaceBurnTime; } if (!this.worldObj.isRemote) { if (!this.isBurning() && (this.slots[0] == null)) { } else { if (!this.isBurning() ) { this.furnaceBurnTime = getItemBurnTime(this.slots[0]); if (this.isBurning()) { flag1 = true; if (this.slots[0] != null) { --this.slots[0].stackSize; if (this.slots[0].stackSize == 0) { this.slots[0] = slots[0].getItem() .getContainerItem(slots[0]); } } } } } if (flag != this.isBurning()) { flag1 = true; BlockTest.setState(this.isBurning(), this.worldObj, this.pos); worldObj.markBlockForUpdate(pos); } } if (flag1) { this.markDirty(); } } public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return new ContainerBasicGenerator(playerInventory, this); } public int getItemBurnTime(ItemStack stack) { return TileEntityFurnace.getItemBurnTime(stack); } public boolean isBurning() { return this.furnaceBurnTime > 0; } Blockstate file: { "variants": { "active=false,facing=north": { "model": "autotech:basic_generator" }, "active=false,facing=east": { "model": "autotech:basic_generator", "y": 90 }, "active=false,facing=south": { "model": "autotech:basic_generator", "y": 180 }, "active=false,facing=west": { "model": "autotech:basic_generator", "y": 270 }, "active=true,facing=north": { "model": "autotech:basic_generator_active1" }, "active=true,facing=east": { "model": "autotech:basic_generator_active1", "y": 90 }, "active=true,facing=south": { "model": "autotech:basic_generator_active1", "y": 180 }, "active=true,facing=west": { "model": "autotech:basic_generator_active1", "y": 270 } } } I have tried a few different variations of the above, and my problem right now is this: - The state seems to be set correctly, but the texture doesn't change visibly What am I doing wrong?
  23. I have a "generator" block that has an "active" state. I have 4 textures for the front of the block: generator_front generator_front_active1 generator_front_active2 generator_front_active3 When the generator is "active", I want the front of it to randomly switch between the 3 active textures (for a fire-effect). What is the best way to do this? I tried adding an "active" property to the block class, and ended up with this as my .json model file: { "variants": { "active=0,facing=east": { "model": “generator_front” }, "active=0,facing=south": { "model": "generator_front", "y": 90 }, "active=0,facing=west": { "model": "generator_front", "y": 180 }, "active=0,facing=north": { "model": "generator_front", "y": 270 }, "active=1,facing=east": { "model": "generator_front_active1” }, "active=1,facing=south": { "model": "generator_front_active1”, "y": 90 }, "active=1,facing=west": { "model": "generator_front_active1”, "y": 180 }, "active=1,facing=north": { "model": "generator_front_active1”, "y": 270 }, "active=2,facing=east": { "model": "generator_front_active2” }, "active=2,facing=south": { "model": "generator_front_active2”, "y": 90 }, "active=2,facing=west": { "model": "generator_front_active2”, "y": 180 }, "active=2,facing=north": { "model": "generator_front_active2”, "y": 270 }, "active=3,facing=east": { "model": "generator_front_active3” }, "active=3,facing=south": { "model": "generator_front_active3”, "y": 90 }, "active=3,facing=west": { "model": "generator_front_active3”, "y": 180 }, "active=3,facing=north": { "model": "generator_front_active3”, "y": 270 } } } I also tried changing the "active" value in the random display tick method, but i got this weird problem where I would only see the block change textures 1 state at a time if I placed/broke a block nearby. What is the right way to do this?
×
×
  • Create New...

Important Information

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