mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-20 04:09:40 +00:00
Fix JABBA-related issues with crafting station slots (#54)
* Fix shift-merging tools voiding items fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11392> * Change 0-sized ItemStacks into null stacks in crafting station attached slots Fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/10425> * Update buildscript * spotlessApply
This commit is contained in:
1 parent
18bfeaff32
commit
39be06c23b
571 files changed
+25959
-28223
No files matched your search
@@ -1,177 +1,150 @@
|
||||
package tconstruct.library.tools;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.material.MaterialLogic;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.client.C07PacketPlayerDigging;
|
||||
import net.minecraft.network.play.server.S23PacketBlockChange;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import tconstruct.tools.TinkerTools;
|
||||
import tconstruct.util.config.PHConstruct;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/* Base class for tools that should be harvesting blocks */
|
||||
|
||||
public abstract class HarvestTool extends ToolCore
|
||||
{
|
||||
public HarvestTool(int baseDamage)
|
||||
{
|
||||
public abstract class HarvestTool extends ToolCore {
|
||||
public HarvestTool(int baseDamage) {
|
||||
super(baseDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
|
||||
{
|
||||
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
|
||||
return super.onBlockStartBreak(stack, x, y, z, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHarvestLevel(ItemStack stack, String toolClass) {
|
||||
// well, we can only get the harvestlevel if we have an item to get it from!
|
||||
if(stack == null || !(stack.getItem() instanceof HarvestTool))
|
||||
return -1;
|
||||
if (stack == null || !(stack.getItem() instanceof HarvestTool)) return -1;
|
||||
// invalid query or wrong toolclass
|
||||
if(toolClass == null || !this.getHarvestType().equals(toolClass))
|
||||
return -1;
|
||||
if (toolClass == null || !this.getHarvestType().equals(toolClass)) return -1;
|
||||
|
||||
if(!stack.hasTagCompound())
|
||||
return -1;
|
||||
if (!stack.hasTagCompound()) return -1;
|
||||
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
// broken tools suck.
|
||||
if (tags.getBoolean("Broken"))
|
||||
return 0;
|
||||
if (tags.getBoolean("Broken")) return 0;
|
||||
|
||||
// tadaaaa
|
||||
return tags.getInteger("HarvestLevel");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getDigSpeed (ItemStack stack, Block block, int meta)
|
||||
{
|
||||
if (!stack.hasTagCompound())
|
||||
return 1.0f;
|
||||
public float getDigSpeed(ItemStack stack, Block block, int meta) {
|
||||
if (!stack.hasTagCompound()) return 1.0f;
|
||||
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
if (tags.getBoolean("Broken"))
|
||||
return 0.1f;
|
||||
if (tags.getBoolean("Broken")) return 0.1f;
|
||||
|
||||
if(isEffective(block, meta))
|
||||
return calculateStrength(tags, block, meta);
|
||||
if (isEffective(block, meta)) return calculateStrength(tags, block, meta);
|
||||
|
||||
return super.getDigSpeed(stack, block, meta);
|
||||
}
|
||||
|
||||
public float calculateStrength (NBTTagCompound tags, Block block, int meta)
|
||||
{
|
||||
public float calculateStrength(NBTTagCompound tags, Block block, int meta) {
|
||||
|
||||
int hlvl = block.getHarvestLevel(meta);
|
||||
if (hlvl > tags.getInteger("HarvestLevel"))
|
||||
return 0.1f;
|
||||
if (hlvl > tags.getInteger("HarvestLevel")) return 0.1f;
|
||||
|
||||
return AbilityHelper.calcToolSpeed(this, tags);
|
||||
}
|
||||
|
||||
public float breakSpeedModifier ()
|
||||
{
|
||||
public float breakSpeedModifier() {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
public float stoneboundModifier ()
|
||||
{
|
||||
public float stoneboundModifier() {
|
||||
return 72f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean func_150897_b (Block block)
|
||||
{
|
||||
public boolean func_150897_b(Block block) {
|
||||
return isEffective(block.getMaterial());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getTraits ()
|
||||
{
|
||||
return new String[] { "harvest" };
|
||||
public String[] getTraits() {
|
||||
return new String[] {"harvest"};
|
||||
}
|
||||
|
||||
protected abstract Material[] getEffectiveMaterials ();
|
||||
protected abstract Material[] getEffectiveMaterials();
|
||||
|
||||
protected abstract String getHarvestType ();
|
||||
protected abstract String getHarvestType();
|
||||
|
||||
@Override
|
||||
public Set<String> getToolClasses(ItemStack stack) {
|
||||
Set<String> set = new HashSet<String>();
|
||||
|
||||
if(stack != null && stack.getItem() instanceof HarvestTool) {
|
||||
if (stack != null && stack.getItem() instanceof HarvestTool) {
|
||||
set.add(((HarvestTool) stack.getItem()).getHarvestType());
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
public boolean isEffective (Block block, int meta)
|
||||
{
|
||||
if(this.getHarvestType().equals(block.getHarvestTool(meta)))
|
||||
return true;
|
||||
|
||||
public boolean isEffective(Block block, int meta) {
|
||||
if (this.getHarvestType().equals(block.getHarvestTool(meta))) return true;
|
||||
else return isEffective(block.getMaterial());
|
||||
}
|
||||
|
||||
public boolean isEffective (Material material)
|
||||
{
|
||||
for (Material m : getEffectiveMaterials())
|
||||
if (m == material)
|
||||
return true;
|
||||
public boolean isEffective(Material material) {
|
||||
for (Material m : getEffectiveMaterials()) if (m == material) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Right-click
|
||||
// Right-click
|
||||
@Override
|
||||
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float clickX, float clickY, float clickZ)
|
||||
{
|
||||
public boolean onItemUse(
|
||||
ItemStack stack,
|
||||
EntityPlayer player,
|
||||
World world,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
int side,
|
||||
float clickX,
|
||||
float clickY,
|
||||
float clickZ) {
|
||||
/*if (world.isRemote)
|
||||
return true;*/
|
||||
return true;*/
|
||||
|
||||
boolean used = false;
|
||||
int hotbarSlot = player.inventory.currentItem;
|
||||
int itemSlot = hotbarSlot == 0 ? 8 : hotbarSlot + 1;
|
||||
ItemStack nearbyStack = null;
|
||||
|
||||
if (hotbarSlot < 8)
|
||||
{
|
||||
if (hotbarSlot < 8) {
|
||||
nearbyStack = player.inventory.getStackInSlot(itemSlot);
|
||||
if (nearbyStack != null)
|
||||
{
|
||||
if (nearbyStack != null) {
|
||||
Item item = nearbyStack.getItem();
|
||||
|
||||
if (item instanceof ItemBlock || (item != null && item == TinkerTools.openBlocksDevNull))
|
||||
{
|
||||
|
||||
if (item instanceof ItemBlock || (item != null && item == TinkerTools.openBlocksDevNull)) {
|
||||
int posX = x;
|
||||
int posY = y;
|
||||
int posZ = z;
|
||||
|
||||
switch (side)
|
||||
{
|
||||
switch (side) {
|
||||
case 0:
|
||||
--posY;
|
||||
break;
|
||||
@@ -192,40 +165,34 @@ public abstract class HarvestTool extends ToolCore
|
||||
break;
|
||||
}
|
||||
|
||||
AxisAlignedBB blockBounds = AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1);
|
||||
AxisAlignedBB blockBounds =
|
||||
AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX + 1, posY + 1, posZ + 1);
|
||||
AxisAlignedBB playerBounds = player.boundingBox;
|
||||
|
||||
if(item instanceof ItemBlock)
|
||||
{
|
||||
if (item instanceof ItemBlock) {
|
||||
Block blockToPlace = ((ItemBlock) item).field_150939_a;
|
||||
if(blockToPlace.getMaterial().blocksMovement())
|
||||
{
|
||||
if (playerBounds.intersectsWith(blockBounds))
|
||||
return false;
|
||||
if (blockToPlace.getMaterial().blocksMovement()) {
|
||||
if (playerBounds.intersectsWith(blockBounds)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
int dmg = nearbyStack.getItemDamage();
|
||||
int count = nearbyStack.stackSize;
|
||||
if (item == TinkerTools.openBlocksDevNull)
|
||||
{
|
||||
//Openblocks uses current inventory slot, so we have to do this...
|
||||
player.inventory.currentItem=itemSlot;
|
||||
item.onItemUse(nearbyStack, player, world, x, y, z, side, clickX, clickY, clickZ);
|
||||
player.inventory.currentItem=hotbarSlot;
|
||||
player.swingItem();
|
||||
}
|
||||
else
|
||||
used = item.onItemUse(nearbyStack, player, world, x, y, z, side, clickX, clickY, clickZ);
|
||||
if (item == TinkerTools.openBlocksDevNull) {
|
||||
// Openblocks uses current inventory slot, so we have to do this...
|
||||
player.inventory.currentItem = itemSlot;
|
||||
item.onItemUse(nearbyStack, player, world, x, y, z, side, clickX, clickY, clickZ);
|
||||
player.inventory.currentItem = hotbarSlot;
|
||||
player.swingItem();
|
||||
} else used = item.onItemUse(nearbyStack, player, world, x, y, z, side, clickX, clickY, clickZ);
|
||||
|
||||
// handle creative mode
|
||||
if(player.capabilities.isCreativeMode) {
|
||||
if (player.capabilities.isCreativeMode) {
|
||||
// fun fact: vanilla minecraft does it exactly the same way
|
||||
nearbyStack.setItemDamage(dmg);
|
||||
nearbyStack.stackSize = count;
|
||||
}
|
||||
if (nearbyStack.stackSize < 1)
|
||||
{
|
||||
if (nearbyStack.stackSize < 1) {
|
||||
nearbyStack = null;
|
||||
player.inventory.setInventorySlotContents(itemSlot, null);
|
||||
}
|
||||
@@ -234,24 +201,23 @@ public abstract class HarvestTool extends ToolCore
|
||||
}
|
||||
|
||||
/*
|
||||
if (used) //Update client
|
||||
{
|
||||
Packet103SetSlot packet = new Packet103SetSlot(player.openContainer.windowId, itemSlot, nearbyStack);
|
||||
((EntityPlayerMP)player).playerNetServerHandler.sendPacketToPlayer(packet);
|
||||
}
|
||||
*/
|
||||
if (used) //Update client
|
||||
{
|
||||
Packet103SetSlot packet = new Packet103SetSlot(player.openContainer.windowId, itemSlot, nearbyStack);
|
||||
((EntityPlayerMP)player).playerNetServerHandler.sendPacketToPlayer(packet);
|
||||
}
|
||||
*/
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
public void breakExtraBlock(World world, int x, int y, int z, int sidehit, EntityPlayer playerEntity, int refX, int refY, int refZ) {
|
||||
public void breakExtraBlock(
|
||||
World world, int x, int y, int z, int sidehit, EntityPlayer playerEntity, int refX, int refY, int refZ) {
|
||||
// prevent calling that stuff for air blocks, could lead to unexpected behaviour since it fires events
|
||||
if (world.isAirBlock(x, y, z))
|
||||
return;
|
||||
if (world.isAirBlock(x, y, z)) return;
|
||||
|
||||
// what?
|
||||
if(!(playerEntity instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!(playerEntity instanceof EntityPlayerMP)) return;
|
||||
EntityPlayerMP player = (EntityPlayerMP) playerEntity;
|
||||
|
||||
// check if the block can be broken, since extra block breaks shouldn't instantly break stuff like obsidian
|
||||
@@ -260,21 +226,19 @@ public abstract class HarvestTool extends ToolCore
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
// only effective materials
|
||||
if (!isEffective(block, meta))
|
||||
return;
|
||||
if (!isEffective(block, meta)) 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);
|
||||
float strength = ForgeHooks.blockStrength(block, player, world, x, y, z);
|
||||
|
||||
// only harvestable blocks that aren't impossibly slow to harvest
|
||||
if (!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength/strength > 10f)
|
||||
return;
|
||||
if (!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength / strength > 10f) return;
|
||||
|
||||
// send the blockbreak event
|
||||
BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x,y,z);
|
||||
if(event.isCanceled())
|
||||
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);
|
||||
@@ -290,7 +254,7 @@ public abstract class HarvestTool extends ToolCore
|
||||
|
||||
// callback to the tool the player uses. Called on both sides. This damages the tool n stuff.
|
||||
ItemStack currentItem = player.getCurrentEquippedItem();
|
||||
if(currentItem != null) {
|
||||
if (currentItem != null) {
|
||||
currentItem.func_150999_a(world, block, x, y, z, player);
|
||||
}
|
||||
|
||||
@@ -299,13 +263,14 @@ public abstract class HarvestTool extends ToolCore
|
||||
// serverside we reproduce ItemInWorldManager.tryHarvestBlock
|
||||
|
||||
// ItemInWorldManager.removeBlock
|
||||
block.onBlockHarvested(world, x,y,z, meta, player);
|
||||
block.onBlockHarvested(world, x, y, z, meta, player);
|
||||
|
||||
if(block.removedByPlayer(world, player, x,y,z, true)) // boolean is if block can be harvested, checked above
|
||||
if (block.removedByPlayer(
|
||||
world, player, x, y, z, true)) // boolean is if block can be harvested, checked above
|
||||
{
|
||||
block.onBlockDestroyedByPlayer( world, x,y,z, meta);
|
||||
block.harvestBlock(world, player, x,y,z, meta);
|
||||
block.dropXpOnBlockBreak(world, x,y,z, event.getExpToDrop());
|
||||
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
|
||||
block.harvestBlock(world, player, x, y, z, meta);
|
||||
block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop());
|
||||
}
|
||||
|
||||
// always send block update to client
|
||||
@@ -313,31 +278,33 @@ public abstract class HarvestTool extends ToolCore
|
||||
}
|
||||
// client sided handling
|
||||
else {
|
||||
//PlayerControllerMP pcmp = Minecraft.getMinecraft().playerController;
|
||||
// clientside we do a "this clock has been clicked on long enough to be broken" call. This should not send any new packets
|
||||
// the code above, executed on the server, sends a block-updates that give us the correct state of the block we destroy.
|
||||
// PlayerControllerMP pcmp = Minecraft.getMinecraft().playerController;
|
||||
// clientside we do a "this clock has been clicked on long enough to be broken" call. This should not send
|
||||
// any new packets
|
||||
// the code above, executed on the server, sends a block-updates that give us the correct state of the block
|
||||
// we destroy.
|
||||
|
||||
// following code can be found in PlayerControllerMP.onPlayerDestroyBlock
|
||||
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);
|
||||
if (block.removedByPlayer(world, player, x, y, z, true)) {
|
||||
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
|
||||
}
|
||||
// callback to the tool
|
||||
ItemStack itemstack = player.getCurrentEquippedItem();
|
||||
if (itemstack != null)
|
||||
{
|
||||
if (itemstack != null) {
|
||||
itemstack.func_150999_a(world, block, x, y, z, player);
|
||||
|
||||
if (itemstack.stackSize == 0)
|
||||
{
|
||||
if (itemstack.stackSize == 0) {
|
||||
player.destroyCurrentEquippedItem();
|
||||
}
|
||||
}
|
||||
|
||||
// send an update to the server, so we get an update back
|
||||
if(PHConstruct.extraBlockUpdates)
|
||||
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x,y,z, Minecraft.getMinecraft().objectMouseOver.sideHit));
|
||||
if (PHConstruct.extraBlockUpdates)
|
||||
Minecraft.getMinecraft()
|
||||
.getNetHandler()
|
||||
.addToSendQueue(new C07PacketPlayerDigging(
|
||||
2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user