remove more meta usage

This commit is contained in:
Shadows_of_Fire 2018-03-22 23:49:50 -04:00
parent 88daf6683d
commit 54e5cdd5cf

View file

@ -31,10 +31,13 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
public class ItemFillingWand extends ItemEnergy { public class ItemFillingWand extends ItemEnergy {
public ItemFillingWand(String name) { public ItemFillingWand(String name) {
@ -62,18 +65,15 @@ public class ItemFillingWand extends ItemEnergy{
return false; return false;
} }
private static void saveBlock(IBlockState state, ItemStack stack){ private static void saveData(ItemStack pickBlock, IBlockState state, ItemStack wand) {
if(!stack.hasTagCompound()){ if (!wand.hasTagCompound()) wand.setTagCompound(new NBTTagCompound());
stack.setTagCompound(new NBTTagCompound()); wand.getTagCompound().setInteger("state", Block.getStateId(state));
wand.getTagCompound().setString("name", pickBlock.getDisplayName());
} }
stack.getTagCompound().setInteger("state", Block.getStateId(state)); private static Pair<IBlockState, String> loadData(ItemStack stack) {
} if (stack.hasTagCompound()) return Pair.of(Block.getStateById(stack.getTagCompound().getInteger("state")), stack.getTagCompound().getString("name"));
private static IBlockState loadBlock(ItemStack stack){
if(stack.hasTagCompound()){
return Block.getStateById(stack.getTagCompound().getInteger("state"));
}
return null; return null;
} }
@ -83,10 +83,10 @@ public class ItemFillingWand extends ItemEnergy{
if (!world.isRemote && player.getItemInUseCount() <= 0) { if (!world.isRemote && player.getItemInUseCount() <= 0) {
if (player.isSneaking()) { if (player.isSneaking()) {
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
saveBlock(state, stack); ItemStack pick = state.getBlock().getPickBlock(state, world.rayTraceBlocks(player.getPositionVector(), new Vec3d(pos.getX() + hitX, pos.getY() + hitY, pos.getZ() + hitZ)), world, pos, player);
saveData(pick, state, stack);
return EnumActionResult.SUCCESS; return EnumActionResult.SUCCESS;
} } else if (loadData(stack) != null) {
else if(loadBlock(stack) != null){
if (!stack.hasTagCompound()) { if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound()); stack.setTagCompound(new NBTTagCompound());
} }
@ -154,8 +154,9 @@ public class ItemFillingWand extends ItemEnergy{
if (!BlockPos.ORIGIN.equals(firstPos) && !BlockPos.ORIGIN.equals(secondPos)) { if (!BlockPos.ORIGIN.equals(firstPos) && !BlockPos.ORIGIN.equals(secondPos)) {
int energyUse = 1500; int energyUse = 1500;
IBlockState replaceState = loadBlock(stack); Pair<IBlockState, String> data = loadData(stack);
if(replaceState != null && (creative || this.getEnergyStored(stack) >= energyUse)){ if (data != null && (creative || this.getEnergyStored(stack) >= energyUse)) {
IBlockState replaceState = data.getLeft();
int lowestX = Math.min(firstPos.getX(), secondPos.getX()); int lowestX = Math.min(firstPos.getX(), secondPos.getX());
int lowestY = Math.min(firstPos.getY(), secondPos.getY()); int lowestY = Math.min(firstPos.getY(), secondPos.getY());
int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ()); int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ());
@ -177,8 +178,7 @@ public class ItemFillingWand extends ItemEnergy{
if (!creative) { if (!creative) {
this.extractEnergyInternal(stack, energyUse, false); this.extractEnergyInternal(stack, energyUse, false);
} }
} } else {
else{
shouldClear = true; shouldClear = true;
} }
} }
@ -205,14 +205,12 @@ public class ItemFillingWand extends ItemEnergy{
compound.setInteger("CurrY", currY); compound.setInteger("CurrY", currY);
compound.setInteger("CurrZ", currZ); compound.setInteger("CurrZ", currZ);
} }
} } else {
else{
shouldClear = true; shouldClear = true;
} }
} }
} }
} } else {
else{
shouldClear = true; shouldClear = true;
} }
@ -228,13 +226,9 @@ public class ItemFillingWand extends ItemEnergy{
String display = StringUtil.localize("tooltip." + ModUtil.MOD_ID + ".item_filling_wand.selectedBlock.none"); String display = StringUtil.localize("tooltip." + ModUtil.MOD_ID + ".item_filling_wand.selectedBlock.none");
IBlockState state = loadBlock(stack); Pair<IBlockState, String> data = loadData(stack);
if(state != null){ if (data != null) {
Block block = state.getBlock(); display = data.getRight();
ItemStack blockStack = new ItemStack(block, 1, block.getMetaFromState(state));
if(StackUtil.isValid(blockStack)){
display = blockStack.getDisplayName();
}
} }
tooltip.add(String.format("%s: %s", StringUtil.localize("tooltip." + ModUtil.MOD_ID + ".item_filling_wand.selectedBlock"), display)); tooltip.add(String.format("%s: %s", StringUtil.localize("tooltip." + ModUtil.MOD_ID + ".item_filling_wand.selectedBlock"), display));