This commit is contained in:
parent
5027e7f984
commit
487a1aa6e0
@ -2,6 +2,7 @@ package com.thebrokenrail.energonrelics;
|
||||
|
||||
import com.thebrokenrail.energonrelics.block.BlockBreakerBlock;
|
||||
import com.thebrokenrail.energonrelics.block.DefensiveLaserBlock;
|
||||
import com.thebrokenrail.energonrelics.block.LightningRodBlock;
|
||||
import com.thebrokenrail.energonrelics.block.VeridiumBlockBlock;
|
||||
import com.thebrokenrail.energonrelics.block.structure.StructureGeneratorBlock;
|
||||
import com.thebrokenrail.energonrelics.block.ThermalGlassBlock;
|
||||
@ -70,6 +71,8 @@ public class EnergonRelics implements ModInitializer {
|
||||
|
||||
public static final Item VERIDIUM_POWDER_ITEM = new Item(new Item.Settings().group(ITEM_GROUP));
|
||||
|
||||
public static final LightningRodBlock LIGHTNING_ROD_BLOCK = new LightningRodBlock();
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
NETWORK_CHIP_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "network_chip"), new NetworkChipItem());
|
||||
@ -106,5 +109,7 @@ public class EnergonRelics implements ModInitializer {
|
||||
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "veridium_powder"), VERIDIUM_POWDER_ITEM);
|
||||
|
||||
CustomPotions.register();
|
||||
|
||||
LIGHTNING_ROD_BLOCK.register("lightning_rod");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.thebrokenrail.energonrelics.block;
|
||||
|
||||
import com.thebrokenrail.energonrelics.block.entity.LightningRodBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.block.util.energy.EnergyProviderBlock;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class LightningRodBlock extends EnergyProviderBlock {
|
||||
public LightningRodBlock() {
|
||||
super(FabricBlockSettings.of(Material.STONE, MaterialColor.BLUE_TERRACOTTA).nonOpaque().allowsSpawning((state, world, pos, type) -> false).solidBlock((state, world, pos) -> false).suffocates((state, world, pos) -> false).emissiveLighting((state, world, pos) -> true).lightLevel(10).requiresTool().strength(1.5f, 6.0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@Environment(EnvType.CLIENT)
|
||||
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
|
||||
return 1f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<BlockEntityType<BlockEntity>, BlockEntity> getFactory() {
|
||||
return LightningRodBlockEntity::new;
|
||||
}
|
||||
|
||||
private static final VoxelShape SHAPE = VoxelShapes.union(createCuboidShape(3d, 0d, 3d, 13d, 2d, 13d), createCuboidShape(7.5d, 2d, 7.5d, 8.5d, 26d, 8.5d));
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package com.thebrokenrail.energonrelics.block.entity;
|
||||
|
||||
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
||||
import com.thebrokenrail.energonrelics.energy.core.EnergyProviderBlockEntity;
|
||||
import com.thebrokenrail.energonrelics.energy.core.util.Action;
|
||||
import com.thebrokenrail.energonrelics.energy.helper.EnergyGenerator;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LightningEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.LightType;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class LightningRodBlockEntity extends EnergyProviderBlockEntity implements EnergyGenerator {
|
||||
public LightningRodBlockEntity(BlockEntityType<?> type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
private int getLight() {
|
||||
if (hasWorld() && Objects.requireNonNull(getWorld()).getDimension().hasSkyLight() && getWorld().isThundering()) {
|
||||
assert getWorld() != null;
|
||||
return getWorld().getLightLevel(LightType.SKY, getPos());
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int cooldown = 0;
|
||||
private long energy = 0;
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public long getDisplayEnergy() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergy() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(long energy) {
|
||||
this.energy = energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void serverTick() {
|
||||
if (cooldown <= 0) {
|
||||
energy = 0;
|
||||
|
||||
if (getLight() > 0) {
|
||||
if (random.nextDouble() <= HardcodedConfig.LIGHTNING_ROD_CHANCE) {
|
||||
LightningEntity entity = EntityType.LIGHTNING_BOLT.create(getWorld());
|
||||
assert entity != null;
|
||||
entity.updatePosition(getPos().getX() + 0.5d, getPos().getY() + 0.5d, getPos().getZ() + 0.5d);
|
||||
entity.method_29498(true);
|
||||
Objects.requireNonNull(getWorld()).spawnEntity(entity);
|
||||
|
||||
cooldown = HardcodedConfig.LIGHTNING_ROD_COOLDOWN;
|
||||
energy = HardcodedConfig.LIGHTNING_ROD_ENERGY_OUTPUT;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cooldown--;
|
||||
}
|
||||
super.serverTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
tag.putInt("Cooldown", cooldown);
|
||||
tag.putLong("Energy", energy);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
cooldown = tag.getInt("Cooldown");
|
||||
energy = tag.getLong("Energy");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePropagatedAction(Action.PropagatedAction action) {
|
||||
super.handlePropagatedAction(action);
|
||||
handlePropagatedActionWithGenerator(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnergyProvider() {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ public class SolarPanelBlockEntity extends EnergyGeneratorBlockEntity {
|
||||
|
||||
@Override
|
||||
protected void serverTick() {
|
||||
super.serverTick();
|
||||
setEnergy(getDisplayEnergy());
|
||||
super.serverTick();
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ public class ReactorControllerBlockEntity extends EnergyGeneratorBlockEntity {
|
||||
|
||||
@Override
|
||||
protected void serverTick() {
|
||||
super.serverTick();
|
||||
if (getCachedState().get(ReactorControllerBlock.POWERED)) {
|
||||
Reactor reactor = getReactor();
|
||||
if (reactor != null && !reactor.core.isReacting()) {
|
||||
@ -63,6 +62,7 @@ public class ReactorControllerBlockEntity extends EnergyGeneratorBlockEntity {
|
||||
}
|
||||
}
|
||||
setEnergy(getDisplayEnergy());
|
||||
super.serverTick();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,4 +23,8 @@ public class HardcodedConfig {
|
||||
public static final long BLOCK_BREAKER_ENERGY_REQUIRED_BREAK = 36;
|
||||
public static final int BLOCK_BREAKER_TIME = 48;
|
||||
public static final Item BLOCK_BREAKER_ITEM = Items.IRON_PICKAXE;
|
||||
|
||||
public static final long LIGHTNING_ROD_ENERGY_OUTPUT = 50000;
|
||||
public static final double LIGHTNING_ROD_CHANCE = 0.00005d;
|
||||
public static final int LIGHTNING_ROD_COOLDOWN = 5;
|
||||
}
|
||||
|
@ -38,8 +38,6 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
||||
|
||||
@Override
|
||||
public void serverTick() {
|
||||
super.serverTick();
|
||||
|
||||
ServerWorld world = (ServerWorld) getWorld();
|
||||
assert world != null;
|
||||
NetworkComponent component = NetworkComponent.getInstance(world);
|
||||
@ -61,6 +59,8 @@ public abstract class EnergyReceiverBlockEntity extends EnergyProviderBlockEntit
|
||||
pendingActions.clear();
|
||||
tickEnergy();
|
||||
|
||||
super.serverTick();
|
||||
|
||||
for (Action.PropagatedAction action : pendingPropagatedActions) {
|
||||
propagateAction(action);
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ public abstract class EnergyGeneratorBlockEntity extends EnergyProviderBlockEnti
|
||||
|
||||
@Override
|
||||
public void setEnergy(long value) {
|
||||
if (value < 0) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
energy = value;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ public class MultimeterItem extends Item {
|
||||
String str;
|
||||
if (value >= Long.MAX_VALUE) {
|
||||
str = "\u221e";
|
||||
} else if (value == -1) {
|
||||
str = "N/A";
|
||||
} else {
|
||||
str = String.valueOf(value);
|
||||
}
|
||||
|
@ -34,5 +34,5 @@
|
||||
"item.minecraft.splash_potion.effect.energonrelics.veridium_poison": "Splash Potion of Degradation",
|
||||
"item.minecraft.lingering_potion.effect.energonrelics.veridium_poison": "Lingering Potion of Degradation",
|
||||
"item.minecraft.tipped_arrow.effect.energonrelics.veridium_poison": "Arrow of Degradation",
|
||||
"block.energonnrelics.lightning_rod": "Lightning Rod"
|
||||
"block.energonrelics.lightning_rod": "Lightning Rod"
|
||||
}
|
@ -7,14 +7,14 @@
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [0, 0, 0],
|
||||
"to": [16, 2, 16],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [11, 8, 11]},
|
||||
"from": [3, 0, 3],
|
||||
"to": [13, 2, 13],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]},
|
||||
"faces": {
|
||||
"north": {"uv": [0, 0, 16, 2], "texture": "#2"},
|
||||
"east": {"uv": [0, 0, 16, 2], "texture": "#2"},
|
||||
"south": {"uv": [0, 0, 16, 2], "texture": "#2"},
|
||||
"west": {"uv": [0, 0, 16, 2], "texture": "#2"},
|
||||
"north": {"uv": [3, 0, 13, 2], "texture": "#2"},
|
||||
"east": {"uv": [3, 0, 13, 2], "texture": "#2"},
|
||||
"south": {"uv": [3, 0, 13, 2], "texture": "#2"},
|
||||
"west": {"uv": [3, 0, 13, 2], "texture": "#2"},
|
||||
"up": {"uv": [0, 0, 16, 16], "texture": "#2"},
|
||||
"down": {"uv": [0, 0, 16, 16], "texture": "#2"}
|
||||
}
|
||||
@ -22,7 +22,7 @@
|
||||
{
|
||||
"from": [7.5, 2, 7.5],
|
||||
"to": [8.5, 18, 8.5],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [15, 10, 14]},
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]},
|
||||
"faces": {
|
||||
"north": {"uv": [0, 0, 1, 16], "texture": "#1"},
|
||||
"east": {"uv": [0, 0, 1, 16], "texture": "#1"},
|
||||
@ -35,7 +35,7 @@
|
||||
{
|
||||
"from": [7.5, 18, 7.5],
|
||||
"to": [8.5, 26, 8.5],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [15, 10, 14]},
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [0, 0, 0]},
|
||||
"faces": {
|
||||
"north": {"uv": [1, 8, 2, 16], "texture": "#1"},
|
||||
"east": {"uv": [1, 8, 2, 16], "texture": "#1"},
|
||||
@ -45,5 +45,17 @@
|
||||
"down": {"uv": [0, 0, 0, 0], "texture": "#1"}
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"display": {
|
||||
"gui": {
|
||||
"rotation": [30, 225, 0],
|
||||
"translation": [0, -1.5, 0],
|
||||
"scale": [0.46875, 0.46875, 0.46875]
|
||||
},
|
||||
"fixed": {
|
||||
"rotation": [0, 0, 0],
|
||||
"translation": [0, -2, 0],
|
||||
"scale": [0.375, 0.375, 0.375]
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 533 B After Width: | Height: | Size: 546 B |
Reference in New Issue
Block a user