generated from NeoForgeMDKs/MDK-1.21-NeoGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a438a6b
commit 537b05e
Showing
12 changed files
with
300 additions
and
33 deletions.
There are no files selected for viewing
89 changes: 77 additions & 12 deletions
89
src/main/java/com/portingdeadmods/modjam/api/blockentities/LaserBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,112 @@ | ||
package com.portingdeadmods.modjam.api.blockentities; | ||
|
||
import com.portingdeadmods.modjam.ModJam; | ||
import com.portingdeadmods.modjam.api.blocks.blockentities.LaserBlock; | ||
import com.portingdeadmods.modjam.registries.MJItems; | ||
import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.item.ItemEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.AABB; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.List; | ||
|
||
public abstract class LaserBlockEntity extends ContainerBlockEntity { | ||
private int laserAnimTime; | ||
private static final int MAX_DISTANCE = 16; | ||
|
||
private float clientLaserTime; | ||
private final Object2IntMap<Direction> laserDistances; | ||
private int itemTransformTime; | ||
public AABB box; | ||
|
||
public LaserBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) { | ||
super(blockEntityType, blockPos, blockState); | ||
this.laserDistances = new Object2IntOpenHashMap<>(); | ||
this.box = new AABB(blockPos); | ||
} | ||
|
||
public abstract List<Direction> getLaserInputs(); | ||
|
||
public abstract List<Direction> getLaserOutputs(); | ||
|
||
public abstract int getLaserDistance(Direction direction); | ||
public Object2IntMap<Direction> getLaserDistances() { | ||
return laserDistances; | ||
} | ||
|
||
public int getLaserAnimTimeDuration() { | ||
return 80; | ||
} | ||
|
||
public int getLaserAnimTime() { | ||
return laserAnimTime; | ||
public float getClientLaserTime() { | ||
return clientLaserTime; | ||
} | ||
|
||
public float getLaserScale(float partialTick) { | ||
return ((float) this.laserAnimTime + partialTick) / (float) this.getLaserAnimTimeDuration(); | ||
return (this.clientLaserTime + partialTick) / (float) this.getLaserAnimTimeDuration(); | ||
} | ||
|
||
@Override | ||
public void commonTick() { | ||
super.commonTick(); | ||
if (laserAnimTime < getLaserAnimTimeDuration()) { | ||
this.laserAnimTime++; | ||
} else { | ||
this.laserAnimTime = 0; | ||
if (level.isClientSide()) { | ||
if (clientLaserTime < getLaserAnimTimeDuration()) { | ||
this.clientLaserTime += 0.5f; | ||
} else { | ||
this.clientLaserTime = 0; | ||
} | ||
} | ||
|
||
if (level.getGameTime() % 10 == 0) { | ||
checkConnections(); | ||
} | ||
damageLiving(); | ||
|
||
transmitPower(); | ||
} | ||
|
||
private void transmitPower() { | ||
|
||
} | ||
|
||
private void damageLiving() { | ||
for (Direction direction : getLaserOutputs()) { | ||
int distance = this.laserDistances.getInt(direction); | ||
BlockPos pos = worldPosition.above().relative(direction, distance - 1); | ||
Vec3 start = worldPosition.getCenter().subtract(0.1, 0, 0.1); | ||
Vec3 end = pos.getCenter().add(0.1, 0, 0.1); | ||
AABB box = new AABB(start, end); | ||
this.box = box; | ||
ModJam.LOGGER.debug("Distance: {}", box); | ||
List<LivingEntity> livingEntities = level.getEntitiesOfClass(LivingEntity.class, box); | ||
for (LivingEntity livingEntity : livingEntities) { | ||
livingEntity.hurt(level.damageSources().inFire(), 3); | ||
} | ||
} | ||
} | ||
|
||
private void checkConnections() { | ||
for (Direction direction : getLaserOutputs()) { | ||
for (int i = 1; i < MAX_DISTANCE; i++) { | ||
BlockPos pos = worldPosition.relative(direction, i); | ||
BlockState state = level.getBlockState(pos); | ||
|
||
if (state.getBlock() instanceof LaserBlock) { | ||
laserDistances.put(direction, i); | ||
break; | ||
} | ||
|
||
if (!state.canBeReplaced() || i == MAX_DISTANCE - 1) { | ||
laserDistances.put(direction, 0); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
...a/com/portingdeadmods/modjam/client/renderer/blockentities/AquaticCatalystBERenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
package com.portingdeadmods.modjam.client.renderer.blockentities; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.portingdeadmods.modjam.api.client.renderer.blockentities.LaserBlockEntityRenderer; | ||
import com.portingdeadmods.modjam.content.blockentities.AquaticCatalystBlockEntity; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
|
||
public class AquaticCatalystBERenderer extends LaserBlockEntityRenderer<AquaticCatalystBlockEntity> { | ||
public AquaticCatalystBERenderer(BlockEntityRendererProvider.Context ctx) { | ||
super(ctx); | ||
} | ||
|
||
@Override | ||
public void render(AquaticCatalystBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, int packedOverlay) { | ||
super.render(blockEntity, partialTick, poseStack, bufferSource, packedLight, packedOverlay); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/portingdeadmods/modjam/utils/CodecUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.portingdeadmods.modjam.utils; | ||
|
||
import com.mojang.serialization.Codec; | ||
|
||
import java.util.Set; | ||
|
||
public final class CodecUtils { | ||
public static <E> Codec<Set<E>> set(final Codec<E> elementCodec) { | ||
return set(elementCodec, 0, Integer.MAX_VALUE); | ||
} | ||
|
||
public static <E> Codec<Set<E>> set(final Codec<E> elementCodec, final int minSize, final int maxSize) { | ||
return new SetCodec<>(elementCodec, minSize, maxSize); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/com/portingdeadmods/modjam/utils/SetBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.portingdeadmods.modjam.utils; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.mojang.serialization.*; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
public interface SetBuilder<T> { | ||
DynamicOps<T> ops(); | ||
|
||
DataResult<T> build(T prefix); | ||
|
||
SetBuilder<T> add(final T value); | ||
|
||
SetBuilder<T> add(final DataResult<T> value); | ||
|
||
SetBuilder<T> withErrorsFrom(final DataResult<?> result); | ||
|
||
SetBuilder<T> mapError(UnaryOperator<String> onError); | ||
|
||
default DataResult<T> build(final DataResult<T> prefix) { | ||
return prefix.flatMap(this::build); | ||
} | ||
|
||
default <E> SetBuilder<T> add(final E value, final Encoder<E> encoder) { | ||
return add(encoder.encodeStart(ops(), value)); | ||
} | ||
|
||
default <E> SetBuilder<T> addAll(final Iterable<E> values, final Encoder<E> encoder) { | ||
values.forEach(v -> encoder.encode(v, ops(), ops().empty())); | ||
return this; | ||
} | ||
|
||
final class Builder<T> implements SetBuilder<T> { | ||
private final DynamicOps<T> ops; | ||
private DataResult<ImmutableSet.Builder<T>> builder = DataResult.success(ImmutableSet.builder(), Lifecycle.stable()); | ||
|
||
public Builder(final DynamicOps<T> ops) { | ||
this.ops = ops; | ||
} | ||
|
||
@Override | ||
public DynamicOps<T> ops() { | ||
return ops; | ||
} | ||
|
||
@Override | ||
public SetBuilder<T> add(final T value) { | ||
builder = builder.map(b -> b.add(value)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public SetBuilder<T> add(final DataResult<T> value) { | ||
builder = builder.apply2stable(ImmutableSet.Builder::add, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public SetBuilder<T> withErrorsFrom(final DataResult<?> result) { | ||
builder = builder.flatMap(r -> result.map(v -> r)); | ||
return this; | ||
} | ||
|
||
@Override | ||
public SetBuilder<T> mapError(final UnaryOperator<String> onError) { | ||
builder = builder.mapError(onError); | ||
return this; | ||
} | ||
|
||
@Override | ||
public DataResult<T> build(final T prefix) { | ||
final DataResult<T> result = builder.flatMap(b -> ops.mergeToList(prefix, b.build().asList())); | ||
builder = DataResult.success(ImmutableSet.builder(), Lifecycle.stable()); | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.