mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
remove more meta usage
This commit is contained in:
parent
88daf6683d
commit
54e5cdd5cf
1 changed files with 65 additions and 71 deletions
|
@ -31,10 +31,13 @@ import net.minecraft.util.EnumHand;
|
|||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
public class ItemFillingWand extends ItemEnergy {
|
||||
|
||||
public ItemFillingWand(String name) {
|
||||
|
@ -62,18 +65,15 @@ public class ItemFillingWand extends ItemEnergy{
|
|||
return false;
|
||||
}
|
||||
|
||||
private static void saveBlock(IBlockState state, ItemStack stack){
|
||||
if(!stack.hasTagCompound()){
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
private static void saveData(ItemStack pickBlock, IBlockState state, ItemStack wand) {
|
||||
if (!wand.hasTagCompound()) wand.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 IBlockState loadBlock(ItemStack stack){
|
||||
if(stack.hasTagCompound()){
|
||||
return Block.getStateById(stack.getTagCompound().getInteger("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"));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -83,10 +83,10 @@ public class ItemFillingWand extends ItemEnergy{
|
|||
if (!world.isRemote && player.getItemInUseCount() <= 0) {
|
||||
if (player.isSneaking()) {
|
||||
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;
|
||||
}
|
||||
else if(loadBlock(stack) != null){
|
||||
} else if (loadData(stack) != null) {
|
||||
if (!stack.hasTagCompound()) {
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
@ -154,8 +154,9 @@ public class ItemFillingWand extends ItemEnergy{
|
|||
if (!BlockPos.ORIGIN.equals(firstPos) && !BlockPos.ORIGIN.equals(secondPos)) {
|
||||
int energyUse = 1500;
|
||||
|
||||
IBlockState replaceState = loadBlock(stack);
|
||||
if(replaceState != null && (creative || this.getEnergyStored(stack) >= energyUse)){
|
||||
Pair<IBlockState, String> data = loadData(stack);
|
||||
if (data != null && (creative || this.getEnergyStored(stack) >= energyUse)) {
|
||||
IBlockState replaceState = data.getLeft();
|
||||
int lowestX = Math.min(firstPos.getX(), secondPos.getX());
|
||||
int lowestY = Math.min(firstPos.getY(), secondPos.getY());
|
||||
int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ());
|
||||
|
@ -177,8 +178,7 @@ public class ItemFillingWand extends ItemEnergy{
|
|||
if (!creative) {
|
||||
this.extractEnergyInternal(stack, energyUse, false);
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
shouldClear = true;
|
||||
}
|
||||
}
|
||||
|
@ -205,14 +205,12 @@ public class ItemFillingWand extends ItemEnergy{
|
|||
compound.setInteger("CurrY", currY);
|
||||
compound.setInteger("CurrZ", currZ);
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
shouldClear = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
shouldClear = true;
|
||||
}
|
||||
|
||||
|
@ -228,13 +226,9 @@ public class ItemFillingWand extends ItemEnergy{
|
|||
|
||||
String display = StringUtil.localize("tooltip." + ModUtil.MOD_ID + ".item_filling_wand.selectedBlock.none");
|
||||
|
||||
IBlockState state = loadBlock(stack);
|
||||
if(state != null){
|
||||
Block block = state.getBlock();
|
||||
ItemStack blockStack = new ItemStack(block, 1, block.getMetaFromState(state));
|
||||
if(StackUtil.isValid(blockStack)){
|
||||
display = blockStack.getDisplayName();
|
||||
}
|
||||
Pair<IBlockState, String> data = loadData(stack);
|
||||
if (data != null) {
|
||||
display = data.getRight();
|
||||
}
|
||||
|
||||
tooltip.add(String.format("%s: %s", StringUtil.localize("tooltip." + ModUtil.MOD_ID + ".item_filling_wand.selectedBlock"), display));
|
||||
|
|
Loading…
Reference in a new issue