deduplication

This commit is contained in:
GiantLuigi4 2023-06-07 15:51:40 -04:00
parent 0749e35431
commit 727808adbc
16 changed files with 35 additions and 596 deletions

View File

@ -50,6 +50,7 @@ public class BlockKeyboardLeft extends BlockPeripheral {
private static final Property<?>[] properties = new Property<?>[] {TYPE, FACING};
public BlockKeyboardLeft() {
super(DefaultPeripheral.KEYBOARD);
}
// TODO: make non static (for extensibility purposes)
@ -63,7 +64,7 @@ public class BlockKeyboardLeft extends BlockPeripheral {
BlockPos relative = pos.relative(BlockKeyboardLeft.mapDirection(state.getValue(FACING).getOpposite()));
BlockState ns = world.getBlockState(relative);
if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) {
if(ns.getBlock() instanceof BlockPeripheral) {
BlockEntity te = world.getBlockEntity(relative); // TODO: check?
if (te instanceof TileEntityKeyboard)
return (TileEntityKeyboard) te;
@ -150,10 +151,6 @@ public class BlockKeyboardLeft extends BlockPeripheral {
super.onRemove(arg, arg2, arg3, arg4, bl);
}
public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) {
return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension());
}
@Override
public VoxelShape getOcclusionShape(BlockState arg, BlockGetter arg2, BlockPos arg3) {
return Shapes.empty();

View File

@ -33,6 +33,7 @@ import net.montoyo.wd.utilities.Vector3i;
import org.jetbrains.annotations.NotNull;
import static net.montoyo.wd.block.BlockKeyboardLeft.KEYBOARD_AABBS;
import static net.montoyo.wd.block.BlockPeripheral.point;
// TODO: merge into KeyboardLeft
public class BlockKeyboardRight extends Block implements IPeripheral {
@ -58,7 +59,7 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
if (setState) {
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
}
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> BlockKeyboardLeft.point(world, pos)), new S2CMessageCloseGui(pos));
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
@Override

View File

@ -5,11 +5,9 @@
package net.montoyo.wd.block;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
@ -17,15 +15,11 @@ import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
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.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
@ -36,7 +30,6 @@ import net.minecraftforge.network.PacketDistributor;
import net.montoyo.mcef.utilities.Log;
import net.montoyo.wd.core.DefaultPeripheral;
import net.montoyo.wd.entity.TileEntityInterfaceBase;
import net.montoyo.wd.entity.TileEntityKeyboard;
import net.montoyo.wd.entity.TileEntityPeripheralBase;
import net.montoyo.wd.entity.TileEntityServer;
import net.montoyo.wd.item.ItemLinker;
@ -45,23 +38,17 @@ import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
import org.jetbrains.annotations.Nullable;
public class BlockPeripheral extends WDBlockContainer {
DefaultPeripheral type;
public static final EnumProperty<DefaultPeripheral> type = EnumProperty.create("type", DefaultPeripheral.class);
private static final Property<?>[] properties = new Property<?>[] { type };
public BlockPeripheral() {
public BlockPeripheral(DefaultPeripheral type) {
super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(properties);
this.type = type;
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
BlockEntityType.BlockEntitySupplier<? extends BlockEntity> cls = state.getValue(type).getTEClass();
BlockEntityType.BlockEntitySupplier<? extends BlockEntity> cls = type.getTEClass();
if(cls == null)
return null;
@ -123,39 +110,16 @@ public class BlockPeripheral extends WDBlockContainer {
return PushReaction.IGNORE;
}
private void removeRightPiece(Level world, BlockPos pos) {
for(Direction nf: Direction.Plane.HORIZONTAL) {
BlockPos np = pos.offset(nf.getNormal());
if(world.getBlockState(np).getBlock() instanceof BlockKeyboardRight) {
world.setBlock(np, Blocks.AIR.defaultBlockState(), 3);
break;
}
}
}
@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityPeripheralBase)
if(te instanceof TileEntityPeripheralBase)
((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor);
if(world.isClientSide || state.getValue(type) != DefaultPeripheral.KEYBOARD)
return;
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) {
removeRightPiece(world, pos);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
}
@Override
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
if(!world.isClientSide) {
if(state.getBlock() == this && state.getValue(type) == DefaultPeripheral.KEYBOARD)
removeRightPiece(world, pos);
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
super.playerDestroy(world, player, pos, state, blockEntity, tool);
@ -166,20 +130,6 @@ public class BlockPeripheral extends WDBlockContainer {
playerDestroy(level, null, pos, level.getBlockState(pos), null, null);
}
@Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if(!world.isClientSide && world.getBlockState(pos).getValue(type) == DefaultPeripheral.KEYBOARD) {
double rpos = (entity.getY() - ((double) pos.getY())) * 16.0;
if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityKeyboard)
((TileEntityKeyboard) te).simulateCat(entity);
}
}
}
public static PacketDistributor.TargetPoint point(Player exclude, Level world, BlockPos bp) {
return new PacketDistributor.TargetPoint((ServerPlayer) exclude, bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension());
}

View File

@ -1,145 +0,0 @@
/*
* Copyright (C) 2019 BARBOTIN Nicolas
*/
package net.montoyo.wd.block;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
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.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.PacketDistributor;
import net.montoyo.wd.core.DefaultPeripheral;
import net.montoyo.wd.entity.*;
import net.montoyo.wd.item.ItemLinker;
import net.montoyo.wd.net.WDNetworkRegistry;
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
import org.jetbrains.annotations.Nullable;
public class BlockRCTRL extends WDBlockContainer {
public static final EnumProperty<DefaultPeripheral> type = BlockPeripheral.type;
private static final Property<?>[] properties = new Property<?>[] {type};
public BlockRCTRL() {
super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(properties);
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new TileEntityRCtrl(pos, state);
}
@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(player.isShiftKeyDown())
return InteractionResult.FAIL;
if(player.getItemInHand(hand).getItem() instanceof ItemLinker)
return InteractionResult.FAIL;
BlockEntity te = world.getBlockEntity(pos);
System.out.println(te);
if(te instanceof TileEntityRCtrl)
return ((TileEntityRCtrl) te).onRightClick(player, hand);
else if(te instanceof TileEntityServer) {
((TileEntityServer) te).onPlayerRightClick(player);
return InteractionResult.PASS;
} else
return InteractionResult.FAIL;
}
@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
if(world.isClientSide)
return;
if(placer instanceof Player) {
BlockEntity te = world.getBlockEntity(pos);
if(te instanceof TileEntityServer)
((TileEntityServer) te).setOwner((Player) placer);
else if(te instanceof TileEntityInterfaceBase)
((TileEntityInterfaceBase) te).setOwner((Player) placer);
}
}
@Override
public PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.IGNORE;
}
@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityPeripheralBase)
((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor);
if(world.isClientSide)
return;
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) {
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
}
@Override
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
if(!world.isClientSide) {
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
super.playerDestroy(world, player, pos, state, blockEntity, tool);
}
@Override
public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) {
playerDestroy(level, null, pos, level.getBlockState(pos), null, null);
}
@Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if(!world.isClientSide) {
double rpos = (entity.getY() - ((double) pos.getY())) * 16.0;
if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityKeyboard)
((TileEntityKeyboard) te).simulateCat(entity);
}
}
}
public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) {
return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension());
}
}

View File

@ -1,145 +0,0 @@
/*
* Copyright (C) 2019 BARBOTIN Nicolas
*/
package net.montoyo.wd.block;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
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.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.PacketDistributor;
import net.montoyo.wd.core.DefaultPeripheral;
import net.montoyo.wd.entity.*;
import net.montoyo.wd.item.ItemLinker;
import net.montoyo.wd.net.WDNetworkRegistry;
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
import org.jetbrains.annotations.Nullable;
public class BlockRedCTRL extends WDBlockContainer {
public static final EnumProperty<DefaultPeripheral> type = BlockPeripheral.type;
private static final Property<?>[] properties = new Property<?>[] {type};
public BlockRedCTRL() {
super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(properties);
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new TileEntityRedCtrl(pos, state);
}
@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(player.isShiftKeyDown())
return InteractionResult.FAIL;
if(player.getItemInHand(hand).getItem() instanceof ItemLinker)
return InteractionResult.FAIL;
BlockEntity te = world.getBlockEntity(pos);
if(te instanceof TileEntityRedCtrl)
return ((TileEntityRedCtrl) te).onRightClick(player, hand);
else if(te instanceof TileEntityServer) {
((TileEntityServer) te).onPlayerRightClick(player);
return InteractionResult.PASS;
} else
return InteractionResult.FAIL;
}
@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
if(world.isClientSide)
return;
if(placer instanceof Player) {
BlockEntity te = world.getBlockEntity(pos);
if(te instanceof TileEntityServer)
((TileEntityServer) te).setOwner((Player) placer);
else if(te instanceof TileEntityInterfaceBase)
((TileEntityInterfaceBase) te).setOwner((Player) placer);
}
}
@Override
public PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.IGNORE;
}
@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityPeripheralBase)
((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor);
if(world.isClientSide)
return;
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) {
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
}
@Override
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
if(!world.isClientSide) {
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
super.playerDestroy(world, player, pos, state, blockEntity, tool);
}
@Override
public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) {
playerDestroy(level, null, pos, level.getBlockState(pos), null, null);
}
@Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if(!world.isClientSide) {
double rpos = (entity.getY() - ((double) pos.getY())) * 16.0;
if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityKeyboard)
((TileEntityKeyboard) te).simulateCat(entity);
}
}
}
public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) {
return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension());
}
}

View File

@ -12,7 +12,6 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
@ -38,13 +37,9 @@ import net.montoyo.wd.data.SetURLData;
import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.init.BlockInit;
import net.montoyo.wd.item.ItemLaserPointer;
import net.montoyo.wd.item.WDItem;
import net.montoyo.wd.utilities.*;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BlockScreen extends BaseEntityBlock {
public static final BooleanProperty hasTE = BooleanProperty.create("haste");
@ -326,7 +321,7 @@ public class BlockScreen extends BaseEntityBlock {
BlockPos bp = pos.toBlock();
BlockEntity te = world.getBlockEntity(bp);
if (te != null && te instanceof TileEntityScreen) {
if (te instanceof TileEntityScreen) {
((TileEntityScreen) te).onDestroy(source);
world.setBlock(bp, world.getBlockState(bp).setValue(hasTE, false), Block.UPDATE_ALL_IMMEDIATE); //Destroy tile entity.
}
@ -377,18 +372,4 @@ public class BlockScreen extends BaseEntityBlock {
public boolean isSignalSource (BlockState state){
return state.getValue(emitting);
}
private static class ItemBlockScreen extends BlockItem implements WDItem {
public ItemBlockScreen(BlockScreen screen) {
super(screen, new Properties());
}
@Nullable
@Override
public String getWikiName(@Nonnull ItemStack is) {
return is.getItem().getName(is).getString();
}
}
}

View File

@ -1,145 +0,0 @@
/*
* Copyright (C) 2019 BARBOTIN Nicolas
*/
package net.montoyo.wd.block;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
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.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.PacketDistributor;
import net.montoyo.wd.core.DefaultPeripheral;
import net.montoyo.wd.entity.TileEntityInterfaceBase;
import net.montoyo.wd.entity.TileEntityKeyboard;
import net.montoyo.wd.entity.TileEntityPeripheralBase;
import net.montoyo.wd.entity.TileEntityServer;
import net.montoyo.wd.item.ItemLinker;
import net.montoyo.wd.net.WDNetworkRegistry;
import net.montoyo.wd.net.client_bound.S2CMessageCloseGui;
import org.jetbrains.annotations.Nullable;
public class BlockServer extends WDBlockContainer{
public static final EnumProperty<DefaultPeripheral> type = BlockPeripheral.type;
private static final Property<?>[] properties = new Property<?>[] {type};
public BlockServer() {
super(BlockBehaviour.Properties.of(Material.STONE).strength(1.5f, 10.f));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(properties);
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new TileEntityServer(pos, state);
}
@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(player.isShiftKeyDown())
return InteractionResult.FAIL;
if(player.getItemInHand(hand).getItem() instanceof ItemLinker)
return InteractionResult.FAIL;
BlockEntity te = world.getBlockEntity(pos);
if(te instanceof TileEntityServer) {
((TileEntityServer) te).onPlayerRightClick(player);
return InteractionResult.SUCCESS;
} else
return InteractionResult.FAIL;
}
@Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
if(world.isClientSide)
return;
if(placer instanceof Player) {
BlockEntity te = world.getBlockEntity(pos);
if(te instanceof TileEntityServer)
((TileEntityServer) te).setOwner((Player) placer);
else if(te instanceof TileEntityInterfaceBase)
((TileEntityInterfaceBase) te).setOwner((Player) placer);
}
}
@Override
public PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.IGNORE;
}
@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor, boolean isMoving) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityPeripheralBase)
((TileEntityPeripheralBase) te).onNeighborChange(neighborType, neighbor);
if(world.isClientSide)
return;
if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isEmptyBlock(neighbor)) {
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
}
@Override
public void playerDestroy(Level world, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {
if(!world.isClientSide) {
WDNetworkRegistry.INSTANCE.send(PacketDistributor.NEAR.with(() -> point(world, pos)), new S2CMessageCloseGui(pos));
}
super.playerDestroy(world, player, pos, state, blockEntity, tool);
}
@Override
public void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) {
playerDestroy(level, null, pos, level.getBlockState(pos), null, null);
}
@Override
public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if(!world.isClientSide) {
double rpos = (entity.getY() - ((double) pos.getY())) * 16.0;
if(rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) {
BlockEntity te = world.getBlockEntity(pos);
if(te != null && te instanceof TileEntityKeyboard)
((TileEntityKeyboard) te).simulateCat(entity);
}
}
}
public static PacketDistributor.TargetPoint point(Level world, BlockPos bp) {
return new PacketDistributor.TargetPoint(bp.getX(), bp.getY(), bp.getZ(), 64.0, world.dimension());
}
}

View File

@ -1,30 +0,0 @@
/*
* Copyright (C) 2018 BARBOTIN Nicolas
*/
package net.montoyo.wd.block;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
public abstract class WDBlock extends Block {
protected BlockItem itemBlock;
public WDBlock(Properties properties) {
super(properties);
}
public void makeItemBlock() {
if(itemBlock != null)
throw new RuntimeException("WDBlock.makeItemBlock() called twice!");
itemBlock = new BlockItem(this, new Item.Properties());
}
public BlockItem getItem() {
return itemBlock;
}
}

View File

@ -12,18 +12,19 @@ import net.montoyo.wd.entity.TileEntityKeyboard;
import net.montoyo.wd.entity.TileEntityRCtrl;
import net.montoyo.wd.entity.TileEntityRedCtrl;
import net.montoyo.wd.entity.TileEntityServer;
import net.montoyo.wd.init.BlockInit;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public enum DefaultPeripheral implements StringRepresentable {
KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard::new, TileEntityKeyboard::getBlockFromTE), //WITH FACING (< 3)
KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard::new, BlockInit.blockKeyBoard), //WITH FACING (< 3)
// CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class),
// OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class),
REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl::new ,TileEntityRCtrl::getBlockFromTE), //WITHOUT FACING (>= 3)
REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl::new ,TileEntityRedCtrl::getBlockFromTE),
SERVER("server", "Server", TileEntityServer::new, TileEntityServer::getBlockFromTE);
REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl::new ,BlockInit.blockRControl), //WITHOUT FACING (>= 3)
REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl::new ,BlockInit.blockRedControl),
SERVER("server", "Server", TileEntityServer::new, BlockInit.blockServer);
private final String name;
private final String wikiName;

View File

@ -11,10 +11,8 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Ocelot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.block.BlockPeripheral;
import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.KeyboardData;
import net.montoyo.wd.init.TileInit;
@ -32,10 +30,6 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase {
blockState = arg3;
}
public static Block getBlockFromTE() {
return new BlockPeripheral().defaultBlockState().getBlock();
}
@Override
public InteractionResult onRightClick(Player player, InteractionHand hand) {
if(level.isClientSide)

View File

@ -9,14 +9,10 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.block.BlockPeripheral;
import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.SetURLData;
import net.montoyo.wd.init.TileInit;
import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Util;
public class TileEntityRCtrl extends TileEntityPeripheralBase {
@ -29,10 +25,6 @@ public class TileEntityRCtrl extends TileEntityPeripheralBase {
blockState = arg3;
}
public static Block getBlockFromTE() {
return new BlockPeripheral().defaultBlockState().getBlock();
}
@Override
public InteractionResult onRightClick(Player player, InteractionHand hand) {
if(level.isClientSide)

View File

@ -12,7 +12,6 @@ import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.block.BlockPeripheral;
import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.RedstoneCtrlData;
import net.montoyo.wd.init.TileInit;
@ -33,10 +32,6 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
blockPos = arg2;
blockState = arg3;
}
public static Block getBlockFromTE() {
return new BlockPeripheral().defaultBlockState().getBlock();
}
@Override
public void load(CompoundTag tag) {

View File

@ -7,7 +7,11 @@ import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import net.montoyo.wd.block.*;
import net.montoyo.wd.block.BlockKeyboardLeft;
import net.montoyo.wd.block.BlockKeyboardRight;
import net.montoyo.wd.block.BlockPeripheral;
import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.core.DefaultPeripheral;
public class BlockInit {
@ -22,9 +26,7 @@ public class BlockInit {
public static final RegistryObject<BlockKeyboardLeft> blockKeyBoard = BlockInit.BLOCKS.register("kb_left", BlockKeyboardLeft::new);
public static final RegistryObject<BlockKeyboardRight> blockKbRight = BLOCKS.register("kb_right", BlockKeyboardRight::new);
public static final RegistryObject<BlockRedCTRL> blockRedControl = BlockInit.BLOCKS.register("redctrl", BlockRedCTRL::new);
public static final RegistryObject<BlockRCTRL> blockRControl = BlockInit.BLOCKS.register("rctrl", BlockRCTRL::new);
public static final RegistryObject<BlockServer> blockServer = BlockInit.BLOCKS.register("server", BlockServer::new);
public static final RegistryObject<BlockPeripheral> blockRedControl = BlockInit.BLOCKS.register("redctrl", () -> new BlockPeripheral(DefaultPeripheral.REDSTONE_CONTROLLER));
public static final RegistryObject<BlockPeripheral> blockRControl = BlockInit.BLOCKS.register("rctrl", () -> new BlockPeripheral(DefaultPeripheral.REMOTE_CONTROLLER));
public static final RegistryObject<BlockPeripheral> blockServer = BlockInit.BLOCKS.register("server", () -> new BlockPeripheral(DefaultPeripheral.SERVER));
}

View File

@ -1,10 +1,7 @@
{
"forge_marker": 1,
"uvlock": false,
"variants": {
"facing=north": { "model": "webdisplays:block/rctrl" },
"facing=east": { "model": "webdisplays:block/rctrl" },
"facing=south": { "model": "webdisplays:block/rctrl" },
"facing=west": { "model": "webdisplays:block/rctrl" }
"": {
"model": "webdisplays:block/rctrl"
}
}
}
}

View File

@ -1,10 +1,7 @@
{
"forge_marker": 1,
"uvlock": false,
"variants": {
"facing=north": { "model": "webdisplays:block/redctrl" },
"facing=east": { "model": "webdisplays:block/redctrl" },
"facing=south": { "model": "webdisplays:block/redctrl" },
"facing=west": { "model": "webdisplays:block/redctrl" }
"": {
"model": "webdisplays:block/redctrl"
}
}
}
}

View File

@ -1,10 +1,7 @@
{
"forge_marker": 1,
"uvlock": false,
"variants": {
"facing=north": { "model": "webdisplays:block/server" },
"facing=east": { "model": "webdisplays:block/server" },
"facing=south": { "model": "webdisplays:block/server" },
"facing=west": { "model": "webdisplays:block/server" }
"": {
"model": "webdisplays:block/server"
}
}
}
}