beginning of gunpowdering being useful
This commit is contained in:
parent
563d579aab
commit
c735b06779
|
@ -1,15 +1,21 @@
|
||||||
package me.parsell.wireddust.common;
|
package me.parsell.wireddust.common;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
|
import net.minecraft.block.CampfireBlock;
|
||||||
|
import net.minecraft.block.TntBlock;
|
||||||
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.BooleanProperty;
|
import net.minecraft.state.property.BooleanProperty;
|
||||||
import net.minecraft.state.property.Properties;
|
import net.minecraft.state.property.Properties;
|
||||||
|
@ -17,104 +23,127 @@ import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Box;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Direction.Axis;
|
import net.minecraft.util.math.Direction.Axis;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldAccess;
|
||||||
|
|
||||||
// TODO: All the magic to make this work the way i want
|
// TODO: All the magic to make this work the way i want
|
||||||
public class WDGunpowderWireBlock extends WDWireBlock{
|
public class WDGunpowderWireBlock extends WDWireBlock{
|
||||||
public static final BooleanProperty LIT;
|
public static final BooleanProperty LIT;
|
||||||
|
public static final BooleanProperty BURNT;
|
||||||
|
|
||||||
public WDGunpowderWireBlock(Settings settings) {
|
public WDGunpowderWireBlock(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WIRE_CONNECTION_NORTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_EAST, WDWireConnection.NONE)).with(WIRE_CONNECTION_SOUTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_WEST, WDWireConnection.NONE)).with(LIT, false));
|
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WIRE_CONNECTION_NORTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_EAST, WDWireConnection.NONE)).with(WIRE_CONNECTION_SOUTH, WDWireConnection.NONE)).with(WIRE_CONNECTION_WEST, WDWireConnection.NONE)).with(LIT, false).with(BURNT, false));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
|
||||||
super.appendProperties(builder.add(LIT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasUpConnection(BlockState state){
|
@Override
|
||||||
return ((WDWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnectedUp() ||
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||||
((WDWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnectedUp() ||
|
super.appendProperties(builder.add(LIT, BURNT));
|
||||||
((WDWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnectedUp() ||
|
}
|
||||||
((WDWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnectedUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean pp = true;
|
private boolean hasUpConnection(BlockState state){
|
||||||
|
return ((WDWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnectedUp() ||
|
||||||
|
((WDWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnectedUp() ||
|
||||||
|
((WDWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnectedUp() ||
|
||||||
|
((WDWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnectedUp();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Supprt UP state
|
@Environment(EnvType.CLIENT)
|
||||||
@Environment(EnvType.CLIENT)
|
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
|
||||||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
|
if (state.get(LIT)){
|
||||||
if (state.get(LIT)){
|
// get random double, within bounds x/y_min and x/y_max
|
||||||
// get random double, within bounds x/y_min and x/y_max
|
double x_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.X);
|
||||||
double x_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.X);
|
double z_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.Z);
|
||||||
double z_min = super.STATE_TO_VOXELSHAPE.get(state).getMin(Axis.Z);
|
double x_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.X);
|
||||||
double x_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.X);
|
double z_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.Z);
|
||||||
double z_max = super.STATE_TO_VOXELSHAPE.get(state).getMax(Axis.Z);
|
|
||||||
|
double x_rand = x_min + (x_max - x_min) * random.nextDouble();
|
||||||
double x_rand = x_min + (x_max - x_min) * random.nextDouble();
|
double z_rand = z_min + (z_max - z_min) * random.nextDouble();
|
||||||
double z_rand = z_min + (z_max - z_min) * random.nextDouble();
|
|
||||||
|
|
||||||
double y_rand = 0.1d;
|
double y_rand = 0.1d;
|
||||||
|
|
||||||
if (hasUpConnection(state)){
|
if (hasUpConnection(state)){
|
||||||
if (z_rand < 0.1d && state.get(WIRE_CONNECTION_NORTH).isConnectedUp() ||
|
if (z_rand < 0.1d && state.get(WIRE_CONNECTION_NORTH).isConnectedUp() ||
|
||||||
z_rand > 0.9d && state.get(WIRE_CONNECTION_SOUTH).isConnectedUp() ||
|
z_rand > 0.9d && state.get(WIRE_CONNECTION_SOUTH).isConnectedUp() ||
|
||||||
x_rand < 0.1d && state.get(WIRE_CONNECTION_WEST).isConnectedUp() ||
|
x_rand < 0.1d && state.get(WIRE_CONNECTION_WEST).isConnectedUp() ||
|
||||||
x_rand > 0.9d && state.get(WIRE_CONNECTION_EAST).isConnectedUp()) {
|
x_rand > 0.9d && state.get(WIRE_CONNECTION_EAST).isConnectedUp()) {
|
||||||
y_rand = 0.1D + (0.9D - 0.1D) * random.nextDouble();
|
y_rand = 0.1D + (0.9D - 0.1D) * random.nextDouble();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("X: %1.2f | Y: %1.2f | Z: %1.2f\n", x_rand, y_rand, z_rand);
|
world.addParticle(ParticleTypes.FLAME, pos.getX() + x_rand, pos.getY() + y_rand, pos.getZ() + z_rand, 0.0, 0.0, 0.0);
|
||||||
|
super.randomDisplayTick(state, world, pos, random);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//NEW
|
// TODO: TEST KILLING MINECRAFT WITH REDSTONE & FILL COMMANDS
|
||||||
/*
|
@Override
|
||||||
double rand_x, rand_y, rand_z;
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
|
||||||
boolean validParticle = false;
|
if(world.isClient)
|
||||||
|
if(player.getStackInHand(hand).getItem().equals(Items.FLINT_AND_STEEL) || !player.hasStackEquipped(EquipmentSlot.MAINHAND))
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
else
|
||||||
|
return ActionResult.PASS;
|
||||||
|
if(player.abilities.allowModifyWorld){
|
||||||
|
if(!state.get(LIT) && player.getStackInHand(hand).getItem().equals(Items.FLINT_AND_STEEL)){
|
||||||
|
player.getStackInHand(hand).damage(1, world.getRandom(), (ServerPlayerEntity)player);
|
||||||
|
light(world, pos, state);
|
||||||
|
return ActionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pp) {
|
super.onUse(state, world, pos, player, hand, hit);
|
||||||
pp = false;
|
return ActionResult.PASS;
|
||||||
System.out.println(super.STATE_TO_VOXELSHAPE.get(state).getBoundingBoxes().size());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
do{
|
public void light(World world, BlockPos pos, BlockState state){
|
||||||
rand_x = random.nextDouble();
|
world.setBlockState(pos, state.with(LIT, true));
|
||||||
rand_y = random.nextDouble();
|
scheduleTick(world, pos);
|
||||||
rand_z = random.nextDouble();
|
}
|
||||||
|
|
||||||
for (Box b : super.STATE_TO_VOXELSHAPE.get(state).getBoundingBoxes()){
|
public void scheduleTick(WorldAccess world, BlockPos pos) {
|
||||||
if (b.contains(rand_x, rand_y, rand_z))
|
if (!world.isClient() && !world.getBlockTickScheduler().isScheduled(pos, this)) {
|
||||||
validParticle = true;
|
world.getBlockTickScheduler().schedule(pos, this, 60);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}while (!validParticle); */
|
}
|
||||||
|
|
||||||
world.addParticle(ParticleTypes.FLAME, pos.getX() + x_rand, pos.getY() + y_rand, pos.getZ() + z_rand, 0.0, 0.0, 0.0);
|
// Three things need to happen'
|
||||||
super.randomDisplayTick(state, world, pos, random);
|
// 1. Set neighbors to lit, if self and schedule another tick update ✓
|
||||||
}
|
// 2. start fire on "flammable" blocks and schedule another tick update | half ✓
|
||||||
}
|
// 3. Destroy self ✓
|
||||||
|
@Override
|
||||||
|
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||||
|
if(!state.get(BURNT)) {
|
||||||
|
Iterator<Direction> dirItr = Direction.Type.HORIZONTAL.iterator();
|
||||||
|
while(dirItr.hasNext()) {
|
||||||
|
Direction dir = dirItr.next();
|
||||||
|
BlockPos offsetPos = pos.offset(dir);
|
||||||
|
BlockState offsetBlockState = world.getBlockState(offsetPos);
|
||||||
|
|
||||||
|
if(state.get(super.DIRECTION_TO_WIRE_CONNECTION.get(dir)).isConnected())
|
||||||
|
if(offsetBlockState.isOf(this))
|
||||||
|
light(world, offsetPos, offsetBlockState);
|
||||||
|
else if(offsetBlockState.isOf(Blocks.TNT)) {
|
||||||
|
TntBlock.primeTnt(world, offsetPos);
|
||||||
|
world.setBlockState(offsetPos, Blocks.AIR.getDefaultState());
|
||||||
|
} else if(offsetBlockState.isOf(Blocks.CAMPFIRE) && !offsetBlockState.get(CampfireBlock.LIT))
|
||||||
|
world.setBlockState(offsetPos, offsetBlockState.with(CampfireBlock.LIT, true));
|
||||||
|
else if(false) // TODO: make flammable blocks array
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: TEST KILLING MINECRAFT WITH REDSTONE & FILL COMMANDS
|
world.setBlockState(pos, state.with(BURNT, true));
|
||||||
@Override
|
scheduleTick(world, pos);
|
||||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
|
} else {
|
||||||
if(world.isClient)
|
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||||
return ActionResult.SUCCESS;
|
}
|
||||||
if(player.abilities.allowModifyWorld){
|
}
|
||||||
if(!state.get(LIT) && player.getStackInHand(hand).getItem().equals(Items.FLINT_AND_STEEL)){
|
|
||||||
player.getStackInHand(hand).damage(1, world.getRandom(), (ServerPlayerEntity)player);
|
static {
|
||||||
world.setBlockState(pos, state.with(LIT, true));
|
LIT = Properties.LIT;
|
||||||
return ActionResult.SUCCESS;
|
BURNT = BooleanProperty.of("burnt");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
super.onUse(state, world, pos, player, hand, hit);
|
|
||||||
return ActionResult.PASS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
LIT = Properties.LIT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue