This commit is contained in:
Boblet 2022-01-18 16:54:45 +01:00
parent 9cc9c4d451
commit b68f9395e8
3 changed files with 203 additions and 276 deletions

View File

@ -1,9 +1,88 @@
package com.hbm.items.tool; package com.hbm.items.tool;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.event.world.BlockEvent;
public interface IItemAbility { public interface IItemAbility {
public void breakExtraBlock(World world, int x, int y, int z, EntityPlayer player, int refX, int refY, int refZ); public boolean canHarvestBlock(Block par1Block, ItemStack itemStack);
public default void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) {
if(world.isAirBlock(x, y, z))
return;
if(!(playerEntity instanceof EntityPlayerMP))
return;
EntityPlayerMP player = (EntityPlayerMP) playerEntity;
ItemStack stack = player.getHeldItem();
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(!canHarvestBlock(block, stack))
return;
Block refBlock = world.getBlock(refX, refY, refZ);
float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ);
float strength = ForgeHooks.blockStrength(block, player, world, x, y, z);
if(!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength / strength > 10f || block.getBlockHardness(world, x, y, z) < 0)
return;
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z);
if(event.isCanceled())
return;
if(player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, x, y, z, meta, player);
if(block.removedByPlayer(world, player, x, y, z, false))
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
if(!world.isRemote) {
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
}
return;
}
player.getCurrentEquippedItem().func_150999_a(world, block, x, y, z, player);
if(!world.isRemote) {
block.onBlockHarvested(world, x, y, z, meta, player);
if(block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
block.harvestBlock(world, player, x, y, z, meta);
block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop());
}
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
if(block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
}
ItemStack itemstack = player.getCurrentEquippedItem();
if(itemstack != null) {
itemstack.func_150999_a(world, block, x, y, z, player);
if(itemstack.stackSize == 0) {
player.destroyCurrentEquippedItem();
}
}
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
}
} }

View File

@ -83,77 +83,6 @@ public class ItemSwordAbility extends ItemSword implements IItemAbility {
return multimap; return multimap;
} }
public void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) {
if(world.isAirBlock(x, y, z))
return;
if(!(playerEntity instanceof EntityPlayerMP))
return;
EntityPlayerMP player = (EntityPlayerMP) playerEntity;
ItemStack stack = player.getHeldItem();
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(!canHarvestBlock(block, stack))
return;
Block refBlock = world.getBlock(refX, refY, refZ);
float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ);
float strength = ForgeHooks.blockStrength(block, player, world, x, y, z);
if(!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength / strength > 10f)
return;
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z);
if(event.isCanceled())
return;
if(player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, x, y, z, meta, player);
if(block.removedByPlayer(world, player, x, y, z, false))
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
if(!world.isRemote) {
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
}
return;
}
player.getCurrentEquippedItem().func_150999_a(world, block, x, y, z, player);
if(!world.isRemote) {
block.onBlockHarvested(world, x, y, z, meta, player);
if(block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
block.harvestBlock(world, player, x, y, z, meta);
block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop());
}
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
if(block.removedByPlayer(world, player, x, y, z, true)) {
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
}
ItemStack itemstack = player.getCurrentEquippedItem();
if(itemstack != null) {
itemstack.func_150999_a(world, block, x, y, z, player);
if(itemstack.stackSize == 0) {
player.destroyCurrentEquippedItem();
}
}
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {

View File

@ -97,7 +97,7 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
return this; return this;
} }
//<insert obvious Rarity joke here> // <insert obvious Rarity joke here>
public ItemToolAbility setRarity(EnumRarity rarity) { public ItemToolAbility setRarity(EnumRarity rarity) {
this.rarity = rarity; this.rarity = rarity;
return this; return this;
@ -152,7 +152,8 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
@Override @Override
public boolean canHarvestBlock(Block block, ItemStack stack) { public boolean canHarvestBlock(Block block, ItemStack stack) {
if(!canOperate(stack)) return false; if(!canOperate(stack))
return false;
if(this.getCurrentAbility(stack) instanceof SilkAbility) if(this.getCurrentAbility(stack) instanceof SilkAbility)
return true; return true;
@ -164,90 +165,14 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
public Multimap getItemAttributeModifiers() { public Multimap getItemAttributeModifiers() {
Multimap multimap = HashMultimap.create(); Multimap multimap = HashMultimap.create();
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double)this.damage, 0)); multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double) this.damage, 0));
multimap.put(SharedMonsterAttributes.movementSpeed.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", movement, 1)); multimap.put(SharedMonsterAttributes.movementSpeed.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", movement, 1));
return multimap; return multimap;
} }
public void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) {
if (world.isAirBlock(x, y, z))
return;
if(!(playerEntity instanceof EntityPlayerMP))
return;
EntityPlayerMP player = (EntityPlayerMP) playerEntity;
ItemStack stack = player.getHeldItem();
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if(!canHarvestBlock(block, stack))
return;
Block refBlock = world.getBlock(refX, refY, refZ);
float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ);
float strength = ForgeHooks.blockStrength(block, player, world, x,y,z);
if (!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength/strength > 10f)
return;
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x,y,z);
if(event.isCanceled())
return;
if (player.capabilities.isCreativeMode) {
block.onBlockHarvested(world, x, y, z, meta, player);
if (block.removedByPlayer(world, player, x, y, z, false))
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
if (!world.isRemote) {
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
}
return;
}
player.getCurrentEquippedItem().func_150999_a(world, block, x, y, z, player);
if (!world.isRemote) {
block.onBlockHarvested(world, x,y,z, meta, player);
if(block.removedByPlayer(world, player, x,y,z, true))
{
block.onBlockDestroyedByPlayer( world, x,y,z, meta);
block.harvestBlock(world, player, x,y,z, meta);
block.dropXpOnBlockBreak(world, x,y,z, event.getExpToDrop());
}
player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world));
} else {
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
if(block.removedByPlayer(world, player, x,y,z, true))
{
block.onBlockDestroyedByPlayer(world, x,y,z, meta);
}
ItemStack itemstack = player.getCurrentEquippedItem();
if (itemstack != null)
{
itemstack.func_150999_a(world, block, x, y, z, player);
if (itemstack.stackSize == 0)
{
player.destroyCurrentEquippedItem();
}
}
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack) { public boolean hasEffect(ItemStack stack) {
return getCurrentAbility(stack) != null || stack.isItemEnchanted();
return getCurrentAbility(stack) != null ? true : super.hasEffect(stack);
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@ -301,22 +226,16 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc
while(getCurrentAbility(stack) != null && !getCurrentAbility(stack).isAllowed()) { while(getCurrentAbility(stack) != null && !getCurrentAbility(stack).isAllowed()) {
player.addChatComponentMessage( player.addChatComponentMessage(new ChatComponentText("[Ability ").appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0]))
new ChatComponentText("[Ability ") .appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + " is blacklisted!]")).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
.appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0]))
.appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + " is blacklisted!]"))
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
i++; i++;
setAbility(stack, i % this.breakAbility.size()); setAbility(stack, i % this.breakAbility.size());
} }
if(getCurrentAbility(stack) != null) { if(getCurrentAbility(stack) != null) {
player.addChatComponentMessage( player.addChatComponentMessage(new ChatComponentText("[Enabled ").appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0]))
new ChatComponentText("[Enabled ") .appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + "]")).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW)));
.appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0]))
.appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + "]"))
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW)));
} else { } else {
player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GOLD + "[Tool ability deactivated]")); player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GOLD + "[Tool ability deactivated]"));
} }