Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Sep 7, 2024
2 parents 88f6f02 + 339138b commit 1f5a283
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package com.portingdeadmods.modjam.api.blockentities;

import com.portingdeadmods.modjam.api.blocks.blockentities.LaserBlock;
import com.portingdeadmods.modjam.registries.MJItems;
import com.portingdeadmods.modjam.utils.ParticlesUtils;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.particles.ParticleTypes;
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public abstract class LaserBlockEntity extends ContainerBlockEntity {
Expand Down Expand Up @@ -72,6 +80,9 @@ private void transmitPower() {

}

private ItemEntity cookingItem = null;
private int cookTime = 0;

private void damageLiving() {
for (Direction direction : getLaserOutputs()) {
int distance = this.laserDistances.getInt(direction);
Expand All @@ -80,10 +91,37 @@ private void damageLiving() {
Vec3 end = pos.getCenter().add(0.1, 0, 0.1);
AABB box = new AABB(start, end);
this.box = box;

assert level != null;
List<LivingEntity> livingEntities = level.getEntitiesOfClass(LivingEntity.class, box);
for (LivingEntity livingEntity : livingEntities) {
livingEntity.hurt(level.damageSources().inFire(), 3);
}

List<ItemEntity> itemEntities = level.getEntitiesOfClass(ItemEntity.class, box);
if (cookingItem == null) {
for (ItemEntity itemEntity : itemEntities) {
if (itemEntity.getItem().is(Items.IRON_INGOT)) {
cookingItem = itemEntity;
cookTime = 0;
break;
}
}
} else {
if (cookTime >= 40) {
cookingItem.setItem(new ItemStack(MJItems.AQUARINE_STEEL.get()));
cookingItem = null;
cookTime = 0;
} else {
cookTime++;
ParticlesUtils.spawnParticles(cookingItem,level,ParticleTypes.END_ROD);
}
}

if (cookingItem != null && (!cookingItem.isAlive() || !cookingItem.getItem().is(Items.IRON_INGOT))) {
cookingItem = null;
cookTime = 0;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiB
Object2IntMap<Direction> laserDistances = blockEntity.getLaserDistances();
for (Direction direction : blockEntity.getLaserOutputs()) {
int laserDistance = laserDistances.getOrDefault(direction, 0);
BlockPos targetPos = originPos.relative(direction, laserDistance-2);
BlockPos targetPos = originPos.relative(direction, laserDistance-1);
if(laserDistance != 0){
LaserRendererHelper.renderOuterBeam(blockEntity, originPos, targetPos, direction, poseStack, bufferSource, partialTick);
}
Expand All @@ -43,7 +43,7 @@ public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiB
}
if(laserDistance != 0){
LaserRendererHelper.renderInnerBeam(poseStack, bufferSource, partialTick, blockEntity.getLevel().getGameTime(),
0, laserDistance-1, FastColor.ARGB32.color(202, 214, 224));
0, laserDistance, FastColor.ARGB32.color(202, 214, 224));
}
}
poseStack.popPose();
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/portingdeadmods/modjam/utils/ParticlesUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.portingdeadmods.modjam.utils;

import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.level.Level;

public class ParticlesUtils {

private static final int PARTICLE_COUNT = 20; // Number of particles to spawn
private static final double PARTICLE_RADIUS = 0.5; // Radius of the sphere around the item
private static final int PARTICLE_DELAY = 5; // Number of ticks between particle spawns

private int particleTicks = 0;

public static void spawnParticles(ItemEntity itemEntity, Level level, ParticleOptions particlesTypes) {
// Spawn particles around the item entity in a spherical pattern
if (particleTicks % PARTICLE_DELAY == 0) { // Control particle spawn rate
for (int i = 0; i < PARTICLE_COUNT; i++) {
double theta = level.random.nextDouble() * Math.PI * 2; // Random angle
double phi = level.random.nextDouble() * Math.PI; // Random angle

// Spherical coordinates to Cartesian coordinates
double xOffset = PARTICLE_RADIUS * Math.sin(phi) * Math.cos(theta);
double yOffset = PARTICLE_RADIUS * Math.cos(phi);
double zOffset = PARTICLE_RADIUS * Math.sin(phi) * Math.sin(theta);

level.addParticle(particlesTypes,
itemEntity.getX() + xOffset,
itemEntity.getY() + yOffset,
itemEntity.getZ() + zOffset,
0, 0, 0);
}
}

particleTicks++;
}

}

0 comments on commit 1f5a283

Please sign in to comment.