Add some more configurability and light emitter behaviour
This commit is contained in:
parent
0bc2d1f684
commit
352ad95a84
|
@ -1651,7 +1651,7 @@ d080b1b25e5bc8baf5aee68691b08c7f12ece3b0 assets/create/models/item/windmill_bear
|
|||
a80fb25a0b655e76be986b5b49fcb0f03461a1ab assets/create/models/item/zinc_nugget.json
|
||||
b1689617190c05ef34bd18456b0c7ae09bb3210f assets/create/models/item/zinc_ore.json
|
||||
71739e613693c476e481dfcf38628a4f52f0f570 assets/create/sounds.json
|
||||
5d0cc4c0255dc241e61c173b31ddca70c88d08e4 data/create/advancements/aesthetics.json
|
||||
0f1b4b980afba9bf2caf583b88e261bba8b10313 data/create/advancements/aesthetics.json
|
||||
187921fa131b06721bfaf63f2623a28c141aae9a data/create/advancements/andesite_alloy.json
|
||||
0ea2db7173b5be28b289ea7c9a6a0cf5805c60c7 data/create/advancements/andesite_casing.json
|
||||
83c046bd200623933545c9e4326f782fb02c87fa data/create/advancements/arm_blaze_burner.json
|
||||
|
@ -3496,6 +3496,7 @@ eae06580a0a5f486cde35426716d50fcb3ba5bb3 data/create/recipes/polished_weathered_
|
|||
0fa8386648398724f6fd373178b706c6b11ddefc data/create/recipes/pressing/gold_ingot.json
|
||||
a104ef6eb8872a40ea7b2ef67ae54cec943162f0 data/create/recipes/pressing/iron_ingot.json
|
||||
7f9e72ec02a9926656744a95066f8aa304514565 data/create/recipes/pressing/lapis_block.json
|
||||
aa037e34fd64ce86fca4086601b5a4aee17da87b data/create/recipes/pressing/lily_pad.json
|
||||
654e274b07af172c22838d47e0974367c20101d4 data/create/recipes/pressing/path.json
|
||||
bd57ccc8eb4357b4a5af021db7b806b514cd2558 data/create/recipes/pressing/sugar_cane.json
|
||||
141173778757d87e7f2e9466bdab6ff1263c8e98 data/create/recipes/sandpaper_polishing/rose_quartz.json
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
"trigger": "create:bracket_apply",
|
||||
"conditions": {
|
||||
"accepted_entries": [
|
||||
"create:large_cogwheel",
|
||||
"create:cogwheel"
|
||||
"create:cogwheel",
|
||||
"create:large_cogwheel"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"type": "create:pressing",
|
||||
"ingredients": [
|
||||
{
|
||||
"item": "minecraft:ghast_tear"
|
||||
}
|
||||
],
|
||||
"results": [
|
||||
{
|
||||
"item": "minecraft:lily_pad"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -50,12 +50,14 @@ import com.simibubi.create.foundation.config.ConfigBase.ConfigBool;
|
|||
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
import mezz.jei.api.recipe.IRecipeManager;
|
||||
import mezz.jei.api.registration.IGuiHandlerRegistration;
|
||||
import mezz.jei.api.registration.IRecipeCatalystRegistration;
|
||||
import mezz.jei.api.registration.IRecipeCategoryRegistration;
|
||||
import mezz.jei.api.registration.IRecipeRegistration;
|
||||
import mezz.jei.api.registration.ISubtypeRegistration;
|
||||
import mezz.jei.api.runtime.IIngredientManager;
|
||||
import mezz.jei.api.runtime.IJeiRuntime;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
|
@ -240,6 +242,17 @@ public class CreateJEI implements IModPlugin {
|
|||
registration.addGhostIngredientHandler(AbstractFilterScreen.class, new FilterGhostIngredientHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
|
||||
IRecipeManager manager = jeiRuntime.getRecipeManager();
|
||||
ResourceLocation rl = new ResourceLocation(Create.ID + ":pressing/lily_pad");
|
||||
manager.getRecipes(pressing)
|
||||
.stream()
|
||||
.filter(iRecipe -> iRecipe.getId().equals(rl))
|
||||
.findFirst()
|
||||
.ifPresent(r -> manager.hideRecipe(r, pressing.getUid()));
|
||||
}
|
||||
|
||||
private class CategoryBuilder<T extends IRecipe<?>> {
|
||||
CreateRecipeCategory<T> category;
|
||||
private Predicate<CRecipes> pred;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.optics;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -13,16 +14,30 @@ import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|||
import net.minecraft.item.DyeColor;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class Beam extends ArrayList<BeamSegment> {
|
||||
private final Set<ILightHandler> lightEventListeners;
|
||||
private final transient Set<ILightHandler> lightEventListeners;
|
||||
@Nullable
|
||||
private final Beam parent;
|
||||
private final long createdAt;
|
||||
@Nullable
|
||||
private final transient World world;
|
||||
private boolean removed = false;
|
||||
|
||||
public Beam(@Nullable Beam parent) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.createdAt = 0;
|
||||
this.world = null;
|
||||
lightEventListeners = new HashSet<>();
|
||||
}
|
||||
|
||||
public Beam(@Nullable Beam parent, @Nullable World world) {
|
||||
super();
|
||||
this.parent = parent;
|
||||
this.world = world;
|
||||
this.createdAt = world == null ? -1 : this.world.getGameTime();
|
||||
lightEventListeners = new HashSet<>();
|
||||
}
|
||||
|
||||
|
@ -63,8 +78,13 @@ public class Beam extends ArrayList<BeamSegment> {
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
Beam that = (Beam) o;
|
||||
return lightEventListeners.equals(that.lightEventListeners);
|
||||
Beam beam = (Beam) o;
|
||||
return createdAt == beam.createdAt && removed == beam.removed && lightEventListeners.equals(beam.lightEventListeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), lightEventListeners, createdAt, removed);
|
||||
}
|
||||
|
||||
public boolean isRemoved() {
|
||||
|
@ -95,6 +115,10 @@ public class Beam extends ArrayList<BeamSegment> {
|
|||
return out;
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
return world != null && world.getGameTime() == createdAt;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Beam getParent() {
|
||||
|
|
|
@ -20,12 +20,16 @@ import net.minecraft.util.math.vector.Vector3d;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public interface ILightHandler {
|
||||
default Beam constructOutBeam(Vector3d beamDirection) {
|
||||
return constructOutBeam(null, beamDirection);
|
||||
}
|
||||
|
||||
default Beam constructOutBeam(@Nullable Beam parent, Vector3d beamDirection) {
|
||||
return constructOutBeam(parent, beamDirection, getBlockPos());
|
||||
}
|
||||
|
||||
default Beam constructOutBeam(@Nullable Beam parent, Vector3d beamDirection, BlockPos testBlockPos) {
|
||||
Beam beam = new Beam(parent);
|
||||
Beam beam = new Beam(parent, getHandlerWorld());
|
||||
World world = getHandlerWorld();
|
||||
if (world == null)
|
||||
return beam;
|
||||
|
@ -38,7 +42,7 @@ public interface ILightHandler {
|
|||
BeamSegment segment = new BeamSegment(this, segmentColor, testPos, direction);
|
||||
beam.add(segment);
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
for (int i = 0; i < getMaxScanRange(); i++) {
|
||||
testPos = testPos.add(direction); // check next block
|
||||
testBlockPos = new BlockPos(testPos.x, testPos.y, testPos.z);
|
||||
BlockState testState = world.getBlockState(testBlockPos);
|
||||
|
@ -64,6 +68,10 @@ public interface ILightHandler {
|
|||
return beam;
|
||||
}
|
||||
|
||||
default int getMaxScanRange() {
|
||||
return 128;
|
||||
}
|
||||
|
||||
default World getHandlerWorld() {
|
||||
return getTile().getWorld();
|
||||
}
|
||||
|
|
|
@ -19,21 +19,23 @@ import net.minecraft.tileentity.TileEntity;
|
|||
|
||||
public abstract class AbstractLightHandlingBehaviour<T extends SmartTileEntity & ILightHandler.ILightHandlerProvider> extends TileEntityBehaviour implements ILightHandler {
|
||||
protected final T handler;
|
||||
private final LightHandlingbehaviourProperties properties;
|
||||
protected Set<Beam> beams;
|
||||
protected Beam beaconBeam = null;
|
||||
@Nullable
|
||||
protected BeaconTileEntity beacon;
|
||||
|
||||
protected AbstractLightHandlingBehaviour(T te) {
|
||||
protected AbstractLightHandlingBehaviour(T te, LightHandlingbehaviourProperties properties) {
|
||||
super(te);
|
||||
this.handler = te;
|
||||
this.properties = properties;
|
||||
beams = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (beacon != null && beacon.isRemoved())
|
||||
if (properties.scansBeacon && beacon != null && beacon.isRemoved())
|
||||
updateBeaconState();
|
||||
}
|
||||
|
||||
|
@ -66,7 +68,8 @@ public abstract class AbstractLightHandlingBehaviour<T extends SmartTileEntity &
|
|||
@Override
|
||||
public void lazyTick() {
|
||||
super.lazyTick();
|
||||
updateBeaconState();
|
||||
if (properties.scansBeacon)
|
||||
updateBeaconState();
|
||||
updateBeams();
|
||||
}
|
||||
|
||||
|
@ -80,4 +83,19 @@ public abstract class AbstractLightHandlingBehaviour<T extends SmartTileEntity &
|
|||
public Set<Beam> getBeams() {
|
||||
return beams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
beams.forEach(Beam::onRemoved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean absorbsLight() {
|
||||
return properties.absorbsLight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxScanRange() {
|
||||
return properties.scanRange;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
|||
public abstract class AbstractLightRelayBehaviour<T extends SmartTileEntity & ILightHandler.ILightHandlerProvider> extends AbstractLightHandlingBehaviour<T> {
|
||||
private boolean isUpdating;
|
||||
|
||||
protected AbstractLightRelayBehaviour(T te) {
|
||||
super(te);
|
||||
protected AbstractLightRelayBehaviour(T te, LightHandlingbehaviourProperties properties) {
|
||||
super(te, properties);
|
||||
isUpdating = false;
|
||||
}
|
||||
|
||||
|
@ -29,12 +29,14 @@ public abstract class AbstractLightRelayBehaviour<T extends SmartTileEntity & IL
|
|||
Set<Beam> oldBeams = new HashSet<>(beams);
|
||||
beams.clear();
|
||||
for (Beam child : oldBeams) {
|
||||
Beam parent = child.getParent();
|
||||
|
||||
child.onRemoved();
|
||||
if (parent == null || parent.isRemoved())
|
||||
if (child.isNew()) {
|
||||
beams.add(child);
|
||||
continue;
|
||||
constructSubBeams(parent).forEach(Beam::onCreated);
|
||||
}
|
||||
Beam parent = child.getParent();
|
||||
child.onRemoved();
|
||||
if (parent != null && !parent.isRemoved())
|
||||
constructSubBeams(parent).forEach(Beam::onCreated);
|
||||
}
|
||||
isUpdating = false;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ public abstract class AbstractRotatedLightRelayBehaviour<T extends KineticTileEn
|
|||
protected float clientAngleDiff;
|
||||
private float prevAngle;
|
||||
|
||||
protected AbstractRotatedLightRelayBehaviour(T te) {
|
||||
super(te);
|
||||
protected AbstractRotatedLightRelayBehaviour(T te, LightHandlingbehaviourProperties properties) {
|
||||
super(te, properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,22 +1,28 @@
|
|||
package com.simibubi.create.content.optics.behaviour;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.simibubi.create.content.optics.Beam;
|
||||
import com.simibubi.create.content.optics.ILightHandler;
|
||||
import com.simibubi.create.content.optics.mirror.MirrorBehaviour;
|
||||
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LightAcceptingBehaviour<T extends SmartTileEntity & ILightHandler.ILightHandlerProvider> extends AbstractLightHandlingBehaviour<T> {
|
||||
public static final BehaviourType<MirrorBehaviour> TYPE = new BehaviourType<>();
|
||||
boolean isUpdating = false;
|
||||
|
||||
protected LightAcceptingBehaviour(T te) {
|
||||
super(te);
|
||||
public LightAcceptingBehaviour(T te, LightHandlingbehaviourProperties properties) {
|
||||
super(te, properties);
|
||||
}
|
||||
|
||||
public LightAcceptingBehaviour(T te) {
|
||||
super(te, LightHandlingbehaviourProperties.create()
|
||||
.withAbsorbsLight(true)
|
||||
.withScansBeacons(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.simibubi.create.content.optics.behaviour;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.simibubi.create.content.optics.Beam;
|
||||
import com.simibubi.create.content.optics.ILightHandler;
|
||||
import com.simibubi.create.content.optics.mirror.MirrorBehaviour;
|
||||
import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType;
|
||||
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
public class LightEmittingBehaviour<T extends SmartTileEntity & ILightHandler.ILightHandlerProvider> extends AbstractLightHandlingBehaviour<T> {
|
||||
public static final BehaviourType<MirrorBehaviour> TYPE = new BehaviourType<>();
|
||||
|
||||
boolean updating = false;
|
||||
|
||||
|
||||
public LightEmittingBehaviour(T te, LightHandlingbehaviourProperties properties) {
|
||||
super(te, properties);
|
||||
}
|
||||
|
||||
public LightEmittingBehaviour(T te) {
|
||||
super(te, LightHandlingbehaviourProperties.create()
|
||||
.withScansBeacons(false)
|
||||
.withAbsorbsLight(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBeams() {
|
||||
if (updating)
|
||||
return;
|
||||
updating = true;
|
||||
|
||||
beams.forEach(Beam::onRemoved);
|
||||
beams.clear();
|
||||
getOutbeamDirections().map(this::constructOutBeam)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(((Predicate<Beam>) Beam::isEmpty).negate())
|
||||
.peek(beams::add)
|
||||
.forEach(Beam::onCreated);
|
||||
|
||||
updating = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BehaviourType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
public Stream<Vector3d> getOutbeamDirections() {
|
||||
return Stream.of(Vector3d.of(tileEntity.getBlockState()
|
||||
.method_28500(BlockStateProperties.FACING)
|
||||
.orElse(Direction.UP)
|
||||
.getDirectionVec()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Beam> getRenderBeams() {
|
||||
return Iterators.concat(beams.iterator(), super.getRenderBeams());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.simibubi.create.content.optics.behaviour;
|
||||
|
||||
public class LightHandlingbehaviourProperties {
|
||||
int scanRange;
|
||||
boolean absorbsLight;
|
||||
boolean scansBeacon;
|
||||
|
||||
private LightHandlingbehaviourProperties() {
|
||||
scanRange = 128;
|
||||
absorbsLight = true;
|
||||
scansBeacon = true;
|
||||
}
|
||||
|
||||
public static LightHandlingbehaviourProperties create() {
|
||||
return new LightHandlingbehaviourProperties();
|
||||
}
|
||||
|
||||
public LightHandlingbehaviourProperties withScanRange(int scanRange) {
|
||||
this.scanRange = scanRange;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LightHandlingbehaviourProperties withAbsorbsLight(boolean absorbsLight) {
|
||||
this.absorbsLight = absorbsLight;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LightHandlingbehaviourProperties withScansBeacons(boolean scansBeacon) {
|
||||
this.scansBeacon = scansBeacon;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import javax.annotation.Nullable;
|
|||
|
||||
import com.simibubi.create.content.optics.Beam;
|
||||
import com.simibubi.create.content.optics.behaviour.AbstractRotatedLightRelayBehaviour;
|
||||
import com.simibubi.create.content.optics.behaviour.LightHandlingbehaviourProperties;
|
||||
import com.simibubi.create.foundation.collision.Matrix3d;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType;
|
||||
import com.simibubi.create.foundation.utility.AngleHelper;
|
||||
|
@ -28,7 +29,9 @@ public class MirrorBehaviour extends AbstractRotatedLightRelayBehaviour<MirrorTi
|
|||
Quaternion bufferedRotationQuaternion = null;
|
||||
|
||||
public MirrorBehaviour(MirrorTileEntity te) {
|
||||
super(te);
|
||||
super(te, LightHandlingbehaviourProperties.create()
|
||||
.withAbsorbsLight(true)
|
||||
.withScansBeacons(true));
|
||||
}
|
||||
|
||||
private Vector3d getReflectionAngle(Vector3d inputAngle) {
|
||||
|
|
|
@ -26,7 +26,9 @@ public class PressingRecipeGen extends ProcessingRecipeGen {
|
|||
LAPIS = create("lapis_block", b -> b.require(Blocks.LAPIS_BLOCK)
|
||||
.output(AllItems.LAPIS_SHEET.get())),
|
||||
BRASS = create("brass_ingot", b -> b.require(I.brass())
|
||||
.output(AllItems.BRASS_SHEET.get()))
|
||||
.output(AllItems.BRASS_SHEET.get())),
|
||||
LILY_PAD = create("lily_pad", b -> b.require(Ingredient.fromItems(Items.GHAST_TEAR))
|
||||
.output(Items.LILY_PAD));
|
||||
|
||||
;
|
||||
|
||||
|
|
Loading…
Reference in a new issue