mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-12 16:27:45 +00:00
Fix chisel opening its UI instead of looked at TE
This commit is contained in:
1 parent
9899ca1177
commit
a0f11f404a
2 files changed
+61
-67
No files matched your search
@@ -30,7 +30,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
||||
|
||||
public final class ChiselController {
|
||||
|
||||
private static class GuiOpen implements Runnable {
|
||||
protected static class GuiOpen implements Runnable {
|
||||
|
||||
private EntityPlayer player;
|
||||
private ItemStack stack;
|
||||
@@ -54,8 +54,7 @@ public final class ChiselController {
|
||||
|
||||
public static final ChiselController INSTANCE = new ChiselController();
|
||||
|
||||
private long lastTickClick = 0;
|
||||
private Queue<GuiOpen> openQueue = Queues.newArrayDeque();
|
||||
Queue<GuiOpen> openQueue = Queues.newArrayDeque();
|
||||
|
||||
private ChiselController() {}
|
||||
|
||||
@@ -80,78 +79,65 @@ public final class ChiselController {
|
||||
|
||||
IChiselItem chisel = (IChiselItem) held.getItem();
|
||||
|
||||
switch (event.action) {
|
||||
case LEFT_CLICK_BLOCK:
|
||||
boolean shifting = event.entityPlayer.isSneaking();
|
||||
int x = event.x, y = event.y, z = event.z;
|
||||
Block block = event.world.getBlock(x, y, z);
|
||||
int metadata = event.world.getBlockMetadata(x, y, z);
|
||||
ICarvingGroup group = Carving.chisel.getGroup(block, metadata);
|
||||
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
|
||||
boolean shifting = event.entityPlayer.isSneaking();
|
||||
int x = event.x, y = event.y, z = event.z;
|
||||
Block block = event.world.getBlock(x, y, z);
|
||||
int metadata = event.world.getBlockMetadata(x, y, z);
|
||||
ICarvingGroup group = Carving.chisel.getGroup(block, metadata);
|
||||
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileEntity te = event.world.getTileEntity(x, y, z);
|
||||
if (te != null) {
|
||||
// Don't support chiseling tile entities
|
||||
return;
|
||||
}
|
||||
TileEntity te = event.world.getTileEntity(x, y, z);
|
||||
if (te != null) {
|
||||
// Don't support chiseling tile entities
|
||||
return;
|
||||
}
|
||||
|
||||
List<ICarvingVariation> list = group.getVariations();
|
||||
List<ICarvingVariation> list = group.getVariations();
|
||||
|
||||
main: for (ItemStack stack : OreDictionary.getOres(group.getOreName())) {
|
||||
ICarvingVariation v = General.getVariation(stack);
|
||||
for (ICarvingVariation check : list) {
|
||||
if (check.getBlock() == v.getBlock() && check.getBlockMeta() == v.getBlockMeta()) {
|
||||
continue main;
|
||||
}
|
||||
}
|
||||
list.add(General.getVariation(stack));
|
||||
}
|
||||
|
||||
ICarvingVariation[] variations = list.toArray(new ICarvingVariation[] {});
|
||||
|
||||
if (chisel.canChiselBlock(event.world, event.entityPlayer, x, y, z, block, metadata)) {
|
||||
ItemStack target = General.getChiselTarget(held);
|
||||
IChiselMode mode = General.getChiselMode(held);
|
||||
ForgeDirection sideHit = ForgeDirection.VALID_DIRECTIONS[event.face];
|
||||
|
||||
if (target != null) {
|
||||
for (ICarvingVariation v : variations) {
|
||||
if (v.getBlock() == Block.getBlockFromItem(target.getItem())
|
||||
&& v.getBlockMeta() == target.getItemDamage()) {
|
||||
mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, v);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int idx = 0;
|
||||
for (int i = 0; i < variations.length; i++) {
|
||||
ICarvingVariation v = variations[i];
|
||||
if (v.getBlock() == block && v.getBlockMeta() == metadata) {
|
||||
idx = i + variations.length + (shifting ? -1 : 1);
|
||||
idx %= variations.length;
|
||||
}
|
||||
}
|
||||
|
||||
ICarvingVariation newVar = variations[idx];
|
||||
mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, newVar);
|
||||
event.entityPlayer.inventory.currentItem = slot;
|
||||
main:
|
||||
for (ItemStack stack : OreDictionary.getOres(group.getOreName())) {
|
||||
ICarvingVariation v = General.getVariation(stack);
|
||||
for (ICarvingVariation check : list) {
|
||||
if (check.getBlock() == v.getBlock() && check.getBlockMeta() == v.getBlockMeta()) {
|
||||
continue main;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RIGHT_CLICK_AIR:
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
// Make sure we have not responded this tick
|
||||
if (event.world.getTotalWorldTime() == lastTickClick) {
|
||||
break;
|
||||
list.add(General.getVariation(stack));
|
||||
}
|
||||
|
||||
ICarvingVariation[] variations = list.toArray(new ICarvingVariation[] {});
|
||||
|
||||
if (chisel.canChiselBlock(event.world, event.entityPlayer, x, y, z, block, metadata)) {
|
||||
ItemStack target = General.getChiselTarget(held);
|
||||
IChiselMode mode = General.getChiselMode(held);
|
||||
ForgeDirection sideHit = ForgeDirection.VALID_DIRECTIONS[event.face];
|
||||
|
||||
if (target != null) {
|
||||
for (ICarvingVariation v : variations) {
|
||||
if (v.getBlock() == Block.getBlockFromItem(target.getItem())
|
||||
&& v.getBlockMeta() == target.getItemDamage()) {
|
||||
mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, v);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lastTickClick = event.world.getTotalWorldTime();
|
||||
int idx = 0;
|
||||
for (int i = 0; i < variations.length; i++) {
|
||||
ICarvingVariation v = variations[i];
|
||||
if (v.getBlock() == block && v.getBlockMeta() == metadata) {
|
||||
idx = i + variations.length + (shifting ? -1 : 1);
|
||||
idx %= variations.length;
|
||||
}
|
||||
}
|
||||
|
||||
ICarvingVariation newVar = variations[idx];
|
||||
mode.chiselAll(event.entityPlayer, event.world, x, y, z, sideHit, newVar);
|
||||
event.entityPlayer.inventory.currentItem = slot;
|
||||
}
|
||||
if (!event.world.isRemote && chisel.canOpenGui(event.world, event.entityPlayer, held)) {
|
||||
openQueue.add(new GuiOpen(event.entityPlayer, held));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,4 +159,12 @@ public class ItemChisel extends Item implements IChiselItem {
|
||||
|| type == ChiselType.NETHERSTAR
|
||||
|| Configurations.ironChiselHasModes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
|
||||
if (!world.isRemote && canOpenGui(world, player, itemStack)) {
|
||||
ChiselController.INSTANCE.openQueue.add(new ChiselController.GuiOpen(player, itemStack));
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user