More removal of BlockStack usages

This commit is contained in:
Nicholas Ignoffo 2018-03-04 10:47:15 -08:00
parent 8a61741e0d
commit 2b86e5c8ad
3 changed files with 11 additions and 45 deletions

View file

@ -1,6 +1,5 @@
package WayofTime.bloodmagic.compat.waila.provider;
import WayofTime.bloodmagic.util.BlockStack;
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitualRegistry;
import WayofTime.bloodmagic.ritual.RitualRegistry;

View file

@ -2,27 +2,19 @@ package WayofTime.bloodmagic.ritual.types;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.ritual.*;
import WayofTime.bloodmagic.util.BlockStack;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockOre;
import net.minecraft.block.BlockRedstoneOre;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RitualMagnetic extends Ritual {
public static final String PLACEMENT_RANGE = "placementRange";
private static final Map<BlockStack, Boolean> oreBlockCache = new HashMap<BlockStack, Boolean>();
// public static final String SEARCH_RANGE = "searchRange";
public BlockPos lastPos; // An offset
@ -58,9 +50,7 @@ public class RitualMagnetic extends Ritual {
}
IBlockState downState = world.getBlockState(pos.down());
Block downBlock = downState.getBlock();
int radius = getRadius(downBlock);
int radius = getRadius(downState.getBlock());
if (replace) {
int j = -1;
@ -78,10 +68,7 @@ public class RitualMagnetic extends Ritual {
while (k <= radius) {
BlockPos newPos = pos.add(i, j, k);
IBlockState state = world.getBlockState(newPos);
Block block = state.getBlock();
ItemStack checkStack = block.getItem(world, newPos, state);
// int meta = block.getMetaFromState(state);
ItemStack checkStack = state.getBlock().getPickBlock(state, null, world, newPos, null);
if (isBlockOre(checkStack)) {
Utils.swapLocations(world, newPos, world, replacement);
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
@ -103,7 +90,6 @@ public class RitualMagnetic extends Ritual {
j = -1;
this.lastPos = new BlockPos(i, j, k);
return;
}
}
@ -147,35 +133,16 @@ public class RitualMagnetic extends Ritual {
return new RitualMagnetic();
}
public static boolean isBlockOre(Block block, int meta) {
if (block == null)
return false;
if (block instanceof BlockOre || block instanceof BlockRedstoneOre)
return true;
if (Item.getItemFromBlock(block) == Items.AIR)
return false;
BlockStack type = new BlockStack(block, meta);
return oreBlockCache.computeIfAbsent(type, RitualMagnetic::computeIsItemOre);
}
private static boolean computeIsItemOre(BlockStack type) {
ItemStack stack = new ItemStack(type.getBlock(), type.getMeta());
return isBlockOre(stack);
}
public static boolean isBlockOre(ItemStack stack) {
if (stack.isEmpty()) {
if (stack.isEmpty())
return false;
}
for (int id : OreDictionary.getOreIDs(stack)) {
String oreName = OreDictionary.getOreName(id);
if (oreName.contains("ore"))
return true;
}
return false;
}
}

View file

@ -848,10 +848,10 @@ public class Utils {
if (finalTile != null)
finalTile.writeToNBT(finalTag);
BlockStack initialStack = BlockStack.getStackFromPos(initialWorld, initialPos);
BlockStack finalStack = BlockStack.getStackFromPos(finalWorld, finalPos);
IBlockState initialState = initialWorld.getBlockState(initialPos);
IBlockState finalState = finalWorld.getBlockState(finalPos);
if ((initialStack.getBlock().equals(Blocks.AIR) && finalStack.getBlock().equals(Blocks.AIR)) || initialStack.getBlock() instanceof BlockPortal || finalStack.getBlock() instanceof BlockPortal)
if ((initialState.getBlock().equals(Blocks.AIR) && finalState.getBlock().equals(Blocks.AIR)) || initialState.getBlock() instanceof BlockPortal || finalState.getBlock() instanceof BlockPortal)
return false;
if (playSound) {
@ -860,9 +860,9 @@ public class Utils {
}
//Finally, we get to do something! (CLEARING TILES)
if (finalStack.getBlock() != null)
if (finalState.getBlock().hasTileEntity(finalState))
finalWorld.removeTileEntity(finalPos);
if (initialStack.getBlock() != null)
if (initialState.getBlock().hasTileEntity(initialState))
initialWorld.removeTileEntity(initialPos);
//TILES CLEARED
@ -889,8 +889,8 @@ public class Utils {
newTileFinal.setWorld(initialWorld);
}
initialWorld.notifyNeighborsOfStateChange(initialPos, finalStack.getBlock(), true);
finalWorld.notifyNeighborsOfStateChange(finalPos, initialStack.getBlock(), true);
initialWorld.notifyNeighborsOfStateChange(initialPos, finalState.getBlock(), true);
finalWorld.notifyNeighborsOfStateChange(finalPos, initialState.getBlock(), true);
return true;
}