Skip to content

Commit

Permalink
laser junctions
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Sep 16, 2024
1 parent a137f9e commit c74bf90
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-09-15T13:58:30.925213678 Item Models: modjam
// 1.21.1 2024-09-16T18:20:11.621392294 Item Models: modjam
51765874ad3111adf69684269ad9a422bfbaac4a assets/modjam/models/item/aquarine_steel_block.json
e674d6859446f65b4ee805ed6e9f47d6cde82515 assets/modjam/models/item/aquarine_steel_ingot.json
098a336dd0b210f2b650174de2346a665b921edd assets/modjam/models/item/aquarine_steel_wrench.json
Expand All @@ -22,6 +22,7 @@ a089323dae9de79cf909c7f0340251864eaed85f assets/modjam/models/item/diving_helmet
c78201ce0b7023d1bd6173df7f9263b243caaeb6 assets/modjam/models/item/etching_acid_bucket.json
054c0dfda629903fcf6880f0db40241af562a1a8 assets/modjam/models/item/gear.json
f0f9891cd57b3a66f7440a71b925348bb8ea745b assets/modjam/models/item/glass_vial.json
90f40165338e8b2c43d8fdfcac66c858337b20de assets/modjam/models/item/laser_junction.json
ded81f67ccb99458d5f971322bfe07b2bcf64129 assets/modjam/models/item/long_distance_laser.json
70e7405579c5908091d6c50ab13bb62c8a3fea61 assets/modjam/models/item/mixer.json
dab337d602d93b0a4930b69e652b1155300c6502 assets/modjam/models/item/prism_monocle.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// 1.21.1 2024-09-15T11:04:48.6913026 Block States: modjam
// 1.21.1 2024-09-16T18:10:06.17361362 Block States: modjam
af3ef9c17c60ced537516e8aa1215fcb76e3683e assets/modjam/blockstates/aquarine_steel_block.json
865a45a4d022b56bc54dc32dae4b666af2df7d6f assets/modjam/blockstates/aquatic_catalyst.json
6e42254717fc67a953282f50517eb06c02193129 assets/modjam/blockstates/chiseled_dark_prismarine.json
3f474de85f7cf428f3ecd383cde71be56c940ecd assets/modjam/blockstates/crate.json
791da2d01b6b33bb1ce175d5c9c1fa5b737c9dfc assets/modjam/blockstates/dark_prismarine_pillar.json
ff480f6623e46679671977b783f08e28c536578d assets/modjam/blockstates/deep_sea_drain.json
74a08c3614f8cf6dace6f155476015776d839ce1 assets/modjam/blockstates/deep_sea_drain_part.json
3d7512c2337ca4277a1e0841655d605398a5ab31 assets/modjam/blockstates/laser_junction.json
a0332b39b3925269df891406b880e356aa4a2a81 assets/modjam/blockstates/long_distance_laser.json
eac838481765cf9a4cbfc888a6b35b11d43f16f6 assets/modjam/blockstates/mixer.json
1f3da306face8fd06aa163eec7cc411123921f90 assets/modjam/blockstates/prismarine_laser_relay.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public abstract class LaserBlockEntity extends ContainerBlockEntity {
protected final Object2IntMap<Direction> laserDistances;
private final Object2IntMap<ItemEntity> activeTransformations;
private final Object2ObjectMap<Direction, Object2IntMap<ItemEntity>> activeTransformations;

private int powerToTransfer;
protected int power;
Expand All @@ -42,7 +42,7 @@ public abstract class LaserBlockEntity extends ContainerBlockEntity {
public LaserBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
super(blockEntityType, blockPos, blockState);
this.laserDistances = new Object2IntOpenHashMap<>();
this.activeTransformations = new Object2IntArrayMap<>();
this.activeTransformations = new Object2ObjectArrayMap<>();
this.powerPerSide = new Object2IntArrayMap<>();
this.purityPerSide = new Object2FloatArrayMap<>();
this.purity = 0;
Expand Down Expand Up @@ -126,7 +126,7 @@ public void commonTick() {

damageLivingEntities(box);

processItemCrafting(box);
processItemCrafting(box, direction);

BlockPos targetPos = worldPosition.relative(direction, distance);
if (level.getBlockEntity(targetPos) instanceof LaserBlockEntity laserBE) {
Expand Down Expand Up @@ -164,46 +164,50 @@ private Optional<ItemTransformationRecipe> getCurrentRecipe(ItemStack itemStack)
return this.level.getRecipeManager().getRecipeFor(ItemTransformationRecipe.Type.INSTANCE, recipeInput, level).map(RecipeHolder::value);
}

// FIXME: If items are moved out of the aabb recipe still works
private void processItemCrafting(AABB box) {
private void processItemCrafting(AABB box, Direction direction) {
// Get all item entities within the box
List<ItemEntity> itemEntities = level.getEntitiesOfClass(ItemEntity.class, box);

for (ItemEntity itemEntity : itemEntities) {
ModJam.LOGGER.debug("found item");
if (!activeTransformations.containsKey(itemEntity)) {
if (!activeTransformations.containsKey(direction) || !activeTransformations.get(direction).containsKey(itemEntity)) {
Optional<ItemTransformationRecipe> optionalRecipe = getCurrentRecipe(itemEntity.getItem());
if (optionalRecipe.isPresent()) {
activeTransformations.put(itemEntity, 0);
if (!activeTransformations.containsKey(direction)) {
activeTransformations.put(direction, new Object2IntArrayMap<>());
}
activeTransformations.get(direction).put(itemEntity, 0);
}
}
}

ObjectIterator<Object2IntMap.Entry<ItemEntity>> iterator = activeTransformations.object2IntEntrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<ItemEntity, Integer> entry = iterator.next();
ItemEntity cookingItem = entry.getKey();
int cookTime = entry.getValue();

if (!cookingItem.isAlive()) {
iterator.remove();
continue;
}

Optional<ItemTransformationRecipe> optionalRecipe = getCurrentRecipe(cookingItem.getItem());
if (optionalRecipe.isPresent()) {
if (cookTime >= optionalRecipe.get().duration()) {
ItemStack resultStack = optionalRecipe.get().getResultItem(null).copy();
resultStack.setCount(cookingItem.getItem().getCount());

ItemEntity resultEntity = new ItemEntity(level, cookingItem.getX(), cookingItem.getY(), cookingItem.getZ(), resultStack);
level.addFreshEntity(resultEntity);
if (activeTransformations.containsKey(direction) && !activeTransformations.get(direction).isEmpty()) {
Object2IntMap<ItemEntity> activeTransformation = activeTransformations.get(direction);
ObjectIterator<Object2IntMap.Entry<ItemEntity>> iterator = activeTransformation.object2IntEntrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<ItemEntity, Integer> entry = iterator.next();
ItemEntity cookingItem = entry.getKey();
int cookTime = entry.getValue();

cookingItem.discard();
if (!cookingItem.isAlive() || !box.contains(cookingItem.position())) {
iterator.remove();
} else {
activeTransformations.put(cookingItem, cookTime + 1);
ParticlesUtils.spawnParticles(cookingItem, level, ParticleTypes.END_ROD);
continue;
}

Optional<ItemTransformationRecipe> optionalRecipe = getCurrentRecipe(cookingItem.getItem());
if (optionalRecipe.isPresent()) {
if (cookTime >= optionalRecipe.get().duration()) {
ItemStack resultStack = optionalRecipe.get().getResultItem(null).copy();
resultStack.setCount(cookingItem.getItem().getCount());

ItemEntity resultEntity = new ItemEntity(level, cookingItem.getX(), cookingItem.getY(), cookingItem.getZ(), resultStack);
level.addFreshEntity(resultEntity);

cookingItem.discard();
iterator.remove();
} else {
activeTransformation.put(cookingItem, cookTime + 1);
ParticlesUtils.spawnParticles(cookingItem, level, ParticleTypes.END_ROD);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.portingdeadmods.modjam.api.client.renderer.blockentities;

import com.mojang.blaze3d.vertex.PoseStack;
import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.modjam.utils.LaserRendererHelper;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
Expand All @@ -19,12 +20,13 @@ public LaserBlockEntityRenderer(BlockEntityRendererProvider.Context ctx) {

@Override
public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay) {
BlockPos originPos = blockEntity.getBlockPos();
Object2IntMap<Direction> laserDistances = blockEntity.getLaserDistances();
for (Direction direction : blockEntity.getLaserOutputs()) {
int laserDistance = laserDistances.getOrDefault(direction, 0);

BlockPos originPos = blockEntity.getBlockPos();
BlockPos targetPos = originPos.relative(direction, laserDistance - 1);
if (laserDistance != 0 && blockEntity.shouldRender(direction)) {
if (laserDistance > 0 && blockEntity.shouldRender(direction)) {
LaserRendererHelper.renderOuterBeam(blockEntity, originPos, targetPos, direction, poseStack, bufferSource, partialTick);

poseStack.pushPose();
Expand All @@ -35,10 +37,26 @@ public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiB
switch (direction) {
case UP -> poseStack.translate(3.5f, 0, 3.5f);
case DOWN, SOUTH, WEST -> poseStack.translate(3.5f, 0, -4.5f);
case NORTH, EAST -> poseStack.translate(-4.5f, 0, -4.5f);
case EAST, NORTH -> poseStack.translate(-4.5f, 0, -4.5f);
}

int offset = 0;
int offset2 = 0;

if (direction == Direction.EAST || direction == Direction.SOUTH) {
offset = 1;
}

if (direction == Direction.NORTH || direction == Direction.WEST || direction == Direction.DOWN) {
offset2 = 1;
}

if (direction == Direction.UP) {
offset = 1;
}

LaserRendererHelper.renderInnerBeam(poseStack, bufferSource, partialTick, blockEntity.getLevel().getGameTime(),
0, laserDistance, FastColor.ARGB32.color(202, 214, 224));
offset, laserDistance - offset - offset2, FastColor.ARGB32.color(202, 214, 224));
}
poseStack.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,28 @@ public DrainBERenderer(BlockEntityRendererProvider.Context ctx) {
public void render(DrainPartBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay) {
BlockState blockState = blockEntity.getBlockState();
if (blockState.getValue(DrainMultiblock.DRAIN_PART) == 4 && blockState.getValue(DrainPartBlock.TOP)) {
DrainBlockEntity drainBE = (DrainBlockEntity) blockEntity.getLevel().getBlockEntity(blockEntity.getBlockPos().below());
VertexConsumer consumer = DrainTopModel.DRAIN_TOP_LOCATION.buffer(bufferSource, RenderType::entityTranslucent);
this.model.setupAnimation();
poseStack.pushPose();
{
float lidAngle = drainBE.getLidIndependentAngle(partialTick);
if (blockEntity.getLevel().getBlockEntity(blockEntity.getBlockPos().below()) instanceof DrainBlockEntity drainBE) {
float lidAngle = drainBE.getLidIndependentAngle(partialTick);

poseStack.translate(-0.75, 0, -0.75);
poseStack.mulPose(Axis.YP.rotation(lidAngle));
poseStack.translate(0.75, 0, 0.75);
this.model.renderLid(poseStack, consumer, packedLight, packedOverlay);
poseStack.pushPose();
{
float valveAngle = drainBE.getValveIndependentAngle(partialTick);
poseStack.translate(-0.75, 0, -0.75);
poseStack.mulPose(Axis.YP.rotation(lidAngle));
poseStack.translate(0.75, 0, 0.75);
this.model.renderLid(poseStack, consumer, packedLight, packedOverlay);
poseStack.pushPose();
{
float valveAngle = drainBE.getValveIndependentAngle(partialTick);

poseStack.translate(0.5, 0, 0.5);
poseStack.mulPose(Axis.YP.rotation(valveAngle));
poseStack.translate(-0.5, 0, -0.5);
this.model.renderValve(poseStack, consumer, packedLight, packedOverlay);
poseStack.translate(0.5, 0, 0.5);
poseStack.mulPose(Axis.YP.rotation(valveAngle));
poseStack.translate(-0.5, 0, -0.5);
this.model.renderValve(poseStack, consumer, packedLight, packedOverlay);
}
poseStack.popPose();
}
poseStack.popPose();
}
poseStack.popPose();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -116,8 +117,7 @@ private static void renderFluid(MixerBlockEntity blockEntity, PoseStack poseStac
private static void renderFluid(PoseStack poseStack, MultiBufferSource bufferSource, FluidStack fluidStack, float alpha, float heightPercentage, int combinedLight) {
VertexConsumer vertexBuilder = bufferSource.getBuffer(RenderType.translucent());
IClientFluidTypeExtensions fluidTypeExtensions = IClientFluidTypeExtensions.of(fluidStack.getFluid());
//noinspection deprecation
TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(fluidTypeExtensions.getStillTexture(fluidStack));
TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(fluidTypeExtensions.getStillTexture(fluidStack));
int color = fluidTypeExtensions.getTintColor();
alpha *= (color >> 24 & 255) / 255f;
float red = (color >> 16 & 255) / 255f;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.portingdeadmods.modjam.content.blockentities;

import com.portingdeadmods.modjam.ModJam;
import com.portingdeadmods.modjam.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.modjam.capabilities.IOActions;
import com.portingdeadmods.modjam.content.blocks.LaserJunctionBlock;
import com.portingdeadmods.modjam.registries.MJBlockEntityTypes;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.capabilities.BlockCapability;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class LaserJunctionBlockEntity extends LaserBlockEntity {
public LaserJunctionBlockEntity(BlockPos blockPos, BlockState blockState) {
super(MJBlockEntityTypes.LASER_JUNCTION.get(), blockPos, blockState);
}

@Override
public ObjectSet<Direction> getLaserInputs() {
return getConnections(LaserJunctionBlock.ConnectionType.INPUT);
}

@Override
public ObjectSet<Direction> getLaserOutputs() {
return getConnections(LaserJunctionBlock.ConnectionType.OUTPUT);
}

private ObjectSet<Direction> getConnections(LaserJunctionBlock.ConnectionType type) {
ObjectSet<Direction> connections = new ObjectArraySet<>();
for (Direction direction : Direction.values()) {
if (getBlockState().getValue(LaserJunctionBlock.CONNECTION[direction.get3DDataValue()]) == type) {
connections.add(direction);
}
}
return connections;
}

@Override
public <T> Map<Direction, Pair<IOActions, int[]>> getSidedInteractions(BlockCapability<T, @Nullable Direction> capability) {
return Map.of();
}

@Override
public void commonTick() {
super.commonTick();
transmitPower(this.power);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ public <T> Map<Direction, Pair<IOActions, int[]>> getSidedInteractions(BlockCapa
public int getMaxLaserDistance() {
return 64;
}

@Override
public void commonTick() {
super.commonTick();

transmitPower(this.power);
}
}
Loading

0 comments on commit c74bf90

Please sign in to comment.