Jump to content

Recommended Posts

Posted

So, my item destroys a 3x3 area of blocks. To do this, I use the onBlockDestroyed method in Item in my item's class. Within the method, I basically check if it has a certain boolean set true within the Item NBT and, if so remove the drops from the block and add it's smelted variant. When trying this, it does not clear the drops but, still adds the smelted variant. But then, doesn't drop the smelted variant. I am quite confused but I am sure it's something simple I am missing. Here's how I am TRYING to do it:

 

NOTE: I can't use the HarvestBlockEvent because, it doesn't register the blocks I destroy through my class. :P

if(stack.stackTagCompound.getBoolean("AutoSmelt") == true) {
		ArrayList<ItemStack> drops = block.getDrops(world, actualX, actualY, actualZ, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));

		LogHelper.logInfo("Drops: " + drops);

		if(FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(block)) != null) {
			ItemStack stackToDrop = FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(block, 1, meta)).copy();

			ItemStack stackToDrop1 = new ItemStack(stackToDrop.getItem(), 1);

			drops.clear();

			drops.add(stackToDrop1);

			LogHelper.logInfo("Drops: " + drops);
		}
	}

 

And here's what pops out in the console when destroying it (Happens eight times):

[22:38:35] [server thread/INFO] [Crew Mod]: Drops: [1xtile.oreGold@0]
[22:38:35] [server thread/INFO] [Crew Mod]: Drops: [1xitem.ingotGold@0]

 

Would appreciate some help!

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Im removing drops like so

if (event.drops != null && event.drops.size() != 0) {
			for (int x = event.drops.size() - 1; x >= 0; x--) {
                                          event.drops.remove(x); 

I'm beginner in java and in minecraft modding.

Please be specific.

Any code examples are appreciated.

Sorry for my english i'm from Czech republic.

Please hit that thank you button if i helped :)

Posted

This code makes it nothing to clear the drops.

ArrayList<ItemStack> drops = block.getDrops(world, actualX, actualY, actualZ, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));

A new instance of drops is made there, so changing that has no effect!

 

You cannot change drops in the Item#onBlockDestroyed(...). You should subscribe to the BlockEvent#HarvestDropsEvent.

 

+ 'it doesn't register the blocks I destroy through my class' means there is something wrong with your logic.

What do you mean by 'destroy through my class'?

If you are trying to break blocks within your logic, Please post relevant code.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Can you post your code for the full onBlocksDestroyed() method?

 

What I would do is break the block clicked on normally, and then destroy the other blocks with a setBlock() method which I'm pretty sure does not call the break or harvest events. As you destroy the other blocks, you can drop what you want.

 

Alternatively, as you destroy the blocks you can force the break event by posting it yourself with a ForgeHooks.onBlockBreakEvent() method call. Then you can handle the break event by checking if player is holding your item and proceeding accordingly.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

So basically, people from previous posts told me I should use the onBlockDestroyed method in the Item class to allow me to destroy extra blocks around the area (I previously used the BreakEvent). In doing this, I put all the breaking code for extra blocks in my Item Class. Here is my entire Item class. It is messy so ignore some parts that are quite long. Still developing it and will make it neater later. :P

 

CrewHammer.java

public class CrewHammer extends ItemPickaxe {

public CrewHammer(ToolMaterial tm) {
	super(tm);
	this.setCreativeTab(CrewMod.tabCrewTools);
	this.setUnlocalizedName("CrewHammer");
	this.setTextureName(MR.TNAME + "CrewHammer");
	this.setFull3D();
	this.setMaxStackSize(1);
}

public void onUpdate(ItemStack stack, World world, Entity entity, int i, boolean flag) {
	fixNBT(stack);
}

public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean flag) {
	list.add(EnumChatFormatting.RED + "Use SHIFT + Right-Click to");
	list.add(EnumChatFormatting.RED + "open the modification menu.");
	list.add("");
	list.add(EnumChatFormatting.GREEN + "Right-Click to quickly");
	list.add(EnumChatFormatting.GREEN + "change between mining sizes");
}

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	if(player.isSneaking()) {
		FMLNetworkHandler.openGui(player, CrewMod.instance, GuiId.guiCrewHammerID, world, (int)player.posX, (int)player.posY, (int)player.posZ);
	}

	return stack;
}

public static void fixNBT(ItemStack stack){
	if(stack.stackTagCompound == null) {
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack NBTTagCompound was null. Attempting fix...");

		stack.stackTagCompound = new NBTTagCompound();
	}

	/*if(!stack.stackTagCompound.hasKey("HammerTag")) {
		stack.stackTagCompound.setTag("HammerTag", new NBTTagCompound());
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'HammerTag'. Attempting fix...");
	}*/

	if(!stack.stackTagCompound.hasKey("MiningSize")) {
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'MiningSize'. Attempting fix...");

		stack.stackTagCompound.setString("MiningSize", "3x3");
	}

	if(!stack.stackTagCompound.hasKey("AutoSmelt")) {
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'AutoSmelt'. Attempting fix...");

		stack.stackTagCompound.setBoolean("AutoSmelt", true);
	}

	if(!stack.stackTagCompound.hasKey("AutoRepair")) {
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'AutoRepair'. Attempting fix...");

		stack.stackTagCompound.setBoolean("AutoRepair", false);
	}

	if(!stack.stackTagCompound.hasKey("Has3x3")) {
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'Has3x3'. Attempting fix...");

		stack.stackTagCompound.setBoolean("Has3x3", false);
	}

	if(!stack.stackTagCompound.hasKey("Has5x5")) {
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'Has5x5'. Attempting fix...");

		stack.stackTagCompound.setBoolean("Has5x5", false);
	}

	if(!stack.stackTagCompound.hasKey("Has7x7")) {
		LogHelper.logWarn("[CrewHammer] " + "The ItemStack did not contain the key 'Has7x7'. Attempting fix...");

		stack.stackTagCompound.setBoolean("Has7x7", false);
	}
}

/**
 * Used for setting the mining size of the Crew Hammer in seperate classes.
 * 
 * @param stack The Hammer.
 * @param miningSize The size to be set (3x3, 5x5, 7x7).
 */
public static void setMiningSize(ItemStack stack, String miningSize) {
	fixNBT(stack);

	stack.stackTagCompound.setString("MiningSize", miningSize);

	LogHelper.logInfo("[CrewHammer#setMiningSize] Method ran successfully! Mining Size is now: " + stack.stackTagCompound.getString("MiningSize"));
}

/**
 * Used for setting the mining size of the Crew Hammer in seperate classes.
 * 
 * @param stack The Hammer.
 * @param canAutoSmelt True if stack has the Auto Smelt mod. False otherwse.
 */
public static void setCanAutoSmelt(ItemStack stack, boolean canAutoSmelt) {
	fixNBT(stack);

	stack.stackTagCompound.setBoolean("AutoSmelt", canAutoSmelt);

	LogHelper.logInfo("[CrewHammer#setCanAutoSmelt] Method ran successfully! Auto Smelt is now: " + stack.stackTagCompound.getBoolean("AutoSmelt"));
}

/**
 * Used for setting the mining size of the Crew Hammer in seperate classes.
 * 
 * @param stack The Hammer.
 * @param canAutoRepair True if stack has the Auto Repair mod. False otherwise.
 */
public static void setCanAutoRepair(ItemStack stack, boolean canAutoRepair) {
	fixNBT(stack);

	stack.stackTagCompound.setBoolean("AutoRepair", canAutoRepair);

	LogHelper.logInfo("[CrewHammer#setCanAutoRepair] Method ran successfully! Auto Repair is now: " + stack.stackTagCompound.getBoolean("AutoRepair"));
}

public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
	fixNBT(stack);

	EntityPlayer player = (EntityPlayer)entity;

	//LogHelper.logInfo("CALLED");

	LogHelper.logInfo("STACK: " + stack);
	LogHelper.logInfo("TAG: " + stack.getTagCompound());

	if(world != null && player != null) {
		LogHelper.logInfo("WORLD WAS NOT NULL NOR WAS PLAYER");

		MovingObjectPosition mop = EntityHelper.raytraceFromEntity(world, player, true, 5.0D);

		int sideHit = mop.sideHit;

		if(player.inventory.getCurrentItem() != null) {
			if(player.inventory.getCurrentItem().getItem().equals(CrewMod.crewHammer)) {
				int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

				//ItemStack hammer = stack;

				//System.out.println("ITEM IN HAND IS CREW HAMMER");

				//Block block = event.block;

				//World world = event.world;

				//int x = event.x;
				//int y = event.y;
				//int z = event.z;

				//CrewHammer.fixNBT(hammer);

				//NBTTagCompound cmp = hammer.stackTagCompound;

				//if(event.isCanceled())
					//return;

				String miningArea = null;

				if(stack.hasTagCompound()) {
					miningArea = stack.getTagCompound().getString("MiningSize");

					//System.out.println("CMP WAS NOT NULL");
				}

				LogHelper.logInfo(miningArea);

				this.breakBlock(world, player, stack, x, y, z, direction, miningArea, sideHit);
			}else {
				super.onBlockDestroyed(stack, world, block, x, y, z, entity);
			}
		}else {
			super.onBlockDestroyed(stack, world, block, x, y, z, entity);
		}
	}

	return true;
}

/**
 * Used for breaking an area of blocks depending on the miningSize.
 * 
 * @param world Instance of the Minecraft world.
 * @param player Player breaking the block.
 * @param stack Stack in the player's hand.
 * @param x X coordinate of the block to be broken.
 * @param y	Y coordinate of the block to be broken.
 * @param z	Z coordinate of the block to be broken.
 * @param playerFacing The direction the player is facing: NORTH, SOUTH, EAST or, WEST.
 * @param miningArea The area of blocks to be destroyed: 1x1 = 0, 3x3 = 1, 5x5 = 2, 7x7 = 3.
 */
public void breakBlock(World world, EntityPlayer player, ItemStack stack, int x, int y, int z, int playerFacing, String miningArea, int sideHit) { //TODO Address Shift-Clicking error with onCrafted.
	System.out.println("BREAK BLOCK RUN");

	Block block = world.getBlock(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);

	/*MovingObjectPosition mop = player.rayTrace(5.0D, 1.0F);

	if(mop == null) {
		LogHelper.logErr("[CrewHammer] " + "Ray Trace has failed!");
		return;
	}*/

	//int sideHit = -1;

	//if(world.isRemote)
	//	sideHit = mop.sideHit;
	//else
	//	return;

	LogHelper.logInfo("[CrewHammer] Side Hit: " + sideHit);

	int refX = x;
	int refY = y;
	int refZ = z;

	if(!isEffective(block, meta, stack))
		return;

	int miningSize = 0;

	if(miningArea != null) {
		if(miningArea.equals("3x3"))
			miningSize = 1;
		else if(miningArea == "5x5")
			miningSize = 2;
		else if(miningArea == "7x7")
			miningSize = 3;
		else
			miningSize = 0;
	}else {
		LogHelper.logErr("[CrewHammer] The Mining Area was null!");
	}

	System.out.println(miningArea);
	System.out.println(miningSize);

	if(playerFacing == 0 || playerFacing == 2) {
		//System.out.println("PLAYER FACING 0 or 2");

		if(miningSize == 0) {
			return;
		}else if(miningSize == 1) {
			System.out.println("MINING IS 3x3");

			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
		}else if(miningSize == 2) {
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
		}else {
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 3, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 3, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 3, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 3, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x - 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 3, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 3, y, z, true, refX, refY, refZ, sideHit, 0, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 3, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 3, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 3, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 3, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x - 1, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 3, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 3, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x - 1, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 1, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 2, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 2, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x - 3, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x + 3, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
		}
	}else {
		//System.out.println("PLAYER FACING 1 or 3");

		if(miningSize == 0) {
			return;
		}else if(miningSize == 1) {
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z - 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z + 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
		}else if(miningSize == 2) {
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z - 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z + 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z - 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z + 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
		}else {
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z - 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 1, z + 3, true, refX, refY, refZ, sideHit, 1, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z - 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 1, z + 3, true, refX, refY, refZ, sideHit, 2, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x, y, z - 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z + 1, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z - 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z + 2, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z - 3, true, refX, refY, refZ, sideHit, 0, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y, z + 3, true, refX, refY, refZ, sideHit, 0, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z - 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z + 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 2, z, true, refX, refY, refZ, sideHit, 1, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z - 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z + 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 2, z, true, refX, refY, refZ, sideHit, 2, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z - 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z + 1, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z - 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z + 2, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z - 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z + 3, true, refX, refY, refZ, sideHit, 1, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y + 3, z, true, refX, refY, refZ, sideHit, 1, playerFacing);

			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z - 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z + 1, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z - 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z + 2, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z - 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z + 3, true, refX, refY, refZ, sideHit, 2, playerFacing);
			this.destroyBlockIfAllowed(world, stack, player, x, y - 3, z, true, refX, refY, refZ, sideHit, 2, playerFacing);
		}
	}
}

/**
 * Destroys a block at the given coords if allowed.
 * 
 * @param world The instance of the World.
 * @param player The player destroying said block.
 * @param x X Coordinate of the block to be destroyed.
 * @param y Y Coordinate of the block to be destroyed.
 * @param z Z Coordinate of the block to be destroyed.
 * @param addDrops If true, adds drops to the block broken.
 * @param refX Reference point X of the center block if destroying multiple ones.
 * @param refY Reference point Y of the center block if destroying multiple ones.
 * @param refZ Reference point Z of the center block if destroying multiple ones.
 * @param Ymodifer Used to determine if the Y variable is added to or, subtracted from. 0 = Nothing, 1 = Added to, 2 = Subtracted from.
 * @param playerDirection The direction the player is facing: NORTH, SOUTH, EAST or, WEST.
 */
public void destroyBlockIfAllowed(World world, ItemStack stack, EntityPlayer player, int x, int y, int z, boolean addDrops, int refX, int refY, int refZ, int sideHit, int Ymodifer, int playerDirection) {
	int actualX = x;
	int actualY = y;
	int actualZ = z;

	if(sideHit == 0 || sideHit == 1) {
		//System.out.println("Z updated");

		actualY = refY;

		int amountToAdd = refY > y ? refY - y : y - refY;

		if(playerDirection == 0 || playerDirection == 2) {
			if(Ymodifer == 0)
				actualZ += 0;
			else if(Ymodifer == 1)
				actualZ += amountToAdd;
			else
				actualZ -= amountToAdd;
		}else {
			if(Ymodifer == 0)
				actualX += 0;
			else if(Ymodifer == 1)
				actualX += amountToAdd;
			else
				actualX -= amountToAdd;
		}

		/*System.out.println("Z: " + actualZ);
		System.out.println(additionZ);
		System.out.println("Y: " + y);
		System.out.println("refY: " + refY);*/
	}

	if(world.isAirBlock(actualX, actualY, actualZ))
		return;

	Block block = world.getBlock(actualX, actualY, actualZ);
	int meta = world.getBlockMetadata(actualX, actualY, actualZ);

	if(!isEffective(block, meta, stack))
		return;

	Block refBlock = world.getBlock(refX, refY, refZ);
        
        float refStrength = refBlock.getBlockHardness(world, refX, refY, refZ);
        float strength = block.getBlockHardness(world, actualX, actualY, actualZ);
        
        float strDifference = strength/refStrength;
        
        System.out.println(strDifference);

	if(!ForgeHooks.canHarvestBlock(block, player, meta) || strength <= -1 || strDifference > 10)
		return;

	EntityPlayerMP playerEntity = (EntityPlayerMP)player;

	if(block.getExpDrop(world, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)) > 0 && !stack.stackTagCompound.getBoolean("AutoSmelt"))
		block.dropXpOnBlockBreak(world, actualX, actualY, actualZ, block.getExpDrop(world, meta, 0));


	if(stack.stackTagCompound.getBoolean("AutoSmelt") == true) {

		//LogHelper.logInfo("Drops: " + drops);

		if(FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(block)) != null) {
					block.getDrops(world, actualX, actualY, actualZ, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)).add(stackToDrop1);

			//drops.clear();

			//drops.add(stackToDrop1);

			LogHelper.logInfo("Drops: " + block.getDrops(world, actualX, actualY, actualZ, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)));
		}
	}

	world.func_147480_a(actualX, actualY, actualZ, addDrops);

	int damage = stack.getItemDamage() + 1;

	if(!player.capabilities.isCreativeMode)
		stack.setItemDamage(damage);
}

public boolean isEffective(Block block, int meta, ItemStack stack) {
	if(ForgeHooks.canToolHarvestBlock(block, meta, stack))
		return true;

	return false; 
	block.getDrops(world, actualX, actualY, actualZ, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)).clear();

			ItemStack stackToDrop = FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(block, 1, meta)).copy();

			ItemStack stackToDrop1 = new ItemStack(stackToDrop.getItem(), 1);

}

/*//Makes it so the item stays in the crafting grid
    public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack) {
        return false;
    }
    
    //Tells the game your item has a container item
    public boolean hasContainerItem() {
    	return true;
    }
    
    //Sets teh container item
    public ItemStack getContainerItem(ItemStack itemStack) {
    	itemStack.attemptDamageItem(1, itemRand);
    	
    	return itemStack;
    }*/
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Use Block#harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) to drop the block drops.

Remind that Block#getDrops(...) just gets the new instance of the drops.

Using the Block#harvestBlock(...), you can use BlockEvent.HarvestDropsEvent to check and smelt the drops.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

I actually fixed this. :P I created a new ItemStack ArrayList in my breakBlock method and copied over a spawning method from Block.java. After that, because I use World#func_147480_a to destroy the block (which has a boolean to enable drops or not); I simply cancel the drops and spawn the items. :P Kinda confusing though so, here's my code. :P

 

public void destroyBlockIfAllowed(World world, ItemStack stack, EntityPlayer player, int x, int y, int z, boolean addDrops, int refX, int refY, int refZ, int sideHit, int Ymodifer, int playerDirection) {
	int actualX = x;
	int actualY = y;
	int actualZ = z;

	if(sideHit == 0 || sideHit == 1) {
		//System.out.println("Z updated");

		actualY = refY;

		int amountToAdd = refY > y ? refY - y : y - refY;

		if(playerDirection == 0 || playerDirection == 2) {
			if(Ymodifer == 0)
				actualZ += 0;
			else if(Ymodifer == 1)
				actualZ += amountToAdd;
			else
				actualZ -= amountToAdd;
		}else {
			if(Ymodifer == 0)
				actualX += 0;
			else if(Ymodifer == 1)
				actualX += amountToAdd;
			else
				actualX -= amountToAdd;
		}
	}

	if(world.isAirBlock(actualX, actualY, actualZ))
		return;

	Block block = world.getBlock(actualX, actualY, actualZ);
	int meta = world.getBlockMetadata(actualX, actualY, actualZ);

	if(!isEffective(block, meta, stack))
		return;

	Block refBlock = world.getBlock(refX, refY, refZ);
        
        float refStrength = refBlock.getBlockHardness(world, refX, refY, refZ);
        float strength = block.getBlockHardness(world, actualX, actualY, actualZ);
        
        float strDifference = strength/refStrength;
        
        System.out.println(strDifference);

	if(!ForgeHooks.canHarvestBlock(block, player, meta) || strength <= -1 || strDifference > 10)
		return;

	EntityPlayerMP playerEntity = (EntityPlayerMP)player;

	if(block.getExpDrop(world, meta, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack)) > 0 && !stack.stackTagCompound.getBoolean("AutoSmelt"))
		block.dropXpOnBlockBreak(world, actualX, actualY, actualZ, block.getExpDrop(world, meta, 0));


	if(stack.stackTagCompound.getBoolean("AutoSmelt") == true) {
		ArrayList<ItemStack> drops = getFurnaceDrops(world, actualX, actualY, actualZ, 0, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack), 1, block, meta, player);

		LogHelper.logInfo("Drops: " + drops);

		for(ItemStack item : drops) {
			dropCustomItems(world, actualX, actualY, actualZ, item);
		}
	}

	world.func_147480_a(actualX, actualY, actualZ, stack.stackTagCompound.getBoolean("AutoSmelt") ? false : addDrops);

	if(!player.capabilities.isCreativeMode)
		stack.attemptDamageItem(1, world.rand);
}

public boolean isEffective(Block block, int meta, ItemStack stack) {
	if(ForgeHooks.canToolHarvestBlock(block, meta, stack))
		return true;

	return false;		
}

/**
     * Spawns EntityItem in the world for the given ItemStack if the world is not remote.
     */
    protected void dropCustomItems(World world, int x, int y, int z, ItemStack stack) {
        if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops") && !world.restoringBlockSnapshots) { // do not drop items while restoring blockstates, prevents item dupe
            float f = 0.7F;
            
            double d0 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
            double d1 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
            double d2 = (double)(world.rand.nextFloat() * f) + (double)(1.0F - f) * 0.5D;
            
            EntityItem entityitem = new EntityItem(world, (double)x + d0, (double)y + d1, (double)z + d2, stack);
            
            entityitem.delayBeforeCanPickup = 10;
            
            world.spawnEntityInWorld(entityitem);
        }
    }
    
    /**
     * This returns a complete list of items dropped from this block.
     *
     * @param world The current world
     * @param x X Position
     * @param y Y Position
     * @param z Z Position
     * @param metadata Current metadata
     * @param fortune Breakers fortune level
     * @return A ArrayList containing all items this block drops
     */
    public ArrayList<ItemStack> getFurnaceDrops(World world, int x, int y, int z, int meta, int fortune, int quantity, Block block, int blockMeta, EntityPlayer player) {
        ArrayList<ItemStack> ret = new ArrayList<ItemStack>();

        int count = quantity;
        
        for(int i = 0; i < count; i++) {
            if(FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(block, 1, blockMeta)) != null) {
            	
            	int itemMeta = FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(block, 1, blockMeta)).getItemDamage();
            	
            	float xpToDrop = FurnaceRecipes.smelting().func_151398_b(new ItemStack(block, 1, blockMeta));
            	
            	LogHelper.logInfo("XP: " + xpToDrop);
            
            Item item = FurnaceRecipes.smelting().getSmeltingResult(new ItemStack(block, 1, blockMeta)).getItem();
            
            LogHelper.logInfo("Item Meta: " + itemMeta);
            
            if (item != null) {
                ret.add(new ItemStack(item, 1, itemMeta));
            }
            }else {
            	if(block.canSilkHarvest(world, player, x, y, z, meta))
            		ret.add(new ItemStack(block, 1, meta));
            	else
            		ret.add(new ItemStack(block.getItemDropped(blockMeta, world.rand, fortune)));
            }
        }
        
        return ret;
    }

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

You should remind that the code would be incompatible with many mods.

(edit) Many mods uses Block#getDrops(...) and HarvestDropsEvent to modify the drops,

but your code just smelts the block and drop it. Do you want your tool to be silk touch with auto-smelting?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Read the 'edit'.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Ok, the method above is called when the block is destroyed by my item. (I basically have an onBlockDestroyed method that is not showed that calls the method destroyBlockIfAllowed) I also use World#func_147480_a() which destroys the block (adds sounds and such) along with telling the game to drop it's items or not. When the block is destroyed with the CrewHammer, it then destroys the blocks around the block destroyed (calling the method I stated above) and then does all of it's shit. xD It shouldn't affect any blocks unless the player is holding my hammer. So, it shouldn't affect other mods.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

So what do you want is silk touch+auto smelting?

But still, there are many problems. You are not dropping anything if the hammer does not have Auto-Smelting trait.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

I check the NBT tag of the stack before editing the drops. The silk touch is there for now because I want stone to drop stone considering it's drop can be smelted into stone. I will be editing it to ignore some blocks. :P It doesn't work on blocks that can not be harvested by a pickaxe.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

I check the NBT tag of the stack before editing the drops. The silk touch is there for now because I want stone to drop stone considering it's drop can be smelted into stone. I will be editing it to ignore some blocks. :P It doesn't work on blocks that can not be harvested by a pickaxe.

That's the problem that I exactly wanted to say. Your logic breaks there.

And, with the code, breaking lapis lazuli would give you the lapis lazuli block. Is that what you want?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Oh no. :P Lapis has a smelting recipe so it would not fall under the else statement. But, I do understand I need to add the fortune effect and such to make the blocks work right. :P Still a bit of testing going on. xD

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Oh no. :P Lapis has a smelting recipe so it would not fall under the else statement. But, I do understand I need to add the fortune effect and such to make the blocks work right. :P Still a bit of testing going on. xD

That's not only the problem. There are tons of blocks added by mods works like lapis.

Also, some of them uses HarvestDropsEvent, so you should fix lots of the logic.

  (As you want it to have fortune effects, etc.)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Don't worry, I will. I plan to use the QuantityDropped variable and, if it is greater than one; basically don't "smelt" it. :P Fortune I will just figure out how Minecraft does it and go from there. Thank you for your concern though considering a lot of people tend not to point out potential incompatibilities like that. :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

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