Jump to content

Armetron

Members
  • Posts

    14
  • Joined

  • Last visited

Everything posted by Armetron

  1. Hi again so today I encountered a strange lighting bug when I gave one of my blocks the setlightvalue() function it seams that when the block is created it produces the intended light however if a stronger light soarce, lets say a torch overpowers the block then its lightlevel is increaced to match that level once the torch is removed. here are some Images to show what I mean When created, working as intended Added a torch next to it Now removed the torch I have never encountered this before when I was modding for 1.7.10 here is my block code package armetron.hardlight.blocks; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.ItemBlock; import net.minecraftforge.fml.common.registry.GameRegistry; public class LuminiumOre extends Block{ public LuminiumOre() { super(Material.ROCK); setUnlocalizedName("luminium_ore"); setRegistryName("luminium_ore"); setLightLevel(0.3f); GameRegistry.register(this); GameRegistry.register(new ItemBlock(this), getRegistryName()); } } knowing my past luck its probably something simple that I overlooked
  2. welp It seems I need to go back to Java class because the solution to my problem was rediculasly easy to fix, I read that I had to use logger.info("string") for it to work but every time I tryed to use it on a file that wasn't the mod file I couldn't get it to work turns out I forgot that I dont have to type logger.info(), I have to type *mymodfile*.logger.info(). I actually feel a bit of shame for not realizing that sooner Thanks anyway you guys
  3. well what my problem is in how to actually use it, for example in my CommonProxy file I have within the preInit "ModBlocks.init();" and "ModItems.init();" which loads all my stuff, I would l to print to console using the logger "Loading *my mod's* blocks" then "Done Loading *my mod's* blocks" that way if any errors happen with loading all I have to find are those two blocks of text to do this would I just have to type Logger#info("Loading " + Reference.MOD_ID + "'s Blocks")
  4. Hey guys So I'm slowly but surly making my mod by following every kind of tutorial I can find, however in many example codes I find I see something called a logger mixed into the code. After doing some research I found out that this part of the log4j api which basically responsible for printing all the text in console when you boot up an instance of forge (INFO, ERROR, ext...) which is something I find very useful and probably better than using println() however despite all these examples that have loggers placed in them I cant seem to find out how modders are actually using them. I followed McJty's Basic Mod - 1.9 tutorial and added logger = event.getModLog() into my preInit and included org.apache.logging.log4j.Logger but now I dont know how to use it, or if I even need to use it does anyone have any experience with loggers or is this something I shouldn't worry about? if this is something worth using are there any tutorials regarding it? (didn't seem to find any here)
  5. Hello, I am using forge 1.9.4 - 12.17.0.1976 and I am starting my path into Minecraft modding I did do some modding for 1.7 but unfortunately things have changed. I was following _Bedrock_Miner_'s 1.8 tutorial and for the most part everything was working until the implementation of items, when I type this.setCreativeTab(CreativeTabs.MISC) eclipse spits out and error saying The type com.google.common.reflect.TypeToken cannot be resolved. It is indirectly referenced from required .class files now the only solution that is given to me is to configure the build path which is already set to my forge project folder. Does anyone know what is going on or has anyone encountered this sort of problem? sorry if this is a ridiculously easy problem to fix, google doesn't show much in the way of a solution
  6. Ha, that was the exact webpage I used Thanks for the help
  7. woops forgot to take out the System.out.println(ticksRemaining); that's what I used to see that the ticks were being updated
  8. EUREKA!!!! I believe I've done it I finally got my item to update the stats of my tile entity remotely Item package com.armetron.crystalline_magic.items; import com.armetron.crystalline_magic.blocks.ModBlocks; import com.armetron.crystalline_magic.tileEntity.TEMagicLilypad; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class MagicTester extends Item { public MagicTester(String unlocalizedName) { super(); this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(CreativeTabs.tabMaterials); } @Override public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) { NBTTagCompound nbt = stack.getTagCompound(); if (nbt == null) { nbt = new NBTTagCompound(); stack.setTagCompound(nbt); } nbt.setBoolean("active", !(nbt.getBoolean("active"))); return stack; } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); if (nbt.getBoolean("active")) { //GET PLAYER POSITION int posX = (int) Math.round(entityIn.posX - 0.5f); int posY = (int) entityIn.posY; int posZ = (int) Math.round(entityIn.posZ - 0.5f); //PLACE BLOCKS AROUND PLAYER POSITION for (int x = posX - 1; x <= posX + 1; x++) { for (int z = posZ - 1; z <= posZ + 1; z++) { BlockPos posWater = new BlockPos(x, posY - 1, z); BlockPos posAir = new BlockPos(x, posY, z); //ONLY PLACE BLOCK ONTOP OF WATER if (worldIn.getBlockState(posWater).getBlock() == Blocks.water) { if (worldIn.isAirBlock(posAir)) { worldIn.setBlockState(posAir, ModBlocks.magicLilypad.getDefaultState()); } //Updates the ticks of an existing TileEntity if (worldIn.getBlockState(posAir).getBlock() == ModBlocks.magicLilypad) { TileEntity lily = worldIn.getTileEntity(posAir); ((TEMagicLilypad) lily).UpdateDecay(7); } } } } } } @Override @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); boolean active = nbt.getBoolean("active"); return active; } } Tile Entity package com.armetron.crystalline_magic.tileEntity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ITickable; public class TEMagicLilypad extends TileEntity implements ITickable{ private int ticksRemaining; //Used when Tile Entity is made from Block Class public TEMagicLilypad(int ticksRemaining){ this.ticksRemaining = ticksRemaining; } //Function used to manually update the ticks remaining public void UpdateDecay(int ticksRemaining) { this.ticksRemaining = ticksRemaining; } @Override public void readFromNBT(NBTTagCompound tagCompound){ super.readFromNBT(tagCompound); this.ticksRemaining = tagCompound.getInteger("TICKS_REMAINING"); } @Override public void writeToNBT(NBTTagCompound tagCompound){ super.writeToNBT(tagCompound); tagCompound.setInteger("TICKS_REMAINING", ticksRemaining); } //TickRemaining is detucted every tick and block is replaced with air //when ticks run out @Override public void update(){ ticksRemaining--; System.out.println(ticksRemaining); if (ticksRemaining <= 0){ worldObj.removeTileEntity(getPos()); worldObj.setBlockToAir(getPos()); } } } The part that was the hardest to discover is TileEntity lily = worldIn.getTileEntity(posAir); ((TEMagicLilypad) lily).UpdateDecay(7); I had no idea that ((class name) tileEntity) would be what edited the stored tileEntity If you happen to see something that I'm overdoing, underdoing, could make more efficient then please feel free to let me know so that I may learn
  9. Yea was reading the link you gave me and WOOSH right over my head, I probably will just have my test item replace the existing decaying blocks with new "fresh" blocks
  10. but isint Public TEMagicLilypad(int ticksRemaining) { this.ticksRemaining = ticksRemaining;} a method that edits the integer when called? sorry I am SUPER new to everything
  11. Well that was my problem, how do I update the integer? I could make it find my block and just replace it with a new block which would set it back to the default integer but I that would probably cause problems on servers down the line
  12. So in my mod I made an item that when activated it will place down a tile entity block that is invisible and has the same dimensions as a lily-pad, to give the illusion that you are walking on water, in an air block on top of a water source block When the item spawns the block, it sets an nbt integer of how long the block will last until it "decays." So far the blocks works great when the player is moving forward, however if the player were to stand still when the block under the player decays the held item is not fast enough to place a new one. What I would like to know is how can I have it so that when the item passes onUpdate() it will "reset" the integer of the blocks instead of waiting for them to decay and place a new one Test Item: @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); if (nbt.getBoolean("active")) { //GET PLAYER POSITION int posX = (int) Math.round(entityIn.posX - 0.5f); int posY = (int) entityIn.posY; int posZ = (int) Math.round(entityIn.posZ - 0.5f); //PLACE BLOCKS AROUND PLAYER POSITION for (int x = posX - 1; x <= posX + 1; x++) { for (int z = posZ - 1; z <= posZ + 1; z++) { BlockPos posWater = new BlockPos(x, posY - 1, z); BlockPos posAir = new BlockPos(x, posY, z); //ONLY PLACE BLOCK ONTOP OF WATER/IN AIR if (worldIn.getBlockState(posWater).getBlock() == Blocks.water) { if (worldIn.isAirBlock(posAir)) { worldIn.setBlockState(posAir, ModBlocks.magicLilypad.getDefaultState()); } } } } } } Bridge Block (magic lilypad) @Override public TileEntity createNewTileEntity(World world, int meta) { return new TEMagicLilypad(50); } Tile Entity Bridge Block public class TEMagicLilypad extends TileEntity implements ITickable{ private int ticksRemaining; public TEMagicLilypad(int ticksRemaining) { this.ticksRemaining = ticksRemaining; } @Override public void readFromNBT(NBTTagCompound tagCompound){ super.readFromNBT(tagCompound); this.ticksRemaining = tagCompound.getInteger("TICKS_REMAINING"); } @Override public void writeToNBT(NBTTagCompound tagCompound){ super.writeToNBT(tagCompound); tagCompound.setInteger("TICKS_REMAINING", ticksRemaining); } @Override public void update(){ ticksRemaining--; if (ticksRemaining <= 0){ worldObj.removeTileEntity(getPos()); worldObj.setBlockToAir(getPos()); } } }
  13. Woot, it works!!! funny thing is at first it still crashed, the reson was that when hasEffect was being called the item in my saved world did not have nbt data yet so it was returning a null. so I added a condition that if at the beggining of the hasEffect if getTagCompound == null then it makes a new NBTTagCompound @Override public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) { NBTTagCompound nbt = stack.getTagCompound(); if (nbt == null) { nbt = new NBTTagCompound(); stack.setTagCompound(nbt); } nbt.setBoolean("active", !(nbt.getBoolean("active"))); System.out.println(nbt.getBoolean("active")); //Used to test before adding hasEffect return stack; } @Override @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); boolean active = nbt.getBoolean("active"); return active; } CODING DOGE IS BEST DOGE!!!!!
  14. so I just started making my own mods for minecraft so I am a complete greenhorn however a do have java experience that I have had to brush up on. I've gotten to the point where I want to make my items "do" something, specifically this item will eventually create an invisible lily pad platform on top of any water source blocks around you. What I'm trying to achieve is have my item hold a Boolean value that determines if it is "on" or "off." To test this I want to feed the Boolean value into the hasEffect function so I can use the enchanted effect as a visual representation of what state it's in. I feel like I'm close but I still have trouble wrapping my head around NBT data. my code public class MagicTester extends Item { public MagicTester(String unlocalizedName) { super(); this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(CreativeTabs.tabMaterials); } @Override public ItemStack onItemRightClick(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer) { if (stack.getTagCompound() == null) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound nbt = stack.getTagCompound(); nbt.setBoolean("active", !(nbt.getBoolean("active"))); stack.getTagCompound().setTag("active", nbt); return stack; } @Override @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack) { NBTTagCompound nbt = (NBTTagCompound) stack.getTagCompound().getTag("active"); boolean active = nbt.getBoolean("active"); return active; } } If you know a good tutorial that talks about nbt data I would much appreciate it
×
×
  • Create New...

Important Information

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