Jump to content

Harystolho

Members
  • Posts

    11
  • Joined

  • Last visited

Posts posted by Harystolho

  1. @Override
    	public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    
    		if ((stack.getMaxItemUseDuration() - entityLiving.getItemInUseCount()) / 20.0F > 5.0) {
    			NBTTagCompound tag = stack.getTagCompound();
    			int radius = tag.getInteger("ToolRadius");
    			for (int x = -radius; x < radius + 1; x++) {
    				for (int y = -radius; y < radius + 1; y++) {
    					for (int z = -radius; z < radius + 1; z++) {
    						BlockPos blockpos = new BlockPos(entityLiving.getPosition().getX() + x,
    								entityLiving.getPosition().getY() + y, entityLiving.getPosition().getZ() + z);
    						IBlockState iblockstate = worldIn.getBlockState(blockpos);
    						if (isOre(iblockstate.getBlock())) {
    							IBlockState stone = Blocks.STONE.getDefaultState();
    							worldIn.setBlockState(blockpos, stone);
    							ItemStack item = new ItemStack(iblockstate.getBlock());
    						
    							entityLiving.entityDropItem(item, 1F);
    						}
    					}
    				}
    			}
    		}
    	}

     

    I'd like to put the blocks I break in the player inventory but I couldn't find an way to do that, so I tried spawning them in the ground, It works but It also spawns some ghost items that I can't pickup

    2017-11-12_15_58_07.png.deef115b74f5251f7ae554fd48ec1d70.png

     

    https://github.com/Harystolho/UberMiner/blob/1.12/src/main/java/harystolho/uberminer/objects/items/BowUber.java

  2. 1 hour ago, diesieben07 said:
    • Do not use ITileEntityProvider. Override hasTileEntity and createTileEntity.
    • Do not use breakBlock for block drops, use getDrops. You will need additional checks, to preserve the TileEntity, see the forge patches to BlockFlowerPot.

    https://github.com/Harystolho/UberMiner/blob/1.12/src/main/java/harystolho/uberminer/objects/blocks/BlockUberTable.java

    Take a look at my class

    Override hasTileEntity and createTileEntity. - OK

    Do not use breakBlock for block drops, use getDrops. - OK

    see the forge patches to BlockFlowerPot. - Didn't find

  3. 2 hours ago, Draco18s said:

    The fact that the chest being not-empty causes the undesired behavior, we can look at your code and find that you have a conditional for exactly this case:

    
    if (!tileentityiubertable.isEmpty()) {

    Therefore, this code is responsible for dropping one of the two items.

    
    spawnAsEntity(worldIn, pos, itemstack);

    Oh, look, it does.

     

    However we know that this is also the version we want to drop therefore it must be something else that's causing the empty copy to drop. Hmm. Empty chest...wait, we get one of these when the chest is empty too! There must be a line that is probably responsible and outside that if-block.

    Getting a TE...no

    Casting a TE...no

    Only one other line:

    
    super.breakBlock(worldIn, pos, state);

    This must be responsible.

     

    Unfortunately as you did not include your whole class, I cannot be sure that the parent class is not just Block.

    public class BlockUberTable extends Block implements IHasModel, ITileEntityProvider

    And I tried to do this

    @Override
    	public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    		TileEntity tileentity = worldIn.getTileEntity(pos);
    
    		if (tileentity instanceof TileEntityUberTable) {
    			TileEntityUberTable tileentityiubertable = (TileEntityUberTable) tileentity;
    
    			if (!tileentityiubertable.isEmpty()) {
    				ItemStack itemstack = new ItemStack(Item.getItemFromBlock(this), 1, 0);
    				NBTTagCompound nbttagcompound = new NBTTagCompound();
    				NBTTagCompound nbttagcompound1 = new NBTTagCompound();
    
    				nbttagcompound.setTag("BlockEntityTag", ((TileEntityUberTable) tileentity).writeToNBT(nbttagcompound1));
    				itemstack.setTagCompound(nbttagcompound);
    
    				if (tileentityiubertable.hasCustomName()) {
    					itemstack.setStackDisplayName(tileentityiubertable.getName());
    
    					tileentityiubertable.setCustomName("Uber Table");
    				}
    				spawnAsEntity(worldIn, pos, itemstack);
    
    				worldIn.updateComparatorOutputLevel(pos, state.getBlock());
    			} else {
    				super.breakBlock(worldIn, pos, state);	
    			}
    		}
    	}

    It still doesn't work, I still get 2 items

  4. @Override
    	public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    		TileEntity tileentity = worldIn.getTileEntity(pos);
    
    		if (tileentity instanceof TileEntityUberTable) {
    			TileEntityUberTable tileentityiubertable = (TileEntityUberTable) tileentity;
    
    			if (!tileentityiubertable.isEmpty()) {
    				ItemStack itemstack = new ItemStack(Item.getItemFromBlock(this), 1, 0);
    				NBTTagCompound nbttagcompound = new NBTTagCompound();
    				NBTTagCompound nbttagcompound1 = new NBTTagCompound();
    
    				nbttagcompound.setTag("BlockEntityTag", ((TileEntityUberTable) tileentity).writeToNBT(nbttagcompound1));
    				itemstack.setTagCompound(nbttagcompound);
    
    				if (tileentityiubertable.hasCustomName()) {
    					itemstack.setStackDisplayName(tileentityiubertable.getName());
    
    					tileentityiubertable.setCustomName("Uber Table");
    				}
    				spawnAsEntity(worldIn, pos, itemstack);
    
    				worldIn.updateComparatorOutputLevel(pos, state.getBlock());
    			}
    			super.breakBlock(worldIn, pos, state);
    		}
    	}

     

    This is a chest, if it's empty and I break it, it drops only 1 item(the chest itself) but if I put something inside it, it drops two items, one has nbt(It's a chest with the items saved in it), the other one doesn't, it's just an empty chest

  5. public class ItemUberTool extends Item implements IHasModel{
    
    	public ItemUberTool(String name) {
    		setUnlocalizedName(name);
    		setRegistryName(name);
    		setMaxStackSize(1);
    		setCreativeTab(Main.UBERMINER);
    		
    		ItemInit.ITEMS.add(this);
    	}
    	@Override
    	public void registerModels() {
    		Main.proxy.registerItemRenderer(this, 0, "inventory");
    	}
    
    
    }

     

    I'm using setMaxStackSize(1); but it's not working, it can get a full stack of this item.

×
×
  • Create New...

Important Information

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