Skip to content

Commit

Permalink
more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 12, 2021
1 parent 3789f4b commit 308d436
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gregtech.api.multiblock.PatternMatchContext;
import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeMap;
import gregtech.common.ConfigHolder;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.Style;
Expand All @@ -23,6 +24,8 @@

public abstract class RecipeMapSteamMultiblockController extends MultiblockWithDisplayBase {

protected static final double CONVERSION_RATE = ConfigHolder.U.multiblockSteamToEU;

public final RecipeMap<?> recipeMap;
protected SteamMultiblockRecipeLogic recipeMapWorkable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@ZenClass("mods.gregtech.item.ItemRegistry")
@ZenRegister
@SuppressWarnings("unused")
public class CTItemUtils {
public class CTItemRegistry {

@ZenMethod("registerItem")
public static void registerItem(String name, short id, int rgb, String materialIconSet, String orePrefix) {
Expand Down
24 changes: 1 addition & 23 deletions src/main/java/gregtech/api/multiblock/BlockPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import gregtech.api.util.IntRange;
import gregtech.api.util.RelativeDirection;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
Expand Down Expand Up @@ -197,27 +198,4 @@ private MutableBlockPos setActualRelativeOffset(MutableBlockPos pos, int x, int
}
return pos.setPos(c1[0], c1[1], c1[2]);
}

/**
* Relative direction when facing horizontally
*/
public enum RelativeDirection {
UP(f -> EnumFacing.UP),
DOWN(f -> EnumFacing.DOWN),
LEFT(EnumFacing::rotateYCCW),
RIGHT(EnumFacing::rotateY),
FRONT(Function.identity()),
BACK(EnumFacing::getOpposite);

final Function<EnumFacing, EnumFacing> actualFacing;

RelativeDirection(Function<EnumFacing, EnumFacing> actualFacing) {
this.actualFacing = actualFacing;
}

public EnumFacing getActualFacing(EnumFacing facing) {
return actualFacing.apply(facing);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.common.base.Joiner;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import gregtech.api.multiblock.BlockPattern.RelativeDirection;
import gregtech.api.util.RelativeDirection;
import gregtech.api.util.IntRange;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -17,7 +17,7 @@
import java.util.Map.Entry;
import java.util.function.Predicate;

import static gregtech.api.multiblock.BlockPattern.RelativeDirection.*;
import static gregtech.api.util.RelativeDirection.*;

public class FactoryBlockPattern {

Expand Down
70 changes: 0 additions & 70 deletions src/main/java/gregtech/api/util/DirectionHelper.java

This file was deleted.

36 changes: 36 additions & 0 deletions src/main/java/gregtech/api/util/RelativeDirection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gregtech.api.util;

import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3i;

import java.util.function.Function;

/**
* Relative direction when facing horizontally
*/
public enum RelativeDirection {
UP(f -> EnumFacing.UP),
DOWN(f -> EnumFacing.DOWN),
LEFT(EnumFacing::rotateYCCW),
RIGHT(EnumFacing::rotateY),
FRONT(Function.identity()),
BACK(EnumFacing::getOpposite);

final Function<EnumFacing, EnumFacing> actualFacing;

RelativeDirection(Function<EnumFacing, EnumFacing> actualFacing) {
this.actualFacing = actualFacing;
}

public EnumFacing getActualFacing(EnumFacing facing) {
return actualFacing.apply(facing);
}

public EnumFacing apply(EnumFacing facing) {
return actualFacing.apply(facing);
}

public Vec3i applyVec3i(EnumFacing facing) {
return apply(facing).getDirectionVec();
}
}
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/util/function/Task.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.api.util.function;

@FunctionalInterface
public interface Task {

boolean run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.ResourceLocation;

import static gregtech.api.multiblock.BlockPattern.RelativeDirection.*;
import static gregtech.api.util.RelativeDirection.*;

public class MetaTileEntityAssemblyLine extends RecipeMapMultiblockController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.List;
import java.util.function.Predicate;

import static gregtech.api.multiblock.BlockPattern.RelativeDirection.*;
import static gregtech.api.util.RelativeDirection.*;

public class MetaTileEntityDistillationTower extends RecipeMapMultiblockController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import java.util.List;

import static gregtech.api.multiblock.BlockPattern.RelativeDirection.*;
import static gregtech.api.util.RelativeDirection.*;

public class MetaTileEntityFusionReactor extends RecipeMapMultiblockController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

public class MetaTileEntitySteamGrinder extends RecipeMapSteamMultiblockController {

private static final double CONVERSION_RATE = ConfigHolder.U.multiblockSteamToEU;

private static final MultiblockAbility<?>[] ALLOWED_ABILITIES = {
MultiblockAbility.STEAM_IMPORT_ITEMS, MultiblockAbility.STEAM_EXPORT_ITEMS, MultiblockAbility.STEAM
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

public class MetaTileEntitySteamOven extends RecipeMapSteamMultiblockController {

private static final double CONVERSION_RATE = ConfigHolder.U.multiblockSteamToEU;
private boolean isActive;

public MetaTileEntitySteamOven(ResourceLocation metaTileEntityId) {
Expand Down
40 changes: 24 additions & 16 deletions src/main/java/gregtech/common/tools/largedrills/ToolDrillLarge.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import gregtech.api.capability.IElectricItem;
import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.items.toolitem.ToolMetaItem;
import gregtech.api.util.DirectionHelper;
import gregtech.api.util.GTUtility;
import gregtech.api.util.RelativeDirection;
import gregtech.common.items.behaviors.ModeSwitchBehavior;
import gregtech.common.tools.ToolBase;
import net.minecraft.block.material.Material;
Expand Down Expand Up @@ -137,7 +137,7 @@ private List<BlockPos> getAOEBlocks(int max, EntityPlayer player, BlockPos hitPo
Vec3d lookVec = player.getLookVec();
EnumFacing facing = EnumFacing.getFacingFromVector((float) lookVec.x, (float) lookVec.y, (float) lookVec.z);
BlockPos corner = findCorner(max, hitPos, player, facing);
BlockPos oppositeCorner = findOppositeCorner(max, corner, player);
BlockPos oppositeCorner = findOppositeCorner(max, corner, facing);

List<BlockPos> posList = Lists.newArrayList(BlockPos.getAllInBox(corner, oppositeCorner));
return posList.stream()
Expand All @@ -155,22 +155,22 @@ private List<BlockPos> getAOEBlocks(int max, EntityPlayer player, BlockPos hitPo
* Returns the relative bottom left closest corner of the possible mining area for the drill.
*/
private static BlockPos findCorner(int max, BlockPos startPos, EntityPlayer player, EnumFacing facing) {
Vec3i leftVec = DirectionHelper.getRelativeLeft(player).getDirectionVec();
Vec3i downVec = DirectionHelper.getRelativeDown(player).getDirectionVec();
Vec3i leftVec = RelativeDirection.LEFT.applyVec3i(facing);
Vec3i downVec = RelativeDirection.DOWN.applyVec3i(facing);
switch (facing) {
case UP:
case DOWN:
// treat up and down as standard cube. just acquire leftmost corner, ignoring floor level
return startPos
.add(DirectionHelper.multiplyVec(leftVec, max / 2))
.add(DirectionHelper.multiplyVec(downVec, max / 2));
.add(multiplyVec(leftVec, max / 2))
.add(multiplyVec(downVec, max / 2));
default:
// try to find lowest pos
Vec3i towardsVec = DirectionHelper.getRelativeForward(player).getDirectionVec();
Vec3i towardsVec = RelativeDirection.FRONT.applyVec3i(facing);

// Find the relative downwards offset
for (int i = 1; i <= max; i++) {
BlockPos currentPos = startPos.add(DirectionHelper.multiplyVec(downVec, i));
BlockPos currentPos = startPos.add(multiplyVec(downVec, i));

BlockPos forwardPos = currentPos.add(towardsVec);
IBlockState state = player.world.getBlockState(forwardPos);
Expand All @@ -181,19 +181,27 @@ private static BlockPos findCorner(int max, BlockPos startPos, EntityPlayer play
}

// Find the relative leftmost BlockPos
return startPos.add(DirectionHelper.multiplyVec(leftVec, max / 2));
return startPos.add(multiplyVec(leftVec, max / 2));
}
}

private static BlockPos findOppositeCorner(int max, BlockPos corner, EntityPlayer player) {
Vec3i rightVec = DirectionHelper.getRelativeRight(player).getDirectionVec();
Vec3i forwardVec = DirectionHelper.getRelativeForward(player).getDirectionVec();
Vec3i upVec = DirectionHelper.getRelativeUp(player).getDirectionVec();
private static BlockPos findOppositeCorner(int max, BlockPos corner, EnumFacing facing) {
Vec3i rightVec = RelativeDirection.RIGHT.applyVec3i(facing);
Vec3i forwardVec = RelativeDirection.FRONT.applyVec3i(facing);
Vec3i upVec = RelativeDirection.UP.applyVec3i(facing);

return corner
.add(DirectionHelper.multiplyVec(rightVec, max - 1))
.add(DirectionHelper.multiplyVec(forwardVec, max - 1))
.add(DirectionHelper.multiplyVec(upVec, max - 1));
.add(multiplyVec(rightVec, max - 1))
.add(multiplyVec(forwardVec, max - 1))
.add(multiplyVec(upVec, max - 1));
}

private static Vec3i multiplyVec(Vec3i start, int multiplier) {
return new Vec3i(
start.getX() * multiplier,
start.getY() * multiplier,
start.getZ() * multiplier
);
}

@Override
Expand Down

0 comments on commit 308d436

Please sign in to comment.