ModernLifePatch/src-source/main/java/com/dairymoose/modernlife/tileentities/RadiatorBlockEntity.java
2024-10-26 09:40:21 +08:00

95 lines
4.3 KiB
Java

package com.dairymoose.modernlife.tileentities;
import com.dairymoose.modernlife.blocks.RadiatorBlock;
import com.dairymoose.modernlife.core.CustomBlocks;
import com.mojang.datafixers.types.Type;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/tileentities/RadiatorBlockEntity.class */
public class RadiatorBlockEntity extends BlockEntity {
public static final BlockEntityType<RadiatorBlockEntity> RADIATOR = BlockEntityType.Builder.of(RadiatorBlockEntity::new, new Block[]{(Block) CustomBlocks.BLOCK_RADIATOR.get()}).build((Type) null);
private static final Logger LOGGER = LogManager.getLogger();
private double multLow;
private double multMed;
private double multHigh;
final int LOW_DIAMETER = 9;
final int MED_DIAMETER = 13;
final int HIGH_DIAMETER = 19;
public RadiatorBlockEntity(BlockPos pos, BlockState state) {
super(RADIATOR, pos, state);
this.multLow = 1.0d;
this.multMed = 1.6d;
this.multHigh = 2.56d;
this.LOW_DIAMETER = 9;
this.MED_DIAMETER = 13;
this.HIGH_DIAMETER = 19;
}
private void meltTargetedSpot(ServerLevel world, BlockPos targetPos, double meltMult) {
double meltChance = 1.0d / targetPos.distSqr(getBlockPos());
if (Math.random() >= meltChance * 1.0d * meltMult) {
return;
}
BlockState targetBlockState = world.getBlockState(targetPos);
if (targetBlockState.is(Blocks.ICE) || targetBlockState.is(Blocks.PACKED_ICE) || targetBlockState.is(Blocks.BLUE_ICE) || targetBlockState.is(Blocks.FROSTED_ICE)) {
world.setBlockAndUpdate(targetPos, Blocks.WATER.defaultBlockState());
world.neighborChanged(targetPos, Blocks.WATER, targetPos);
} else if (targetBlockState.is(Blocks.SNOW) || targetBlockState.is(Blocks.SNOW_BLOCK)) {
targetBlockState.getOptionalValue(BlockStateProperties.SNOWY);
world.sendParticles(ParticleTypes.LARGE_SMOKE, targetPos.getX() + 0.5d, targetPos.getY() + 0.5d, targetPos.getZ() + 0.5d, 0, 0.0d, 0.0d, 0.0d, 0.0d);
world.m_46961_(targetPos, false);
}
}
public void meltSnow(int meltDiameter, double meltMult, int n) {
for (int i = 0; i < n; i++) {
int xOffset = ((int) (meltDiameter * Math.random())) - (meltDiameter / 2);
int zOffset = ((int) (meltDiameter * Math.random())) - (meltDiameter / 2);
Level level = getLevel();
if (level instanceof ServerLevel) {
ServerLevel world = (ServerLevel) level;
BlockPos targetPos = new BlockPos(getBlockPos().getX() + xOffset, getBlockPos().getY(), getBlockPos().getZ() + zOffset);
meltTargetedSpot(world, targetPos, meltMult);
meltTargetedSpot(world, targetPos.below(), meltMult);
meltTargetedSpot(world, targetPos.below().below(), meltMult);
meltTargetedSpot(world, targetPos.above(), meltMult);
meltTargetedSpot(world, targetPos.above().above(), meltMult);
}
}
}
public static void tick(Level level, BlockPos pos, BlockState state, RadiatorBlockEntity entity) {
entity.tick();
}
public void tick() {
RadiatorBlock.HeatType heat = (RadiatorBlock.HeatType) getBlockState().getValue(RadiatorBlock.HEAT);
switch (heat) {
case HeatType.off:
default:
return;
case HeatType.low:
meltSnow(9, this.multLow, 1);
return;
case HeatType.medium:
meltSnow(13, this.multMed, 2);
return;
case HeatType.high:
meltSnow(19, this.multHigh, 5);
return;
}
}
}