mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 23:23:40 +01:00
Cogwheel refactor Part III
- Removed the calls to the AllBlocks entries where necessary - Made placement helpers call the same code as CogWheelBlock.isValidPosition
This commit is contained in:
parent
7b022cd302
commit
1bffb82ae4
6 changed files with 83 additions and 55 deletions
|
@ -1,6 +1,16 @@
|
|||
package com.simibubi.create.content.contraptions.relays.advanced;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.CogwheelBlockItem;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
|
||||
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
|
||||
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -19,18 +29,11 @@ import net.minecraft.util.math.shapes.VoxelShape;
|
|||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.function.Predicate;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.AllTileEntities;
|
||||
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.CogwheelBlockItem;
|
||||
import com.simibubi.create.foundation.block.ITE;
|
||||
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
|
||||
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
|
||||
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements ITE<SpeedControllerTileEntity> {
|
||||
|
||||
private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());
|
||||
|
@ -83,7 +86,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
|
|||
private static class PlacementHelper implements IPlacementHelper {
|
||||
@Override
|
||||
public Predicate<ItemStack> getItemPredicate() {
|
||||
return AllBlocks.LARGE_COGWHEEL::isIn;
|
||||
return ((Predicate<ItemStack>) ICogWheel::isLargeCogItem).and(ICogWheel::isDedicatedCogItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,8 +104,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
|
|||
|
||||
Axis newAxis = state.get(HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X;
|
||||
|
||||
if (CogwheelBlockItem.hasLargeCogwheelNeighbor(world, newPos, newAxis)
|
||||
|| CogwheelBlockItem.hasSmallCogwheelNeighbor(world, newPos, newAxis))
|
||||
if (!CogWheelBlock.isValidCogwheelPosition(true, world, newPos, newAxis))
|
||||
return PlacementOffset.fail();
|
||||
|
||||
return PlacementOffset.success(newPos, s -> s.with(CogWheelBlock.AXIS, newAxis));
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.RotationPropagator;
|
|||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.components.motor.CreativeMotorTileEntity;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
|
||||
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform;
|
||||
|
@ -118,8 +119,8 @@ public class SpeedControllerTileEntity extends KineticTileEntity {
|
|||
if (world == null || !world.isRemote)
|
||||
return;
|
||||
BlockState stateAbove = world.getBlockState(pos.up());
|
||||
hasBracket = AllBlocks.LARGE_COGWHEEL.has(stateAbove) && stateAbove.get(CogWheelBlock.AXIS)
|
||||
.isHorizontal();
|
||||
hasBracket = ICogWheel.isDedicatedCogWheel(stateAbove.getBlock()) && ICogWheel.isLargeCog(stateAbove)
|
||||
&& stateAbove.get(CogWheelBlock.AXIS).isHorizontal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,8 +59,12 @@ public class CogWheelBlock extends AbstractShaftBlock implements ICogWheel {
|
|||
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
|
||||
return isValidCogwheelPosition(ICogWheel.isLargeCog(state), worldIn, pos, state.get(AXIS));
|
||||
}
|
||||
|
||||
public static boolean isValidCogwheelPosition(boolean large, IWorldReader worldIn, BlockPos pos, Axis cogAxis) {
|
||||
for (Direction facing : Iterate.directions) {
|
||||
if (facing.getAxis() == state.get(AXIS))
|
||||
if (facing.getAxis() == cogAxis)
|
||||
continue;
|
||||
|
||||
BlockPos offsetPos = pos.offset(facing);
|
||||
|
@ -68,7 +72,7 @@ public class CogWheelBlock extends AbstractShaftBlock implements ICogWheel {
|
|||
if (blockState.has(AXIS) && facing.getAxis() == blockState.get(AXIS))
|
||||
continue;
|
||||
|
||||
if (ICogWheel.isLargeCog(blockState) || isLargeCog() && ICogWheel.isSmallCog(blockState))
|
||||
if (ICogWheel.isLargeCog(blockState) || large && ICogWheel.isSmallCog(blockState))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -112,4 +116,9 @@ public class CogWheelBlock extends AbstractShaftBlock implements ICogWheel {
|
|||
public float getParticleInitialRadius() {
|
||||
return isLargeCog() ? 1f : .75f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDedicatedCogWheel() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.world.World;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.AllShapes;
|
||||
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
||||
import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock;
|
||||
|
@ -99,7 +98,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
continue;
|
||||
if (blockState.get(CogWheelBlock.AXIS) != axis)
|
||||
continue;
|
||||
if (AllBlocks.LARGE_COGWHEEL.has(blockState) == large)
|
||||
if (ICogWheel.isLargeCog(blockState) == large)
|
||||
continue;
|
||||
AllTriggers.triggerFor(AllTriggers.SHIFTING_GEARS, player);
|
||||
}
|
||||
|
@ -113,7 +112,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
|
||||
@Override
|
||||
public Predicate<ItemStack> getItemPredicate() {
|
||||
return AllBlocks.COGWHEEL::isIn;
|
||||
return ((Predicate<ItemStack>) ICogWheel::isSmallCogItem).and(ICogWheel::isDedicatedCogItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,7 +127,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
for (Direction dir : directions) {
|
||||
BlockPos newPos = pos.offset(dir);
|
||||
|
||||
if (hasLargeCogwheelNeighbor(world, newPos, state.get(AXIS)))
|
||||
if (!CogWheelBlock.isValidCogwheelPosition(false, world, newPos, state.get(AXIS)))
|
||||
continue;
|
||||
|
||||
if (!world.getBlockState(newPos)
|
||||
|
@ -152,7 +151,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
|
||||
@Override
|
||||
public Predicate<ItemStack> getItemPredicate() {
|
||||
return AllBlocks.LARGE_COGWHEEL::isIn;
|
||||
return ((Predicate<ItemStack>) ICogWheel::isLargeCogItem).and(ICogWheel::isDedicatedCogItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -169,7 +168,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
BlockPos newPos = pos.offset(dir)
|
||||
.offset(side);
|
||||
|
||||
if (hasLargeCogwheelNeighbor(world, newPos, dir.getAxis()) || hasSmallCogwheelNeighbor(world, newPos, dir.getAxis()))
|
||||
if (!CogWheelBlock.isValidCogwheelPosition(true, world, newPos, dir.getAxis()))
|
||||
continue;
|
||||
|
||||
if (!world.getBlockState(newPos)
|
||||
|
@ -211,7 +210,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
.isReplaceable())
|
||||
continue;
|
||||
|
||||
if (AllBlocks.COGWHEEL.has(state) && hasSmallCogwheelNeighbor(world, newPos, state.get(AXIS)))
|
||||
if (!CogWheelBlock.isValidCogwheelPosition(ICogWheel.isLargeCog(state), world, newPos, state.get(AXIS)))
|
||||
continue;
|
||||
|
||||
return PlacementOffset.success(newPos, s -> s.with(AXIS, state.get(AXIS)));
|
||||
|
@ -235,12 +234,12 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
|
||||
@Override
|
||||
public Predicate<ItemStack> getItemPredicate() {
|
||||
return AllBlocks.LARGE_COGWHEEL::isIn;
|
||||
return ((Predicate<ItemStack>) ICogWheel::isLargeCogItem).and(ICogWheel::isDedicatedCogItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<BlockState> getStatePredicate() {
|
||||
return s -> !AllBlocks.COGWHEEL.has(s) && ICogWheel.isSmallCog(s);
|
||||
return s -> !ICogWheel.isDedicatedCogWheel(s.getBlock()) && ICogWheel.isSmallCog(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -272,8 +271,7 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
.isReplaceable())
|
||||
continue;
|
||||
|
||||
if (hasLargeCogwheelNeighbor(world, newPos, newAxis)
|
||||
|| hasSmallCogwheelNeighbor(world, newPos, newAxis))
|
||||
if (!CogWheelBlock.isValidCogwheelPosition(false, world, newPos, newAxis))
|
||||
return PlacementOffset.fail();
|
||||
|
||||
return PlacementOffset.success(newPos, s -> s.with(CogWheelBlock.AXIS, newAxis));
|
||||
|
@ -283,27 +281,4 @@ public class CogwheelBlockItem extends BlockItem {
|
|||
}
|
||||
|
||||
}
|
||||
public static boolean hasLargeCogwheelNeighbor(World world, BlockPos pos, Axis axis) {
|
||||
for (Direction dir : Iterate.directions) {
|
||||
if (dir.getAxis() == axis)
|
||||
continue;
|
||||
|
||||
if (AllBlocks.LARGE_COGWHEEL.has(world.getBlockState(pos.offset(dir))))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hasSmallCogwheelNeighbor(World world, BlockPos pos, Axis axis) {
|
||||
for (Direction dir : Iterate.directions) {
|
||||
if (dir.getAxis() == axis)
|
||||
continue;
|
||||
|
||||
if (AllBlocks.COGWHEEL.has(world.getBlockState(pos.offset(dir))))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,53 @@
|
|||
package com.simibubi.create.content.contraptions.relays.elementary;
|
||||
|
||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface ICogWheel extends IRotate {
|
||||
|
||||
static boolean isSmallCog(BlockState state) {
|
||||
return state.getBlock() instanceof ICogWheel && ((ICogWheel) state.getBlock()).isSmallCog();
|
||||
return isSmallCog(state.getBlock());
|
||||
}
|
||||
|
||||
static boolean isLargeCog(BlockState state) {
|
||||
return state.getBlock() instanceof ICogWheel && ((ICogWheel) state.getBlock()).isLargeCog();
|
||||
return isLargeCog(state.getBlock());
|
||||
}
|
||||
|
||||
static boolean isSmallCog(Block block) {
|
||||
return block instanceof ICogWheel && ((ICogWheel) block).isSmallCog();
|
||||
}
|
||||
|
||||
static boolean isLargeCog(Block block) {
|
||||
return block instanceof ICogWheel && ((ICogWheel) block).isLargeCog();
|
||||
}
|
||||
|
||||
static boolean isDedicatedCogWheel(Block block) {
|
||||
return block instanceof ICogWheel && ((ICogWheel) block).isDedicatedCogWheel();
|
||||
}
|
||||
|
||||
static boolean isDedicatedCogItem(ItemStack test) {
|
||||
Item item = test.getItem();
|
||||
if (!(item instanceof BlockItem))
|
||||
return false;
|
||||
return isDedicatedCogWheel(((BlockItem) item).getBlock());
|
||||
}
|
||||
|
||||
static boolean isSmallCogItem(ItemStack test) {
|
||||
Item item = test.getItem();
|
||||
if (!(item instanceof BlockItem))
|
||||
return false;
|
||||
return isSmallCog(((BlockItem) item).getBlock());
|
||||
}
|
||||
|
||||
static boolean isLargeCogItem(ItemStack test) {
|
||||
Item item = test.getItem();
|
||||
if (!(item instanceof BlockItem))
|
||||
return false;
|
||||
return isLargeCog(((BlockItem) item).getBlock());
|
||||
}
|
||||
|
||||
default boolean isLargeCog() {
|
||||
|
@ -19,4 +57,8 @@ public interface ICogWheel extends IRotate {
|
|||
default boolean isSmallCog() {
|
||||
return !isLargeCog();
|
||||
}
|
||||
|
||||
default boolean isDedicatedCogWheel() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.relays.elementary;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.foundation.advancement.AllTriggers;
|
||||
|
@ -34,7 +33,7 @@ public class SimpleKineticTileEntity extends KineticTileEntity {
|
|||
|
||||
@Override
|
||||
public List<BlockPos> addPropagationLocations(IRotate block, BlockState state, List<BlockPos> neighbours) {
|
||||
if (!AllBlocks.LARGE_COGWHEEL.has(state))
|
||||
if (!ICogWheel.isLargeCog(state))
|
||||
return super.addPropagationLocations(block, state, neighbours);
|
||||
|
||||
BlockPos.getAllInBox(new BlockPos(-1, -1, -1), new BlockPos(1, 1, 1))
|
||||
|
|
Loading…
Reference in a new issue