2022-11-22 15:26:15 +01:00
|
|
|
package com.pahimar.ee3.util;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import com.pahimar.ee3.handler.EquivalencyHandler;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class TransmutationHelper {
|
|
|
|
public static ItemStack previousBlockStack;
|
|
|
|
public static ItemStack currentBlockStack;
|
|
|
|
public static ItemStack targetBlockStack;
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public static boolean transmuteInWorld(
|
|
|
|
final World world,
|
|
|
|
final EntityPlayer player,
|
|
|
|
final ItemStack stack,
|
|
|
|
final int x,
|
|
|
|
final int y,
|
|
|
|
final int z,
|
|
|
|
final Block target,
|
|
|
|
final int targetMeta
|
|
|
|
) {
|
2022-11-22 15:26:15 +01:00
|
|
|
world.setBlock(x, y, z, target, targetMeta, 2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String formatTargetBlockInfo(final ItemStack targetBlock) {
|
|
|
|
if (targetBlock != null) {
|
2023-01-03 17:47:36 +01:00
|
|
|
return TransmutationHelper.targetBlockStack.getUnlocalizedName() + ":"
|
|
|
|
+ TransmutationHelper.targetBlockStack.getItemDamage();
|
2022-11-22 15:26:15 +01:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public static void
|
|
|
|
updateTargetBlock(final World world, final int x, final int y, final int z) {
|
2022-11-22 15:26:15 +01:00
|
|
|
final Block currentBlock = world.getBlock(x, y, z);
|
|
|
|
int meta = world.getBlockMetadata(x, y, z);
|
|
|
|
if (currentBlock != null) {
|
|
|
|
meta = currentBlock.damageDropped(meta);
|
|
|
|
TransmutationHelper.currentBlockStack = new ItemStack(currentBlock, 1, meta);
|
|
|
|
if (TransmutationHelper.previousBlockStack == null) {
|
2023-01-03 17:47:36 +01:00
|
|
|
TransmutationHelper.previousBlockStack
|
|
|
|
= TransmutationHelper.currentBlockStack;
|
|
|
|
TransmutationHelper.targetBlockStack = getNextBlock(
|
|
|
|
TransmutationHelper.currentBlockStack.getItem(),
|
|
|
|
TransmutationHelper.currentBlockStack.getItemDamage()
|
|
|
|
);
|
|
|
|
} else if (!EquivalencyHandler.instance().areEquivalent(
|
|
|
|
TransmutationHelper.previousBlockStack,
|
|
|
|
TransmutationHelper.currentBlockStack
|
|
|
|
)) {
|
|
|
|
TransmutationHelper.previousBlockStack
|
|
|
|
= TransmutationHelper.currentBlockStack;
|
|
|
|
TransmutationHelper.targetBlockStack = getNextBlock(
|
|
|
|
TransmutationHelper.currentBlockStack.getItem(),
|
|
|
|
TransmutationHelper.currentBlockStack.getItemDamage()
|
|
|
|
);
|
2022-11-22 15:26:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getNextBlock(final Item id, final int meta) {
|
2023-01-03 17:47:36 +01:00
|
|
|
final ArrayList<ItemStack> list
|
|
|
|
= EquivalencyHandler.instance().getEquivalencyList(id, meta);
|
2022-11-22 15:26:15 +01:00
|
|
|
final ItemStack nextStack = null;
|
|
|
|
if (list != null) {
|
|
|
|
return getNextBlock(id, meta, id, meta);
|
|
|
|
}
|
|
|
|
return nextStack;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
private static ItemStack
|
|
|
|
getNextBlock(final Item id, final int meta, final Item origId, final int origMeta) {
|
|
|
|
final ArrayList<ItemStack> list
|
|
|
|
= EquivalencyHandler.instance().getEquivalencyList(id, meta);
|
2022-11-22 15:26:15 +01:00
|
|
|
ItemStack nextStack = null;
|
|
|
|
if (list == null) {
|
|
|
|
return nextStack;
|
|
|
|
}
|
|
|
|
nextStack = EquivalencyHandler.instance().getNextInList(id, meta);
|
|
|
|
nextStack.stackSize = 1;
|
|
|
|
if (nextStack.getItem() == origId && nextStack.getItemDamage() == origMeta) {
|
|
|
|
return nextStack;
|
|
|
|
}
|
|
|
|
if (nextStack.getItem() instanceof ItemBlock) {
|
|
|
|
return nextStack;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
return getNextBlock(
|
|
|
|
nextStack.getItem(), nextStack.getItemDamage(), origId, origMeta
|
|
|
|
);
|
2022-11-22 15:26:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getPreviousBlock(final Item itemID, final int meta) {
|
2023-01-03 17:47:36 +01:00
|
|
|
final ArrayList<ItemStack> list
|
|
|
|
= EquivalencyHandler.instance().getEquivalencyList(itemID, meta);
|
2022-11-22 15:26:15 +01:00
|
|
|
final ItemStack prevStack = null;
|
|
|
|
if (list != null) {
|
|
|
|
return getPreviousBlock(itemID, meta, itemID, meta);
|
|
|
|
}
|
|
|
|
return prevStack;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
|
|
|
|
private static ItemStack getPreviousBlock(
|
|
|
|
final Item id, final int meta, final Item origId, final int origMeta
|
|
|
|
) {
|
|
|
|
final ArrayList<ItemStack> list
|
|
|
|
= EquivalencyHandler.instance().getEquivalencyList(id, meta);
|
2022-11-22 15:26:15 +01:00
|
|
|
ItemStack prevStack = null;
|
|
|
|
if (list == null) {
|
|
|
|
return prevStack;
|
|
|
|
}
|
|
|
|
prevStack = EquivalencyHandler.instance().getPrevInList(id, meta);
|
|
|
|
prevStack.stackSize = 1;
|
|
|
|
if (prevStack.getItem() == origId && prevStack.getItemDamage() == origMeta) {
|
|
|
|
return prevStack;
|
|
|
|
}
|
|
|
|
if (prevStack.getItem() instanceof ItemBlock) {
|
|
|
|
return prevStack;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
return getPreviousBlock(
|
|
|
|
prevStack.getItem(), prevStack.getItemDamage(), origId, origMeta
|
|
|
|
);
|
2022-11-22 15:26:15 +01:00
|
|
|
}
|
|
|
|
}
|