Use cached directions

This commit is contained in:
Snownee 2020-12-10 09:36:59 +08:00
parent d9a59f704e
commit 77e9a75877
40 changed files with 102 additions and 77 deletions

View file

@ -18,6 +18,7 @@ import com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock;
import com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity;
import com.simibubi.create.content.contraptions.relays.gearbox.GearboxTileEntity;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -431,7 +432,7 @@ public class RotationPropagator {
.isAreaLoaded(te.getPos(), 1))
return neighbours;
for (Direction facing : Direction.values())
for (Direction facing : Iterate.directions)
neighbours.add(te.getPos()
.offset(facing));

View file

@ -1,5 +1,7 @@
package com.simibubi.create.content.contraptions.base;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext;
@ -26,7 +28,7 @@ public abstract class DirectionalKineticBlock extends KineticBlock {
public Direction getPreferredFacing(BlockItemUseContext context) {
Direction prefferedSide = null;
for (Direction side : Direction.values()) {
for (Direction side : Iterate.directions) {
BlockState blockState = context.getWorld()
.getBlockState(context.getPos()
.offset(side));

View file

@ -1,5 +1,7 @@
package com.simibubi.create.content.contraptions.base;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext;
@ -38,9 +40,7 @@ public abstract class HorizontalAxisKineticBlock extends KineticBlock {
public static Axis getPreferredHorizontalAxis(BlockItemUseContext context) {
Direction prefferedSide = null;
for (Direction side : Direction.values()) {
if (side.getAxis().isVertical())
continue;
for (Direction side : Iterate.horizontalDirections) {
BlockState blockState = context.getWorld().getBlockState(context.getPos().offset(side));
if (blockState.getBlock() instanceof IRotate) {
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getWorld(), context.getPos().offset(side),

View file

@ -1,5 +1,7 @@
package com.simibubi.create.content.contraptions.base;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext;
@ -40,7 +42,7 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock {
public static Axis getPreferredAxis(BlockItemUseContext context) {
Axis prefferedAxis = null;
for (Direction side : Direction.values()) {
for (Direction side : Iterate.directions) {
BlockState blockState = context.getWorld()
.getBlockState(context.getPos()
.offset(side));

View file

@ -14,6 +14,7 @@ import java.util.stream.Collectors;
import com.google.common.base.Predicates;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
@ -74,7 +75,7 @@ public class ConnectedInputHandler {
positions.remove(pos);
while (!frontier.isEmpty()) {
BlockPos current = frontier.remove(0);
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
BlockPos next = current.offset(direction);
if (!positions.remove(next))
continue;

View file

@ -9,6 +9,7 @@ import com.simibubi.create.content.contraptions.components.crafter.ConnectedInpu
import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity.Phase;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Pointing;
import com.simibubi.create.foundation.utility.VecHelper;
@ -109,7 +110,7 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IT
crafter.ejectWholeGrid();
}
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
if (direction.getAxis() == state.get(HORIZONTAL_FACING)
.getAxis())
continue;

View file

@ -16,6 +16,7 @@ import com.google.common.base.Predicates;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllRecipeTypes;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Pointing;
import net.minecraft.block.BlockState;
@ -109,7 +110,7 @@ public class RecipeGridHandler {
Direction blockFacing = blockState.get(HORIZONTAL_FACING);
Direction blockPointing = MechanicalCrafterBlock.getTargetDirection(blockState);
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
if (blockFacing.getAxis() == facing.getAxis())
continue;
if (blockPointing == facing)

View file

@ -7,6 +7,7 @@ import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
@ -52,9 +53,8 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock implements ITE
@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
for (Direction d : Direction.values()) {
if (d.getAxis() == state.get(AXIS) || d.getAxis()
.isVertical())
for (Direction d : Iterate.horizontalDirections) {
if (d.getAxis() == state.get(AXIS))
continue;
if (AllBlocks.CRUSHING_WHEEL_CONTROLLER.has(worldIn.getBlockState(pos.offset(d))))
worldIn.setBlockState(pos.offset(d), Blocks.AIR.getDefaultState());
@ -153,7 +153,7 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock implements ITE
@Override
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
BlockPos neighbourPos = pos.offset(direction);
BlockState neighbourState = worldIn.getBlockState(neighbourPos);
Axis stateAxis = state.get(AXIS);

View file

@ -7,6 +7,7 @@ import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -127,9 +128,7 @@ public class CrushingWheelControllerBlock extends Block
return;
}
for (Direction d : Direction.values()) {
if (d.getAxis().isVertical())
continue;
for (Direction d : Iterate.horizontalDirections) {
BlockState neighbour = world.getBlockState(pos.offset(d));
if (!AllBlocks.CRUSHING_WHEEL.has(neighbour))
continue;

View file

@ -1,6 +1,7 @@
package com.simibubi.create.content.contraptions.components.crusher;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.DamageSource;
@ -29,7 +30,7 @@ public class CrushingWheelTileEntity extends KineticTileEntity {
}
public void fixControllers() {
for (Direction d : Direction.values())
for (Direction d : Iterate.directions)
((CrushingWheelBlock) getBlockState().getBlock()).updateControllers(getBlockState(), getWorld(), getPos(),
d);
}

View file

@ -4,6 +4,7 @@ import javax.annotation.Nullable;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -75,9 +76,7 @@ public abstract class EngineBlock extends HorizontalBlock implements IWrenchable
BlockPos baseBlockPos = getBaseBlockPos(state, pos);
if (!isValidBaseBlock(world.getBlockState(baseBlockPos), world, pos))
return false;
for (Direction otherFacing : Direction.values()) {
if (otherFacing.getAxis().isVertical())
continue;
for (Direction otherFacing : Iterate.horizontalDirections) {
if (otherFacing == facing)
continue;
BlockPos otherPos = baseBlockPos.offset(otherFacing);

View file

@ -296,7 +296,7 @@ public abstract class Contraption {
// Slime blocks and super glue drag adjacent blocks if possible
boolean isSlimeBlock = state.getBlock() instanceof SlimeBlock;
for (Direction offset : Direction.values()) {
for (Direction offset : Iterate.directions) {
BlockPos offsetPos = pos.offset(offset);
BlockState blockState = world.getBlockState(offsetPos);
if (isAnchoringBlockAt(offsetPos))
@ -755,7 +755,7 @@ public abstract class Contraption {
continue;
if (nonBrittles)
for (Direction face : Direction.values())
for (Direction face : Iterate.directions)
state = state.updatePostPlacement(face, world.getBlockState(targetPos.offset(face)), world,
targetPos, targetPos.offset(face));

View file

@ -11,6 +11,7 @@ import com.simibubi.create.content.contraptions.components.structureMovement.cha
import com.simibubi.create.content.contraptions.relays.belt.BeltBlock;
import com.simibubi.create.content.contraptions.relays.belt.BeltSlope;
import com.simibubi.create.foundation.utility.DirectionHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.block.BellBlock;
@ -310,13 +311,13 @@ public class StructureTransform {
BlockState rotated = state.with(AXIS, transformAxis(state.get(AXIS)));
AbstractChassisBlock block = (AbstractChassisBlock) state.getBlock();
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
BooleanProperty glueableSide = block.getGlueableSide(rotated, face);
if (glueableSide != null)
rotated = rotated.with(glueableSide, false);
}
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
BooleanProperty glueableSide = block.getGlueableSide(state, face);
if (glueableSide == null || !state.get(glueableSide))
continue;

View file

@ -4,6 +4,7 @@ import com.simibubi.create.AllItems;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.BlockState;
import net.minecraft.block.RotatedPillarBlock;
@ -56,7 +57,7 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock implements
return ActionResultType.PASS;
if (isSlimeBall && state.get(affectedSide)) {
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
BooleanProperty glueableSide = getGlueableSide(state, face);
if (glueableSide != null && !state.get(glueableSide)) {
if (worldIn.isRemote) {
@ -95,13 +96,13 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock implements
return state;
BlockState rotated = super.rotate(state, rotation);
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
BooleanProperty glueableSide = getGlueableSide(rotated, face);
if (glueableSide != null)
rotated = rotated.with(glueableSide, false);
}
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
BooleanProperty glueableSide = getGlueableSide(state, face);
if (glueableSide == null || !state.get(glueableSide))
continue;
@ -120,13 +121,13 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock implements
return state;
BlockState mirrored = state;
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
BooleanProperty glueableSide = getGlueableSide(mirrored, face);
if (glueableSide != null)
mirrored = mirrored.with(glueableSide, false);
}
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
BooleanProperty glueableSide = getGlueableSide(state, face);
if (glueableSide == null || !state.get(glueableSide))
continue;

View file

@ -17,6 +17,7 @@ import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.CenteredSideValueBoxTransform;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.BulkScrollValueBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueBehaviour;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Lang;
import net.minecraft.block.BlockState;
@ -122,7 +123,7 @@ public class ChassisTileEntity extends SmartTileEntity {
}
// Collect group of connected linear chassis
for (Direction offset : Direction.values()) {
for (Direction offset : Iterate.directions) {
if (offset.getAxis() == axis)
continue;
BlockPos current = pos.offset(offset);
@ -187,7 +188,7 @@ public class ChassisTileEntity extends SmartTileEntity {
AbstractChassisBlock block = (AbstractChassisBlock) state.getBlock();
int chassisRange = visualize ? range.scrollableValue : getRange();
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
if (facing.getAxis() == axis)
continue;
if (!state.get(block.getGlueableSide(state, facing)))
@ -215,7 +216,7 @@ public class ChassisTileEntity extends SmartTileEntity {
if (!searchPos.equals(pos))
positions.add(searchPos);
for (Direction offset : Direction.values()) {
for (Direction offset : Iterate.directions) {
if (offset.getAxis() == axis)
continue;
if (searchPos.equals(pos) && offset != facing)

View file

@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock;
import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
import net.minecraft.block.BlockRenderType;
@ -42,7 +43,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
@Override
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
BlockPos neighbourPos = pos.offset(direction);
BlockState neighbourState = worldIn.getBlockState(neighbourPos);
if (!AllBlocks.WATER_WHEEL.has(neighbourState))
@ -75,7 +76,7 @@ public class WaterWheelBlock extends HorizontalKineticBlock implements ITE<Water
}
public void updateAllSides(BlockState state, World worldIn, BlockPos pos) {
for (Direction d : Direction.values())
for (Direction d : Iterate.directions)
updateFlowAt(state, worldIn, pos, d);
updateWheelSpeed(worldIn, pos);
}

View file

@ -6,6 +6,7 @@ import java.util.Map;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntityType;
@ -19,7 +20,7 @@ public class WaterWheelTileEntity extends GeneratingKineticTileEntity {
public WaterWheelTileEntity(TileEntityType<? extends WaterWheelTileEntity> type) {
super(type);
flows = new HashMap<>();
for (Direction d : Direction.values())
for (Direction d : Iterate.directions)
setFlow(d, 0);
setLazyTickRate(20);
}
@ -28,7 +29,7 @@ public class WaterWheelTileEntity extends GeneratingKineticTileEntity {
protected void read(CompoundNBT compound, boolean clientPacket) {
super.read(compound, clientPacket);
if (compound.contains("Flows")) {
for (Direction d : Direction.values())
for (Direction d : Iterate.directions)
setFlow(d, compound.getCompound("Flows")
.getFloat(d.getName()));
}
@ -42,7 +43,7 @@ public class WaterWheelTileEntity extends GeneratingKineticTileEntity {
@Override
public void write(CompoundNBT compound, boolean clientPacket) {
CompoundNBT flows = new CompoundNBT();
for (Direction d : Direction.values())
for (Direction d : Iterate.directions)
flows.putFloat(d.getName(), this.flows.get(d));
compound.put("Flows", flows);

View file

@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -55,7 +56,7 @@ public class CogWheelBlock extends AbstractShaftBlock {
@Override
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
if (facing.getAxis() == state.get(AXIS))
continue;

View file

@ -4,6 +4,7 @@ import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Lang;
import net.minecraft.block.Block;
@ -62,7 +63,7 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
axis = placedAxis;
BlockState state = getDefaultState().with(AXIS, axis);
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
if (facing.getAxis() == axis)
continue;
BlockPos pos = context.getPos();
@ -130,7 +131,7 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock {
.updateNeighbors(context.getWorld(), context.getPos(), 1);
Axis axis = newState.get(AXIS);
newState = getDefaultState().with(AXIS, axis);
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
if (facing.getAxis() == axis)
continue;
BlockPos pos = context.getPos();

View file

@ -6,6 +6,7 @@ import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import net.minecraft.block.Block;
@ -30,7 +31,7 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer {
final BlockPos pos = te.getPos();
float time = AnimationTickHolder.getRenderTick();
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
Axis axis = direction.getAxis();
if (boxAxis != axis)
continue;

View file

@ -6,6 +6,7 @@ import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
@ -143,7 +144,7 @@ public class GaugeBlock extends DirectionalAxisKineticBlock {
return;
int color = gaugeTE.color;
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
if (!shouldRenderHeadOnFace(worldIn, pos, stateIn, face))
continue;

View file

@ -6,6 +6,7 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.content.contraptions.relays.gauge.GaugeBlock.Type;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import net.minecraft.block.BlockState;
@ -46,7 +47,7 @@ public class GaugeRenderer extends KineticTileEntityRenderer {
.renderOn(gaugeState);
SuperByteBuffer dialBuffer = AllBlockPartials.GAUGE_DIAL.renderOn(gaugeState);
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
if (!((GaugeBlock) gaugeState.getBlock()).shouldRenderHeadOnFace(te.getWorld(), te.getPos(), gaugeState,
facing))
continue;

View file

@ -5,6 +5,7 @@ import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import net.minecraft.client.renderer.IRenderTypeBuffer;
@ -28,7 +29,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer {
final BlockPos pos = te.getPos();
float time = AnimationTickHolder.getRenderTick();
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
final Axis axis = direction.getAxis();
if (boxAxis == axis)
continue;

View file

@ -4,6 +4,7 @@ import java.util.Map;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -41,10 +42,7 @@ public class VerticalGearboxItem extends BlockItem {
@Override
protected boolean onBlockPlaced(BlockPos pos, World world, PlayerEntity player, ItemStack stack, BlockState state) {
Axis prefferedAxis = null;
for (Direction side : Direction.values()) {
if (side.getAxis()
.isVertical())
continue;
for (Direction side : Iterate.horizontalDirections) {
BlockState blockState = world.getBlockState(pos.offset(side));
if (blockState.getBlock() instanceof IRotate) {
if (((IRotate) blockState.getBlock()).hasShaftTowards(world, pos.offset(side), blockState,

View file

@ -15,6 +15,7 @@ import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.foundation.networking.AllPackets;
import com.simibubi.create.foundation.utility.BlockHelper;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -207,7 +208,7 @@ public class SymmetryWandItem extends Item {
if (world.canPlace(block, position, ISelectionContext.forEntity(player))) {
BlockState blockState = blockSet.get(position);
for (Direction face : Direction.values())
for (Direction face : Iterate.directions)
blockState = blockState.updatePostPlacement(face, world.getBlockState(position.offset(face)), world,
position, position.offset(face));

View file

@ -137,11 +137,11 @@ public abstract class ZapperItem extends Item {
player.setActiveHand(hand);
// Check if can be used
String msg = validateUsage(item);
ITextComponent msg = validateUsage(item);
if (msg != null) {
world.playSound(player, player.getPosition(), AllSoundEvents.BLOCKZAPPER_DENY.get(), SoundCategory.BLOCKS,
1f, 0.5f);
player.sendStatusMessage(new StringTextComponent(TextFormatting.RED + msg), true);
player.sendStatusMessage(msg.applyTextStyle(TextFormatting.RED), true);
return new ActionResult<ItemStack>(ActionResultType.FAIL, item);
}
@ -192,10 +192,10 @@ public abstract class ZapperItem extends Item {
return new ActionResult<ItemStack>(ActionResultType.SUCCESS, item);
}
public String validateUsage(ItemStack item) {
public ITextComponent validateUsage(ItemStack item) {
CompoundNBT tag = item.getOrCreateTag();
if (!canActivateWithoutSelectedBlock(item) && !tag.contains("BlockUsed"))
return Lang.translate("blockzapper.leftClickToSet");
return Lang.createTranslationTextComponent("blockzapper.leftClickToSet");
return null;
}

View file

@ -15,6 +15,7 @@ import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.foundation.item.ItemDescription;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.simibubi.create.foundation.utility.BlockHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.NBTHelper;
@ -47,6 +48,7 @@ import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.common.util.Constants.BlockFlags;
import net.minecraftforge.event.ForgeEventFactory;
public class BlockzapperItem extends ZapperItem {
@ -92,6 +94,7 @@ public class BlockzapperItem extends ZapperItem {
items.add(gunWithPurpurStuff);
}
@Override
protected boolean activate(World world, PlayerEntity player, ItemStack stack, BlockState selectedState,
BlockRayTraceResult raytrace) {
CompoundNBT nbt = stack.getOrCreateTag();
@ -119,13 +122,13 @@ public class BlockzapperItem extends ZapperItem {
if (!player.isCreative() && replace)
dropBlocks(world, player, stack, face, placed);
for (Direction updateDirection : Direction.values())
for (Direction updateDirection : Iterate.directions)
selectedState = selectedState.updatePostPlacement(updateDirection,
world.getBlockState(placed.offset(updateDirection)), world, placed, placed.offset(updateDirection));
BlockSnapshot blocksnapshot = BlockSnapshot.getBlockSnapshot(world, placed);
IFluidState ifluidstate = world.getFluidState(placed);
world.setBlockState(placed, ifluidstate.getBlockState(), 18);
world.setBlockState(placed, ifluidstate.getBlockState(), BlockFlags.UPDATE_NEIGHBORS);
world.setBlockState(placed, selectedState);
if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP)) {
blocksnapshot.restore(true, false);

View file

@ -16,6 +16,7 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -43,10 +44,10 @@ public class WorldshaperItem extends ZapperItem {
}
@Override
public String validateUsage(ItemStack item) {
public ITextComponent validateUsage(ItemStack item) {
if (!item.getOrCreateTag()
.contains("BrushParams"))
return Lang.translate("terrainzapper.shiftRightClickToSet");
return Lang.createTranslationTextComponent("terrainzapper.shiftRightClickToSet");
return super.validateUsage(item);
}

View file

@ -5,6 +5,7 @@ import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.foundation.tileEntity.renderer.SmartTileEntityRenderer;
import com.simibubi.create.foundation.utility.AngleHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.MatrixStacker;
import com.simibubi.create.foundation.utility.SuperByteBuffer;
import com.simibubi.create.foundation.utility.VecHelper;
@ -32,7 +33,7 @@ public class BeltTunnelRenderer extends SmartTileEntityRenderer<BeltTunnelTileEn
Vec3d pivot = VecHelper.voxelSpace(0, 10, 1f);
MatrixStacker msr = MatrixStacker.of(ms);
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
if (!te.flaps.containsKey(direction))
continue;

View file

@ -109,10 +109,7 @@ public class BeltTunnelTileEntity extends SmartTileEntity {
public void updateTunnelConnections() {
flaps.clear();
BlockState tunnelState = getBlockState();
for (Direction direction : Direction.values()) {
if (direction.getAxis()
.isVertical())
continue;
for (Direction direction : Iterate.horizontalDirections) {
BlockState blockState = world.getBlockState(pos.offset(direction));
if (blockState.getBlock() instanceof BeltTunnelBlock)
continue;

View file

@ -3,6 +3,8 @@ package com.simibubi.create.content.logistics.block.inventories;
import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext;
@ -62,7 +64,7 @@ public class CrateBlock extends ProperDirectionalBlock implements IWrenchable {
if (context.getPlayer() == null || !context.getPlayer()
.isSneaking()) {
for (Direction d : Direction.values()) {
for (Direction d : Iterate.directions) {
BlockState state = world.getBlockState(pos.offset(d));
if (state.getBlock() == this && !state.get(DOUBLE))
return getDefaultState().with(FACING, d)

View file

@ -6,6 +6,7 @@ import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -115,11 +116,7 @@ public class StockpileSwitchBlock extends HorizontalBlock implements ITE<Stockpi
BlockState state = getDefaultState();
Direction preferredFacing = null;
for (Direction face : Direction.values()) {
if (face.getAxis()
.isVertical())
continue;
for (Direction face : Iterate.horizontalDirections) {
TileEntity te = context.getWorld()
.getTileEntity(context.getPos()
.offset(face));

View file

@ -23,6 +23,7 @@ import com.simibubi.create.foundation.item.ItemHelper.ExtractionCountMode;
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.utility.BlockHelper;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -143,7 +144,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC
public void findInventories() {
hasCreativeCrate = false;
attachedInventories.clear();
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
if (!world.isBlockPresent(pos.offset(facing)))
continue;

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Random;
import com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour.CTContext;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -54,7 +55,7 @@ public class CTModel extends BakedModelWrapperWithData {
protected CTData createCTData(ILightReader world, BlockPos pos, BlockState state) {
CTData data = new CTData();
for (Direction face : Direction.values()) {
for (Direction face : Iterate.directions) {
if (!Block.shouldSideBeRendered(state, world, pos, face) && !behaviour.buildContextForOccludedDirections())
continue;
CTSpriteShiftEntry spriteShift = behaviour.get(state, face);

View file

@ -2,6 +2,8 @@ package com.simibubi.create.foundation.entity;
import java.util.Optional;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.IDataSerializer;
@ -19,7 +21,7 @@ public class CreateDataSerializers {
public Optional<Direction> read(PacketBuffer buffer) {
int i = buffer.readVarInt();
return i == 0 ? Optional.empty() : Optional.of(Direction.values()[i - 1]);
return i == 0 ? Optional.empty() : Optional.of(Iterate.directions[i - 1]);
}
public Optional<Direction> copyValue(Optional<Direction> opt) {

View file

@ -5,6 +5,7 @@ import java.util.Random;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.simibubi.create.foundation.renderState.RenderTypes;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft;
@ -81,7 +82,7 @@ public class PartialItemModelRenderer {
Random random = new Random();
IModelData data = EmptyModelData.INSTANCE;
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
random.setSeed(42L);
ir.renderBakedItemQuads(ms, p_229114_6_, model.getQuads((BlockState) null, direction, random, data), stack,
light, overlay);

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.RaycastHelper;
import net.minecraft.block.Block;
@ -64,7 +65,7 @@ public class EdgeInteractionHandler {
if (Block.hasSolidSide(world.getBlockState(pos.offset(face)), world, pos.offset(face), face.getOpposite()))
return sides;
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
if (direction.getAxis() == face.getAxis())
continue;
BlockPos neighbourPos = pos.offset(direction);

View file

@ -124,7 +124,7 @@ public class TreeCutter {
leaves.add(currentPos);
int distance = isLog ? 0 : blockState.get(LeavesBlock.DISTANCE);
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
BlockPos offset = currentPos.offset(direction);
if (visited.contains(offset))
continue;
@ -182,7 +182,7 @@ public class TreeCutter {
if (!lowerLayer && !pos.equals(currentPos.down()) && isLog(reader.getBlockState(currentPos.down())))
return false;
for (Direction direction : Direction.values()) {
for (Direction direction : Iterate.directions) {
if (direction == Direction.DOWN)
continue;
if (direction == Direction.UP && !lowerLayer)

View file

@ -36,7 +36,7 @@ public class VoxelShaper {
}
public static VoxelShaper forDirectional(VoxelShape shape, Direction facing){
return forDirectionsWithRotation(shape, facing, Arrays.asList(Direction.values()), new DefaultRotationValues());
return forDirectionsWithRotation(shape, facing, Arrays.asList(Iterate.directions), new DefaultRotationValues());
}
public static VoxelShaper forAxis(VoxelShape shape, Axis along){

View file

@ -6,6 +6,7 @@ import java.util.Random;
import com.simibubi.create.content.curiosities.tools.SandPaperItem;
import com.simibubi.create.content.palettes.MetalBlock;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -54,7 +55,7 @@ public class OxidizingBlock extends MetalBlock {
int currentState = state.get(OXIDIZATION);
boolean canIncrease = false;
LinkedList<Integer> neighbors = new LinkedList<>();
for (Direction facing : Direction.values()) {
for (Direction facing : Iterate.directions) {
BlockPos neighbourPos = pos.offset(facing);
if (!worldIn.isAreaLoaded(neighbourPos, 0))
continue;