Helper swap

- Replaced temporary AllItems#typeOf with ItemEntry's non-static isIn
This commit is contained in:
simibubi 2020-06-03 22:17:11 +02:00
parent 36ab939126
commit 77835c3a65
27 changed files with 34 additions and 49 deletions

View file

@ -38,7 +38,6 @@ import com.simibubi.create.foundation.data.CreateRegistrate;
import com.tterrag.registrate.util.entry.ItemEntry; import com.tterrag.registrate.util.entry.ItemEntry;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity; import net.minecraft.item.Rarity;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
@ -229,12 +228,6 @@ public class AllItems {
.register(); .register();
} }
// Helper
public static boolean typeOf(ItemEntry<?> entry, ItemStack stack) {
return stack != null && stack.getItem() == entry.get();
}
// Load this class // Load this class
public static void register() {} public static void register() {}

View file

@ -173,7 +173,7 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IT
if (!(te instanceof MechanicalCrafterTileEntity)) if (!(te instanceof MechanicalCrafterTileEntity))
return ActionResultType.PASS; return ActionResultType.PASS;
MechanicalCrafterTileEntity crafter = (MechanicalCrafterTileEntity) te; MechanicalCrafterTileEntity crafter = (MechanicalCrafterTileEntity) te;
boolean wrenched = AllItems.typeOf(AllItems.WRENCH, heldItem); boolean wrenched = AllItems.WRENCH.isIn(heldItem);
if (hit.getFace() == state.get(HORIZONTAL_FACING)) { if (hit.getFace() == state.get(HORIZONTAL_FACING)) {
@ -186,7 +186,7 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IT
if (worldIn.isRemote) if (worldIn.isRemote)
return ActionResultType.SUCCESS; return ActionResultType.SUCCESS;
if (AllItems.typeOf(AllItems.CRAFTER_SLOT_COVER, heldItem)) { if (AllItems.CRAFTER_SLOT_COVER.isIn(heldItem)) {
if (crafter.covered) if (crafter.covered)
return ActionResultType.PASS; return ActionResultType.PASS;
crafter.covered = true; crafter.covered = true;

View file

@ -85,7 +85,7 @@ public class DeployerBlock extends DirectionalAxisKineticBlock implements ITE<De
BlockRayTraceResult hit) { BlockRayTraceResult hit) {
ItemStack heldByPlayer = player.getHeldItem(handIn) ItemStack heldByPlayer = player.getHeldItem(handIn)
.copy(); .copy();
if (AllItems.typeOf(AllItems.WRENCH, heldByPlayer)) if (AllItems.WRENCH.isIn(heldByPlayer))
return ActionResultType.PASS; return ActionResultType.PASS;
if (hit.getFace() != state.get(FACING)) if (hit.getFace() != state.get(FACING))

View file

@ -90,7 +90,7 @@ public class ChassisRangeDisplay {
public static void tick() { public static void tick() {
PlayerEntity player = Minecraft.getInstance().player; PlayerEntity player = Minecraft.getInstance().player;
World world = Minecraft.getInstance().world; World world = Minecraft.getInstance().world;
boolean hasWrench = AllItems.typeOf(AllItems.WRENCH, player.getHeldItemMainhand()); boolean hasWrench = AllItems.WRENCH.isIn(player.getHeldItemMainhand());
for (Iterator<BlockPos> iterator = entries.keySet() for (Iterator<BlockPos> iterator = entries.keySet()
.iterator(); iterator.hasNext();) { .iterator(); iterator.hasNext();) {

View file

@ -49,7 +49,7 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock implements
ItemStack heldItem = player.getHeldItem(handIn); ItemStack heldItem = player.getHeldItem(handIn);
boolean isSlimeBall = heldItem.getItem() boolean isSlimeBall = heldItem.getItem()
.isIn(Tags.Items.SLIMEBALLS) || AllItems.typeOf(AllItems.SUPER_GLUE, heldItem); .isIn(Tags.Items.SLIMEBALLS) || AllItems.SUPER_GLUE.isIn(heldItem);
BooleanProperty affectedSide = getGlueableSide(state, hit.getFace()); BooleanProperty affectedSide = getGlueableSide(state, hit.getFace());
if (affectedSide == null) if (affectedSide == null)

View file

@ -63,7 +63,7 @@ public class SuperGlueHandler {
public static void glueInOffHandAppliesOnBlockPlace(EntityPlaceEvent event, BlockPos pos, PlayerEntity placer) { public static void glueInOffHandAppliesOnBlockPlace(EntityPlaceEvent event, BlockPos pos, PlayerEntity placer) {
ItemStack itemstack = placer.getHeldItemOffhand(); ItemStack itemstack = placer.getHeldItemOffhand();
if (!AllItems.typeOf(AllItems.SUPER_GLUE, itemstack)) if (!AllItems.SUPER_GLUE.isIn(itemstack))
return; return;
double distance = placer.getAttribute(PlayerEntity.REACH_DISTANCE) double distance = placer.getAttribute(PlayerEntity.REACH_DISTANCE)

View file

@ -1,7 +1,5 @@
package com.simibubi.create.content.contraptions.components.structureMovement.glue; package com.simibubi.create.content.contraptions.components.structureMovement.glue;
import static com.simibubi.create.AllItems.typeOf;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.matrix.MatrixStack.Entry; import com.mojang.blaze3d.matrix.MatrixStack.Entry;
import com.mojang.blaze3d.vertex.IVertexBuilder; import com.mojang.blaze3d.vertex.IVertexBuilder;
@ -54,8 +52,8 @@ public class SuperGlueRenderer extends EntityRenderer<SuperGlueEntity> {
PlayerEntity player = Minecraft.getInstance().player; PlayerEntity player = Minecraft.getInstance().player;
boolean visible = isVisible(entity); boolean visible = isVisible(entity);
boolean holdingGlue = typeOf(AllItems.SUPER_GLUE, player.getHeldItemMainhand()) boolean holdingGlue = AllItems.SUPER_GLUE.isIn(player.getHeldItemMainhand())
|| typeOf(AllItems.SUPER_GLUE, player.getHeldItemOffhand()); || AllItems.SUPER_GLUE.isIn(player.getHeldItemOffhand());
if (!visible && !holdingGlue) if (!visible && !holdingGlue)
return; return;

View file

@ -185,7 +185,7 @@ public class MinecartContraptionItem extends Item {
return; return;
ItemStack wrench = player.getHeldItem(event.getHand()); ItemStack wrench = player.getHeldItem(event.getHand());
if (!AllItems.typeOf(AllItems.WRENCH, wrench)) if (!AllItems.WRENCH.isIn(wrench))
return; return;
if (entity instanceof ContraptionEntity) if (entity instanceof ContraptionEntity)
entity = entity.getRidingEntity(); entity = entity.getRidingEntity();

View file

@ -51,7 +51,7 @@ public class GoggleOverlayRenderer {
List<String> tooltip = new ArrayList<>(); List<String> tooltip = new ArrayList<>();
if (goggleInformation && AllItems.typeOf(AllItems.GOGGLES, goggles)) { if (goggleInformation && AllItems.GOGGLES.isIn(goggles)) {
IHaveGoggleInformation gte = (IHaveGoggleInformation) te; IHaveGoggleInformation gte = (IHaveGoggleInformation) te;
if (!gte.addToGoggleTooltip(tooltip, mc.player.isSneaking())) if (!gte.addToGoggleTooltip(tooltip, mc.player.isSneaking()))
goggleInformation = false; goggleInformation = false;

View file

@ -41,7 +41,7 @@ public class GogglesItem extends Item {
public static boolean canSeeParticles(PlayerEntity player) { public static boolean canSeeParticles(PlayerEntity player) {
for (ItemStack itemStack : player.getArmorInventoryList()) for (ItemStack itemStack : player.getArmorInventoryList())
if (AllItems.typeOf(AllItems.GOGGLES, itemStack)) if (AllItems.GOGGLES.isIn(itemStack))
return true; return true;
return false; return false;
} }

View file

@ -80,7 +80,7 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) { BlockRayTraceResult hit) {
ItemStack held = player.getHeldItemMainhand(); ItemStack held = player.getHeldItemMainhand();
if (AllItems.typeOf(AllItems.WRENCH, held)) if (AllItems.WRENCH.isIn(held))
return ActionResultType.PASS; return ActionResultType.PASS;
if (held.getItem() instanceof BlockItem) { if (held.getItem() instanceof BlockItem) {
BlockItem blockItem = (BlockItem) held.getItem(); BlockItem blockItem = (BlockItem) held.getItem();

View file

@ -39,7 +39,7 @@ public class BeltConnectorHandler {
for (Hand hand : Hand.values()) { for (Hand hand : Hand.values()) {
ItemStack heldItem = player.getHeldItem(hand); ItemStack heldItem = player.getHeldItem(hand);
if (!AllItems.typeOf(AllItems.BELT_CONNECTOR, heldItem)) if (!AllItems.BELT_CONNECTOR.isIn(heldItem))
continue; continue;
if (!heldItem.hasTag()) if (!heldItem.hasTag())
continue; continue;

View file

@ -1,7 +1,5 @@
package com.simibubi.create.content.curiosities.symmetry; package com.simibubi.create.content.curiosities.symmetry;
import static com.simibubi.create.AllItems.typeOf;
import java.util.Random; import java.util.Random;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
@ -77,7 +75,7 @@ public class SymmetryHandler {
PlayerInventory inv = player.inventory; PlayerInventory inv = player.inventory;
for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) { for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) {
if (!inv.getStackInSlot(i) if (!inv.getStackInSlot(i)
.isEmpty() && typeOf(AllItems.WAND_OF_SYMMETRY, inv.getStackInSlot(i))) { .isEmpty() && AllItems.WAND_OF_SYMMETRY.isIn(inv.getStackInSlot(i))) {
SymmetryWandItem.remove(player.world, inv.getStackInSlot(i), player, event.getPos()); SymmetryWandItem.remove(player.world, inv.getStackInSlot(i), player, event.getPos());
} }
} }
@ -91,7 +89,7 @@ public class SymmetryHandler {
for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) { for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) {
ItemStack stackInSlot = player.inventory.getStackInSlot(i); ItemStack stackInSlot = player.inventory.getStackInSlot(i);
if (!typeOf(AllItems.WAND_OF_SYMMETRY, stackInSlot)) if (!AllItems.WAND_OF_SYMMETRY.isIn(stackInSlot))
continue; continue;
if (!SymmetryWandItem.isEnabled(stackInSlot)) if (!SymmetryWandItem.isEnabled(stackInSlot))
continue; continue;
@ -155,7 +153,7 @@ public class SymmetryHandler {
for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) { for (int i = 0; i < PlayerInventory.getHotbarSize(); i++) {
ItemStack stackInSlot = player.inventory.getStackInSlot(i); ItemStack stackInSlot = player.inventory.getStackInSlot(i);
if (stackInSlot != null && typeOf(AllItems.WAND_OF_SYMMETRY, stackInSlot) if (stackInSlot != null && AllItems.WAND_OF_SYMMETRY.isIn(stackInSlot)
&& SymmetryWandItem.isEnabled(stackInSlot)) { && SymmetryWandItem.isEnabled(stackInSlot)) {
SymmetryMirror mirror = SymmetryWandItem.getMirror(stackInSlot); SymmetryMirror mirror = SymmetryWandItem.getMirror(stackInSlot);

View file

@ -60,7 +60,7 @@ public class DeforesterItem extends AxeItem {
@SubscribeEvent @SubscribeEvent
public static void onBlockDestroyed(BlockEvent.BreakEvent event) { public static void onBlockDestroyed(BlockEvent.BreakEvent event) {
ItemStack heldItemMainhand = event.getPlayer().getHeldItemMainhand(); ItemStack heldItemMainhand = event.getPlayer().getHeldItemMainhand();
if (!AllItems.typeOf(AllItems.DEFORESTER, heldItemMainhand)) if (!AllItems.DEFORESTER.isIn(heldItemMainhand))
return; return;
destroyTree(heldItemMainhand, event.getWorld(), event.getState(), event.getPos(), event.getPlayer()); destroyTree(heldItemMainhand, event.getWorld(), event.getState(), event.getPos(), event.getPlayer());
} }

View file

@ -152,7 +152,7 @@ public class BlockzapperItem extends ZapperItem {
@Override @Override
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
if (AllItems.typeOf(AllItems.BLOCKZAPPER, stack)) { if (AllItems.BLOCKZAPPER.isIn(stack)) {
CompoundNBT nbt = stack.getOrCreateTag(); CompoundNBT nbt = stack.getOrCreateTag();
if (!nbt.contains("Replace")) if (!nbt.contains("Replace"))
nbt.putBoolean("Replace", false); nbt.putBoolean("Replace", false);

View file

@ -33,8 +33,8 @@ public class BlockzapperRenderHandler {
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
ItemStack heldMain = player.getHeldItemMainhand(); ItemStack heldMain = player.getHeldItemMainhand();
ItemStack heldOff = player.getHeldItemOffhand(); ItemStack heldOff = player.getHeldItemOffhand();
boolean zapperInMain = AllItems.typeOf(AllItems.BLOCKZAPPER, heldMain); boolean zapperInMain = AllItems.BLOCKZAPPER.isIn(heldMain);
boolean zapperInOff = AllItems.typeOf(AllItems.BLOCKZAPPER, heldOff); boolean zapperInOff = AllItems.BLOCKZAPPER.isIn(heldOff);
if (zapperInMain) { if (zapperInMain) {
CompoundNBT tag = heldMain.getOrCreateTag(); CompoundNBT tag = heldMain.getOrCreateTag();

View file

@ -45,7 +45,7 @@ public class BlockzapperUpgradeRecipe implements ICraftingRecipe {
public ItemStack getCraftingResult(CraftingInventory inv) { public ItemStack getCraftingResult(CraftingInventory inv) {
for (int slot = 0; slot < inv.getSizeInventory(); slot++) { for (int slot = 0; slot < inv.getSizeInventory(); slot++) {
ItemStack handgun = inv.getStackInSlot(slot).copy(); ItemStack handgun = inv.getStackInSlot(slot).copy();
if (!AllItems.typeOf(AllItems.BLOCKZAPPER, handgun)) if (!AllItems.BLOCKZAPPER.isIn(handgun))
continue; continue;
BlockzapperItem.setTier(getUpgradedComponent(), getTier(), handgun); BlockzapperItem.setTier(getUpgradedComponent(), getTier(), handgun);
return handgun; return handgun;

View file

@ -44,8 +44,8 @@ public class WorldshaperRenderHandler {
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
ItemStack heldMain = player.getHeldItemMainhand(); ItemStack heldMain = player.getHeldItemMainhand();
ItemStack heldOff = player.getHeldItemOffhand(); ItemStack heldOff = player.getHeldItemOffhand();
boolean zapperInMain = AllItems.typeOf(AllItems.WORLDSHAPER, heldMain); boolean zapperInMain = AllItems.WORLDSHAPER.isIn(heldMain);
boolean zapperInOff = AllItems.typeOf(AllItems.WORLDSHAPER, heldOff); boolean zapperInOff = AllItems.WORLDSHAPER.isIn(heldOff);
if (zapperInMain) { if (zapperInMain) {
CompoundNBT tag = heldMain.getOrCreateTag(); CompoundNBT tag = heldMain.getOrCreateTag();

View file

@ -50,7 +50,7 @@ public class ToggleLatchBlock extends AbstractDiodeBlock {
return ActionResultType.PASS; return ActionResultType.PASS;
if (player.isSneaking()) if (player.isSneaking())
return ActionResultType.PASS; return ActionResultType.PASS;
if (AllItems.typeOf(AllItems.WRENCH, player.getHeldItem(handIn))) if (AllItems.WRENCH.isIn(player.getHeldItem(handIn)))
return ActionResultType.PASS; return ActionResultType.PASS;
return activated(worldIn, pos, state); return activated(worldIn, pos, state);
} }

View file

@ -95,7 +95,7 @@ public class StockpileSwitchBlock extends HorizontalBlock implements ITE<Stockpi
@Override @Override
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) { BlockRayTraceResult hit) {
if (player != null && AllItems.typeOf(AllItems.WRENCH, player.getHeldItem(handIn))) if (player != null && AllItems.WRENCH.isIn(player.getHeldItem(handIn)))
return ActionResultType.PASS; return ActionResultType.PASS;
DistExecutor.runWhenOn(Dist.CLIENT, DistExecutor.runWhenOn(Dist.CLIENT,
() -> () -> withTileEntityDo(worldIn, pos, te -> this.displayScreen(te, player))); () -> () -> withTileEntityDo(worldIn, pos, te -> this.displayScreen(te, player)));

View file

@ -1,7 +1,5 @@
package com.simibubi.create.content.schematics.block; package com.simibubi.create.content.schematics.block;
import static com.simibubi.create.AllItems.typeOf;
import com.simibubi.create.AllContainerTypes; import com.simibubi.create.AllContainerTypes;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
@ -46,9 +44,8 @@ public class SchematicTableContainer extends Container {
inputSlot = new SlotItemHandler(te.inventory, 0, -9, 40) { inputSlot = new SlotItemHandler(te.inventory, 0, -9, 40) {
@Override @Override
public boolean isItemValid(ItemStack stack) { public boolean isItemValid(ItemStack stack) {
return typeOf(AllItems.EMPTY_SCHEMATIC, stack) return AllItems.EMPTY_SCHEMATIC.isIn(stack) || AllItems.SCHEMATIC_AND_QUILL.isIn(stack)
|| typeOf(AllItems.SCHEMATIC_AND_QUILL, stack) || AllItems.SCHEMATIC.isIn(stack);
|| typeOf(AllItems.SCHEMATIC, stack);
} }
}; };

View file

@ -27,7 +27,7 @@ public class SchematicannonInventory extends ItemStackHandler {
public boolean isItemValid(int slot, ItemStack stack) { public boolean isItemValid(int slot, ItemStack stack) {
switch (slot) { switch (slot) {
case 0: // Blueprint Slot case 0: // Blueprint Slot
return AllItems.typeOf(AllItems.SCHEMATIC, stack); return AllItems.SCHEMATIC.isIn(stack);
case 1: // Blueprint output case 1: // Blueprint output
return false; return false;
case 2: // Book input case 2: // Book input

View file

@ -177,7 +177,7 @@ public class SchematicAndQuillHandler {
outliner().chaseAABB(outlineSlot, currentSelectionBox) outliner().chaseAABB(outlineSlot, currentSelectionBox)
.colored(0x6886c5) .colored(0x6886c5)
.withFaceTextures(AllSpecialTextures.CHECKERED, AllSpecialTextures.HIGHLIGHT_CHECKERED) .withFaceTextures(AllSpecialTextures.CHECKERED, AllSpecialTextures.HIGHLIGHT_CHECKERED)
.lineWidth(1/16f) .lineWidth(1 / 16f)
.highlightFace(selectedFace); .highlightFace(selectedFace);
} }
@ -192,8 +192,7 @@ public class SchematicAndQuillHandler {
} }
private boolean isActive() { private boolean isActive() {
return isPresent() && AllItems.typeOf(AllItems.SCHEMATIC_AND_QUILL, return isPresent() && AllItems.SCHEMATIC_AND_QUILL.isIn(Minecraft.getInstance().player.getHeldItemMainhand());
Minecraft.getInstance().player.getHeldItemMainhand());
} }
private boolean isPresent() { private boolean isPresent() {

View file

@ -234,7 +234,7 @@ public class SchematicHandler {
private ItemStack findBlueprintInHand(PlayerEntity player) { private ItemStack findBlueprintInHand(PlayerEntity player) {
ItemStack stack = player.getHeldItemMainhand(); ItemStack stack = player.getHeldItemMainhand();
if (!AllItems.typeOf(AllItems.SCHEMATIC, stack)) if (!AllItems.SCHEMATIC.isIn(stack))
return null; return null;
if (!stack.hasTag()) if (!stack.hasTag())
return null; return null;

View file

@ -97,7 +97,7 @@ public class TooltipHelper {
ClientPlayerEntity player = Minecraft.getInstance().player; ClientPlayerEntity player = Minecraft.getInstance().player;
boolean hasGlasses = player != null boolean hasGlasses = player != null
&& AllItems.typeOf(AllItems.GOGGLES, player.getItemStackFromSlot(EquipmentSlotType.HEAD)); && AllItems.GOGGLES.isIn(player.getItemStackFromSlot(EquipmentSlotType.HEAD));
if (hasGlasses != gogglesMode) { if (hasGlasses != gogglesMode) {
gogglesMode = hasGlasses; gogglesMode = hasGlasses;

View file

@ -36,7 +36,7 @@ public class ScrollValueHandler {
return false; return false;
if (!mc.player.isAllowEdit()) if (!mc.player.isAllowEdit())
return false; return false;
if (scrolling.needsWrench && !AllItems.typeOf(AllItems.WRENCH, mc.player.getHeldItemMainhand())) if (scrolling.needsWrench && !AllItems.WRENCH.isIn(mc.player.getHeldItemMainhand()))
return false; return false;
if (scrolling.slotPositioning instanceof Sided) if (scrolling.slotPositioning instanceof Sided)
((Sided) scrolling.slotPositioning).fromSide(result.getFace()); ((Sided) scrolling.slotPositioning).fromSide(result.getFace());

View file

@ -36,7 +36,7 @@ public class ScrollValueRenderer {
if (behaviour == null) if (behaviour == null)
return; return;
if (behaviour.needsWrench if (behaviour.needsWrench
&& !AllItems.typeOf(AllItems.WRENCH, Minecraft.getInstance().player.getHeldItemMainhand())) && !AllItems.WRENCH.isIn(Minecraft.getInstance().player.getHeldItemMainhand()))
return; return;
boolean highlight = behaviour.testHit(target.getHitVec()); boolean highlight = behaviour.testHit(target.getHitVec());