mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 00:16:27 +01:00
add a missing placement helper
- for placing small cogs against integrated cog wheels
This commit is contained in:
parent
3c4e504f61
commit
dc6baae0ea
2 changed files with 83 additions and 29 deletions
|
@ -41,7 +41,7 @@ public class CogwheelBlockItem extends BlockItem {
|
||||||
large = block.isLarge;
|
large = block.isLarge;
|
||||||
|
|
||||||
placementHelperId = PlacementHelpers.register(large ? new LargeCogHelper() : new SmallCogHelper());
|
placementHelperId = PlacementHelpers.register(large ? new LargeCogHelper() : new SmallCogHelper());
|
||||||
integratedCogHelperId = large ? PlacementHelpers.register(new IntegratedCogHelper()) : -1;
|
integratedCogHelperId = PlacementHelpers.register(large ? new IntegratedLargeCogHelper() : new IntegratedSmallCogHelper());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -231,7 +231,7 @@ public class CogwheelBlockItem extends BlockItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
public static class IntegratedCogHelper implements IPlacementHelper {
|
public static class IntegratedLargeCogHelper implements IPlacementHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<ItemStack> getItemPredicate() {
|
public Predicate<ItemStack> getItemPredicate() {
|
||||||
|
@ -282,4 +282,57 @@ public class CogwheelBlockItem extends BlockItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MethodsReturnNonnullByDefault
|
||||||
|
public static class IntegratedSmallCogHelper implements IPlacementHelper {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Predicate<ItemStack> getItemPredicate() {
|
||||||
|
return ((Predicate<ItemStack>) ICogWheel::isSmallCogItem).and(ICogWheel::isDedicatedCogItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Predicate<BlockState> getStatePredicate() {
|
||||||
|
return s -> !ICogWheel.isDedicatedCogWheel(s.getBlock()) && ICogWheel.isSmallCog(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlacementOffset getOffset(PlayerEntity player, World world, BlockState state, BlockPos pos, BlockRayTraceResult ray) {
|
||||||
|
Direction face = ray.getFace();
|
||||||
|
Axis newAxis;
|
||||||
|
|
||||||
|
if (state.contains(HorizontalKineticBlock.HORIZONTAL_FACING))
|
||||||
|
newAxis = state.get(HorizontalKineticBlock.HORIZONTAL_FACING)
|
||||||
|
.getAxis();
|
||||||
|
else if (state.contains(DirectionalKineticBlock.FACING))
|
||||||
|
newAxis = state.get(DirectionalKineticBlock.FACING)
|
||||||
|
.getAxis();
|
||||||
|
else
|
||||||
|
newAxis = Axis.Y;
|
||||||
|
|
||||||
|
if (face.getAxis() == newAxis)
|
||||||
|
return PlacementOffset.fail();
|
||||||
|
|
||||||
|
List<Direction> directions = IPlacementHelper.orderedByDistanceExceptAxis(pos, ray.getHitVec(), newAxis);
|
||||||
|
|
||||||
|
for (Direction d : directions) {
|
||||||
|
BlockPos newPos = pos.offset(d);
|
||||||
|
|
||||||
|
if (!world.getBlockState(newPos)
|
||||||
|
.getMaterial()
|
||||||
|
.isReplaceable())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!CogWheelBlock.isValidCogwheelPosition(false, world, newPos, newAxis))
|
||||||
|
return PlacementOffset.fail();
|
||||||
|
|
||||||
|
return PlacementOffset.success()
|
||||||
|
.at(newPos)
|
||||||
|
.withTransform(s -> s.with(CogWheelBlock.AXIS, newAxis));
|
||||||
|
}
|
||||||
|
|
||||||
|
return PlacementOffset.fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,11 +97,12 @@ public class UIRenderHelper {
|
||||||
private static void streak(MatrixStack ms, int width, int height, int c1, int c2, int c3, int c4) {
|
private static void streak(MatrixStack ms, int width, int height, int c1, int c2, int c3, int c4) {
|
||||||
double split1 = .5;
|
double split1 = .5;
|
||||||
double split2 = .75;
|
double split2 = .75;
|
||||||
Matrix4f model = ms.peek()
|
Matrix4f model = ms.peek().getModel();
|
||||||
.getModel();
|
RenderSystem.disableAlphaTest();
|
||||||
GuiUtils.drawGradientRect(model, 0, -width, 0, width, (int) (split1 * height), c1, c2);
|
GuiUtils.drawGradientRect(model, 0, -width, 0, width, (int) (split1 * height), c1, c2);
|
||||||
GuiUtils.drawGradientRect(model, 0, -width, (int) (split1 * height), width, (int) (split2 * height), c2, c3);
|
GuiUtils.drawGradientRect(model, 0, -width, (int) (split1 * height), width, (int) (split2 * height), c2, c3);
|
||||||
GuiUtils.drawGradientRect(model, 0, -width, (int) (split2 * height), width, height, c3, c4);
|
GuiUtils.drawGradientRect(model, 0, -width, (int) (split2 * height), width, height, c3, c4);
|
||||||
|
RenderSystem.enableAlphaTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue