Jump to content

ChampionAsh5357

Members
  • Posts

    3284
  • Joined

  • Last visited

  • Days Won

    62

Everything posted by ChampionAsh5357

  1. Ah, that might help. For some reason I thought that attaching it to the inventory meant that it was going to be attached to the player. I've fixed that now. However, now I seem to be getting a NullPointerException when the writeToNBT function is being called. I did, and I know I need to sync the server to the client data. However, I want to get rid of all the errors first so that it at least saves to server before I start implementing the client syncing. I was going to do that as soon as I finished getting it working properly.
  2. I am trying to add a custom slot to the player inventory. I've managed to get the container and GUI working and getting the visual to show up in game. However, I cannot seem to manage to keep the inventory persistent between sessions. I've been playing with the code in multiple ways, but I cannot seem to find a working solution. I might be overlooking something major and just not be noticing it. Any help is appreciated. Custom Player Inventory Capability: Capability Registry Custom Player Inventory Event Loading Container
  3. This is my tile entity class. I'm pretty sure it synchronizing with the client because debug I ran has both values as the same during the read and write. Also, as I mentioned previously, the particles do change color which I can only assume is from the client. The only thing that doesn't change color is the actual block. I apologize if I'm misunderstanding what you meant. public class TileEntitySingleColor extends TileEntity implements ITickable{ private int red = 0, green = 0, blue = 0; @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("red", this.red); compound.setInteger("green", this.green); compound.setInteger("blue", this.blue); return compound; } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.red = compound.getInteger("red"); this.green = compound.getInteger("green"); this.blue = compound.getInteger("blue"); } @Override public NBTTagCompound getUpdateTag() { return this.writeToNBT(new NBTTagCompound()); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { this.readFromNBT(pkt.getNbtCompound()); } @Override public SPacketUpdateTileEntity getUpdatePacket() { return new SPacketUpdateTileEntity(this.pos, 0, this.getUpdateTag()); } public void setRgb(int red, int green, int blue) { this.red = red; this.green = green; this.blue = blue; } public int[] rgb() { return new int[] {this.red, this.green, this.blue}; } public int hex() { return ((red&0x0ff)<<16)|((green&0x0ff)<<8)|(blue&0x0ff); } @Override public void update() { } }
  4. I created a block to update the color based on the rgb input of the player. I've managed to create the tile entity and implement the IBlockColor and IItemColor for the block. However, the in-game block model doesn't update. I know that the code is working somewhat because the block's particles change color. Color Handler within postInit: Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(new IBlockColor() { @Override public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) { TileEntitySingleColor te = (TileEntitySingleColor)worldIn.getTileEntity(pos); return te.hex(); } }, CustomBlocks.single_color); final IItemColor item_color = (stack, tintIndex) -> { IBlockState iblockstate = ((ItemBlock) stack.getItem()).getBlock().getDefaultState(); return Minecraft.getMinecraft().getBlockColors().colorMultiplier(iblockstate, null, null, tintIndex); }; Minecraft.getMinecraft().getItemColors().registerItemColorHandler(item_color, CustomBlocks.single_color); Simplified version of onBlockActivated (Test purposes): @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing heldItem, float side, float hitX, float hitY) { TileEntitySingleColor color = (TileEntitySingleColor)worldIn.getTileEntity(pos); color.setRgb(255, 0, 0); color.getWorld().notifyBlockUpdate(pos, state, state, 0); return true; } Can anyone please help me figure out what I'm doing incorrectly? Thank you.
  5. The reason I use ITileEntityProvider is because I'm overriding a custom class for blocks. ITileEntityProvider does the same as extending BlockContainer. Thanks, I'll look into it.
  6. I started working on a project about a year ago now that I just started to actually complete. I spent about four hours creating the tile entity to create a pipe that teleports you to a location based on the information stored. However, when I close the world and reload it, the client side does not seem to be able to load up the information stored in the nbt while the server side can. I'm not the greatest at tile entities so I was wondering if anyone could help me fix this problem. This is my tile entity: package com.championash5357.supermariobrothers.tileentity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; public class TileEntityWarpPipe extends TileEntity { private double xCoord, yCoord, zCoord; @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); this.xCoord = compound.getDouble("XCoordinate"); this.yCoord = compound.getDouble("YCoordinate"); this.zCoord = compound.getDouble("ZCoordinate"); System.out.println("NBT X: "+ compound.getInteger("XCoordinate")); System.out.println("NBT Y: "+ compound.getInteger("YCoordinate")); System.out.println("NBT Z: "+ compound.getInteger("ZCoordinate")); } @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setDouble("XCoordinate", this.xCoord); compound.setDouble("YCoordinate", this.yCoord); compound.setDouble("ZCoordinate", this.zCoord); return compound; } public void setCoordinates(ItemStack wrench) { NBTTagCompound nbt = (NBTTagCompound)wrench.getTagCompound().getTag("coordinates"); this.xCoord = nbt.getDouble("XCoord"); this.yCoord = nbt.getDouble("YCoord"); this.zCoord = nbt.getDouble("ZCoord"); } public double getX() { return this.xCoord; } public double getY() { return this.yCoord; } public double getZ() { return this.zCoord; } } This is my block code: package com.championash5357.supermariobrothers.blocks; import java.util.List; import org.lwjgl.input.Keyboard; import com.championash5357.supermariobrothers.client.Reference.SuperMario; import com.championash5357.supermariobrothers.init.MarioBlocks; import com.championash5357.supermariobrothers.items.ItemWrench; import com.championash5357.supermariobrothers.tileentity.TileEntityWarpPipe; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockWarpPipeBase extends BlockSuperMarioBros implements ITileEntityProvider{ protected static final AxisAlignedBB PIPE_NF = new AxisAlignedBB(0.8125D, 0D, 0D, 0.875D, 1D, 0.8125D); protected static final AxisAlignedBB PIPE_NR = new AxisAlignedBB(0D, 0D, 0.8125D, 0.8125D, 1D, 0.875D); protected static final AxisAlignedBB PIPE_ND = new AxisAlignedBB(0D, 0D, 0D, 0.8125D, 0.0625D, 0.8125D); protected static final AxisAlignedBB PIPE_WF = new AxisAlignedBB(0.8125D, 0D, 0.1875D, 0.875D, 1D, 1D); protected static final AxisAlignedBB PIPE_WL = new AxisAlignedBB(0D, 0D, 0.125D, 0.8125D, 1D, 0.1875D); protected static final AxisAlignedBB PIPE_WD = new AxisAlignedBB(0D, 0D, 0.1875D, 0.8125D, 0.0625D, 1D); protected static final AxisAlignedBB PIPE_SB = new AxisAlignedBB(0.125D, 0D, 0.1875D, 0.1875D, 1D, 1D); protected static final AxisAlignedBB PIPE_SL = new AxisAlignedBB(0.1875D, 0D, 0.125D, 1D, 1D, 0.1875D); protected static final AxisAlignedBB PIPE_SD = new AxisAlignedBB(0.1875D, 0D, 0.1875D, 1D, 0.0625D, 1D); protected static final AxisAlignedBB PIPE_EB = new AxisAlignedBB(0.125D, 0D, 0D, 0.1875D, 1D, 0.8125D); protected static final AxisAlignedBB PIPE_ER = new AxisAlignedBB(0.1875D, 0D, 0.8125D, 1D, 1D, 0.875D); protected static final AxisAlignedBB PIPE_ED = new AxisAlignedBB(0.1875D, 0D, 0D, 1D, 0.0625D, 0.8125D); public static final PropertyDirection FACING = BlockHorizontal.FACING; public BlockWarpPipeBase() { super(Material.ROCK); setUnlocalizedName(SuperMario.WARP_PIPE_BASE.getUnlocalizedName()); setRegistryName(SuperMario.WARP_PIPE_BASE.getRegistryName()); setWikiName(SuperMario.WARP_PIPE_BASE.getWikiName()); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = playerIn.getHeldItem(hand); if(stack != null) { if(stack.getItem() instanceof ItemWrench) { if(stack.getItem().hasEffect(stack)) { TileEntityWarpPipe pipe = (TileEntityWarpPipe)worldIn.getTileEntity(pos); pipe.setCoordinates(stack); NBTTagCompound nbt = (NBTTagCompound)stack.getTagCompound().getTag("coordinates"); double x = nbt.getDouble("XCoord"); double y = nbt.getDouble("YCoord"); double z = nbt.getDouble("ZCoord"); stack.func_190918_g(1); if(!worldIn.isRemote) playerIn.addChatMessage(new TextComponentString("This warp pipe at " + TextFormatting.GOLD + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + TextFormatting.WHITE + " will now teleport the player to " + TextFormatting.GOLD + x + ", " + y + ", " + z + TextFormatting.WHITE + ".")); } } } return true; } @Override public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) { return FULL_BLOCK_AABB.offset(pos); } @Override public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { if(entityIn instanceof EntityPlayer) teleport((EntityPlayer)entityIn, pos, worldIn); super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn); } private void teleport(EntityPlayer player, BlockPos pos, World world) { TileEntityWarpPipe pipe = (TileEntityWarpPipe)world.getTileEntity(pos); if(player.isSneaking()) { player.setLocationAndAngles(pipe.getX(), pipe.getY(), pipe.getZ(), player.rotationYaw, player.rotationPitch); } } @Override public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { EnumFacing enumfacing = (EnumFacing)state.getValue(FACING); switch(enumfacing) { case EAST: return PIPE_ED; case SOUTH: return PIPE_SD; case WEST: return PIPE_WD; case NORTH: default: return PIPE_ND; } } @Override public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn) { addCollisionBoxToList(pos, entityBox, collidingBoxes, state.getBoundingBox(worldIn, pos)); addCollisionBoxToList(pos, entityBox, collidingBoxes, this.getFrontShape(state)); addCollisionBoxToList(pos, entityBox, collidingBoxes, this.getSideShape(state)); } private AxisAlignedBB getFrontShape(IBlockState state) { switch((EnumFacing)state.getValue(FACING)) { case EAST: return PIPE_EB; case SOUTH: return PIPE_SB; case WEST: return PIPE_WF; case NORTH: default: return PIPE_NF; } } private AxisAlignedBB getSideShape(IBlockState state) { switch ((EnumFacing)state.getValue(FACING)) { case EAST: return PIPE_ER; case SOUTH: return PIPE_SL; case WEST: return PIPE_WL; case NORTH: default: return PIPE_NR; } } 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) { IBlockState iblockstate = worldIn.getBlockState(pos.north()); IBlockState iblockstate1 = worldIn.getBlockState(pos.south()); IBlockState iblockstate2 = worldIn.getBlockState(pos.west()); IBlockState iblockstate3 = worldIn.getBlockState(pos.east()); EnumFacing enumfacing = (EnumFacing)state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock()) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock()) { enumfacing = EnumFacing.NORTH; } else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock()) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock()) { enumfacing = EnumFacing.WEST; } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2); } } public static void setState(boolean active, World worldIn, BlockPos pos) { IBlockState iblockstate = worldIn.getBlockState(pos); worldIn.setBlockState(pos, MarioBlocks.warp_pipe_base.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3); worldIn.setBlockState(pos, MarioBlocks.warp_pipe_base.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3); } 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 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(); } public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING))); } public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING))); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {FACING}); } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public void func_190948_a(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) { tooltip.add("" + TextFormatting.DARK_RED + "Super Mario Bros."); tooltip.add(""); if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { tooltip.add("" + TextFormatting.GOLD + "One of the main modes of transportation that transports the traveler to the other end."); } else { tooltip.add("" + TextFormatting.WHITE + "Hold " + TextFormatting.AQUA + TextFormatting.UNDERLINE + "LShift" + TextFormatting.RESET + " for more information."); } } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityWarpPipe(); } } Thank you for your time.
  7. public class ItemCutter extends Item { public ItemCutter() { setUnlocalizedName("cutter"); setRegistryName("itemcutter"); setCreativeTab(CreativeTabs.MISC); setNoRepair(); setMaxDamage(79); setMaxStackSize(1); } @Override public boolean hasContainerItem(ItemStack stack) { return true; } @Override public ItemStack getContainerItem(ItemStack itemStack) { return itemStack.getItemDamage() < itemStack.getMaxDamage() ? new ItemStack(itemStack.getItem(), 1, itemStack.getItemDamage() + 1) : ItemStack.EMPTY; } }
  8. I originally created an item that would lose durability each time it was used in the crafting table. I managed to get the code to work properly, but there is a problem wen I shift-click the crafting recipe output. I created a shapeless recipe where it took my container item and another item and converted it into an output. However, if I shift-clicked the output to my inventory, it would convert all the items even if there wasn't enough durability for the entire stack. What I've noticed is that it initially checks the first one and then skips to the last one after it converted all the items. I want to know if there is a way to have it so that shift-clicking only converts the items to the amount of durability still left on the item. This is taking my container item with only one durability and a stack of items in the crafting table: This is the result after I shift-click on the output:
  9. In 1.12, the CraftingHelper.class registers minecraft and modded items for recipes along with the ore dictionary. However, I can't seem to figure out how to call an OreDictionary item through a json file. According to the code, I assumed it would be "item": "ore:logWood", however it says that this is a Unknown item and doesn't exist. Can somebody explain how to call on it please? Thank you.
  10. I know that Minecraft 1.12 is still in early development, but I had to try it out. I believe the only things that didn't work are the recipes and the advancements since they both are running through json files now and Minecraft Forge still hasn't release code supporting these new conditions. My question is regarding the recipes which are run through the CraftingManager and registered through the function func_193372_a with the two parameters being the ResourceLocation (which I assume is for the json file) and IRecipe (which is something that was supported in the past). I have never used IRecipe to register a crafting recipe, but is it possible to use this function in a mod being created for 1.12 if they have the foreknowledge of IRecipe to accurately use the function? I have been trying for the past two days and I'm not 100% sure if I am using IRecipe correctly.
×
×
  • Create New...

Important Information

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