everything but one

This commit is contained in:
Mysticpasta1 2022-06-24 07:48:31 -05:00
parent e6a5d38f55
commit 1cfbb02d6e
17 changed files with 136 additions and 106 deletions

View File

@ -22,6 +22,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity; 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.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
@ -112,12 +113,12 @@ public class BlockPeripheral extends BaseEntityBlock {
@Nullable @Nullable
@Override @Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
Class<? extends BlockEntity> cls = state.getValue(type).getTEClass(); BlockEntityType.BlockEntitySupplier<? extends BlockEntity> cls = state.getValue(type).getTEClass();
if(cls == null) if(cls == null)
return null; return null;
try { try {
return cls.newInstance(); return cls.create(pos, state); //TODO does this even work!
} catch(Throwable t) { } catch(Throwable t) {
Log.errorEx("Couldn't instantiate peripheral TileEntity:", t); Log.errorEx("Couldn't instantiate peripheral TileEntity:", t);
} }

View File

@ -5,17 +5,12 @@
package net.montoyo.wd.block; package net.montoyo.wd.block;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.block.state.IBlockState;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.Explosion;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.World; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -33,6 +28,7 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.block.state.properties.Property; import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
@ -45,6 +41,7 @@ import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.init.BlockInit; import net.montoyo.wd.init.BlockInit;
import net.montoyo.wd.item.WDItem; import net.montoyo.wd.item.WDItem;
import net.montoyo.wd.utilities.*; import net.montoyo.wd.utilities.*;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -98,7 +95,7 @@ public class BlockScreen extends BaseEntityBlock {
return super.updateShape(state, direction, neighborState, level, currentPos, neighborPos); return super.updateShape(state, direction, neighborState, level, currentPos, neighborPos);
} }
@Override /* @Override
@Nonnull @Nonnull
public BlockState getExtendedState(@Nonnull BlockState ret, Level world, BlockPos bpos) { public BlockState getExtendedState(@Nonnull BlockState ret, Level world, BlockPos bpos) {
Vector3i pos = new Vector3i(bpos); Vector3i pos = new Vector3i(bpos);
@ -114,7 +111,7 @@ public class BlockScreen extends BaseEntityBlock {
} }
return ret; return ret;
} }*/
// @Override // @Override
// @Nonnull // @Nonnull
@ -328,28 +325,23 @@ public class BlockScreen extends BaseEntityBlock {
private void destroySide(Level world, Vector3i pos, BlockSide side, Multiblock.BlockOverride override, Player source) { private void destroySide(Level world, Vector3i pos, BlockSide side, Multiblock.BlockOverride override, Player source) {
Multiblock.findOrigin(world, pos, side, override); Multiblock.findOrigin(world, pos, side, override);
BlockPos bp = pos.toBlock(); BlockPos bp = pos.toBlock();
TileEntity te = world.getTileEntity(bp); BlockEntity te = world.getBlockEntity(bp);
if(te != null && te instanceof TileEntityScreen) { if(te != null && te instanceof TileEntityScreen) {
((TileEntityScreen) te).onDestroy(source); ((TileEntityScreen) te).onDestroy(source);
world.setBlockState(bp, world.getBlockState(bp).withProperty(hasTE, false)); //Destroy tile entity. world.setBlock(bp, world.getBlockState(bp).setValue(hasTE, false), Block.UPDATE_ALL_IMMEDIATE); //Destroy tile entity.
} }
} }
@Override @Override
public boolean removedByPlayer(@Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer ply, boolean willHarvest) { public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
onDestroy(world, pos, ply); onDestroy(level, pos, player);
return super.removedByPlayer(state, world, pos, ply, willHarvest); return super.onDestroyedByPlayer(state, level, pos, player, willHarvest, fluid);
} }
@Override @Override
public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) { public void setPlacedBy(Level world, @NotNull BlockPos pos, @NotNull BlockState state, @org.jetbrains.annotations.Nullable LivingEntity whoDidThisShit, @NotNull ItemStack stack) {
onDestroy(world, pos, null); if(world.isClientSide)
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase whoDidThisShit, ItemStack stack) {
if(world.isRemote)
return; return;
Multiblock.BlockOverride override = new Multiblock.BlockOverride(new Vector3i(pos), Multiblock.OverrideAction.IGNORE); Multiblock.BlockOverride override = new Multiblock.BlockOverride(new Vector3i(pos), Multiblock.OverrideAction.IGNORE);
@ -365,13 +357,13 @@ public class BlockScreen extends BaseEntityBlock {
for(Vector3i neighbor: neighbors) { for(Vector3i neighbor: neighbors) {
if(world.getBlockState(neighbor.toBlock()).getBlock() instanceof BlockScreen) { if(world.getBlockState(neighbor.toBlock()).getBlock() instanceof BlockScreen) {
for(BlockSide bs: BlockSide.values()) for(BlockSide bs: BlockSide.values())
destroySide(world, neighbor.clone(), bs, override, (whoDidThisShit instanceof EntityPlayer) ? ((EntityPlayer) whoDidThisShit) : null); destroySide(world, neighbor.clone(), bs, override, (whoDidThisShit instanceof Player) ? ((Player) whoDidThisShit) : null);
} }
} }
} }
@Override @Override
public PushReaction getPistonPushReaction(BlockState state) { public @NotNull PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.IGNORE; return PushReaction.IGNORE;
} }

View File

@ -5,9 +5,11 @@
package net.montoyo.wd.client.gui; package net.montoyo.wd.client.gui;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.loading.FMLPaths;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.client.gui.controls.Button; import net.montoyo.wd.client.gui.controls.Button;
import net.montoyo.wd.client.gui.controls.Control; import net.montoyo.wd.client.gui.controls.Control;
@ -20,7 +22,7 @@ import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Log; import net.montoyo.wd.utilities.Log;
import net.montoyo.wd.utilities.TypeData; import net.montoyo.wd.utilities.TypeData;
import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Util;
import org.lwjgl.system.CallbackI; import org.lwjgl.glfw.GLFW;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,9 +46,11 @@ public class GuiKeyboard extends WDScreen {
private Button btnOk; private Button btnOk;
public GuiKeyboard() { public GuiKeyboard() {
super(Component.nullToEmpty(null));
} }
public GuiKeyboard(TileEntityScreen tes, BlockSide side, BlockPos kbPos) { public GuiKeyboard(TileEntityScreen tes, BlockSide side, BlockPos kbPos) {
this();
this.tes = tes; this.tes = tes;
this.side = side; this.side = side;
this.kbPos = kbPos; this.kbPos = kbPos;
@ -61,20 +65,20 @@ public class GuiKeyboard extends WDScreen {
public void init() { public void init() {
super.init(); super.init();
if(minecraft.getSingleplayerServer() != null && !minecraft.getSingleplayerServer().isPublished()) if (minecraft.getSingleplayerServer() != null && !minecraft.getSingleplayerServer().isPublished())
showWarning = false; //NO NEED showWarning = false; //NO NEED
else else
showWarning = !hasUserReadWarning(); showWarning = !hasUserReadWarning();
loadFrom(new ResourceLocation("webdisplays", "gui/keyboard.json")); loadFrom(new ResourceLocation("webdisplays", "gui/keyboard.json"));
if(showWarning) { if (showWarning) {
int maxLabelW = 0; int maxLabelW = 0;
int totalH = 0; int totalH = 0;
for(Control ctrl : controls) { for (Control ctrl : controls) {
if(ctrl != lblInfo && ctrl instanceof Label) { if (ctrl != lblInfo && ctrl instanceof Label) {
if(ctrl.getWidth() > maxLabelW) if (ctrl.getWidth() > maxLabelW)
maxLabelW = ctrl.getWidth(); maxLabelW = ctrl.getWidth();
totalH += ctrl.getHeight(); totalH += ctrl.getHeight();
@ -87,8 +91,8 @@ public class GuiKeyboard extends WDScreen {
totalH += btnOk.getHeight(); totalH += btnOk.getHeight();
int y = (height - totalH) / 2; int y = (height - totalH) / 2;
for(Control ctrl : controls) { for (Control ctrl : controls) {
if(ctrl != lblInfo) { if (ctrl != lblInfo) {
ctrl.setPos(ctrl.getX(), y); ctrl.setPos(ctrl.getX(), y);
y += ctrl.getHeight(); y += ctrl.getHeight();
} }
@ -103,39 +107,45 @@ public class GuiKeyboard extends WDScreen {
} }
@Override @Override
public void handleKeyboardInput() throws IOException { public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if(showWarning) { key(keyCode, scanCode, true);
try { return super.keyPressed(keyCode, scanCode, modifiers);
super.handleKeyboardInput(); }
} catch(IOException ex) {
Log.warningEx("Caught exception while handling screen input", ex);
}
return; @Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
key(keyCode, scanCode, false);
return super.keyPressed(keyCode, scanCode, modifiers);
}
public void key(int keyCode, int scanCode, boolean pressed) {
char chr = getChar(keyCode, scanCode);
if (pressed) {
int kc = keyCode;
evStack.add(new TypeData(TypeData.Action.PRESS, kc, chr));
evStack.add(new TypeData(TypeData.Action.RELEASE, kc, chr));
} }
if(Keyboard.isCreated()) { if (chr != 0)
while(Keyboard.next()) { evStack.add(new TypeData(TypeData.Action.TYPE, 0, chr));
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE)
mc.displayGuiScreen(null);
else {
char chr = Keyboard.getEventCharacter();
if(Keyboard.getEventKeyState()) { if (!evStack.isEmpty() && !syncRequested())
int kc = Keyboard.getEventKey(); requestSync();
}
evStack.add(new TypeData(TypeData.Action.PRESS, kc, chr)); public char getChar(int keyCode, int scanCode) {
evStack.add(new TypeData(TypeData.Action.RELEASE, kc, chr)); String keystr = GLFW.glfwGetKeyName(keyCode, scanCode);
} if(keystr == null){
keystr = "\0";
if(chr != 0)
evStack.add(new TypeData(TypeData.Action.TYPE, 0, chr));
}
}
if(!evStack.isEmpty() && !syncRequested())
requestSync();
} }
if(keyCode == GLFW.GLFW_KEY_ENTER){
keystr = "\n";
}
if(keystr.length() == 0){
return (char) -1;
}
return keystr.charAt(keystr.length() - 1);
} }
@Override @Override
@ -162,14 +172,14 @@ public class GuiKeyboard extends WDScreen {
btnOk.setVisible(false); btnOk.setVisible(false);
showWarning = false; showWarning = false;
defaultBackground = false; defaultBackground = false;
mc.inGameHasFocus = true; minecraft.setWindowActive(true);
mc.mouseHelper.grabMouseCursor(); minecraft.mouseHandler.grabMouse();
} }
} }
private boolean hasUserReadWarning() { private boolean hasUserReadWarning() {
try { try {
File f = new File(mc.mcDataDir, WARNING_FNAME); File f = new File(FMLPaths.GAMEDIR.name(), WARNING_FNAME);
if(f.exists()) { if(f.exists()) {
BufferedReader br = new BufferedReader(new FileReader(f)); BufferedReader br = new BufferedReader(new FileReader(f));
@ -187,7 +197,7 @@ public class GuiKeyboard extends WDScreen {
private void writeUserAcknowledge() { private void writeUserAcknowledge() {
try { try {
File f = new File(mc.mcDataDir, WARNING_FNAME); File f = new File(FMLPaths.GAMEDIR.name(), WARNING_FNAME);
BufferedWriter bw = new BufferedWriter(new FileWriter(f)); BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write("read\n"); bw.write("read\n");
@ -199,7 +209,7 @@ public class GuiKeyboard extends WDScreen {
@Override @Override
public boolean isForBlock(BlockPos bp, BlockSide side) { public boolean isForBlock(BlockPos bp, BlockSide side) {
return bp.equals(kbPos) || (bp.equals(tes.getPos()) && side == this.side); return bp.equals(kbPos) || (bp.equals(tes.getBlockPos()) && side == this.side);
} }
} }

View File

@ -36,7 +36,7 @@ public final class LaserPointerRenderer implements IItemRenderer {
} }
@Override @Override
public final void render(ItemStack is, float handSideSign, float swingProgress, float equipProgress) { public void render(PoseStack poseStack, ItemStack is, float handSideSign, float swingProgress, float equipProgress) {
//This whole method is a fucking hack //This whole method is a fucking hack
float sqrtSwingProg = (float) Math.sqrt(swingProgress); float sqrtSwingProg = (float) Math.sqrt(swingProgress);
float sinSqrtSwingProg1 = (float) Math.sin(sqrtSwingProg * PI); float sinSqrtSwingProg1 = (float) Math.sin(sqrtSwingProg * PI);

View File

@ -20,6 +20,7 @@ public final class ModelMinePad extends Model {
private final ModelPart right; private final ModelPart right;
public ModelMinePad() { public ModelMinePad() {
super();
textureWidth = 64; textureWidth = 64;
textureHeight = 32; textureHeight = 32;

View File

@ -6,6 +6,7 @@ package net.montoyo.wd.core;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.init.ItemInit;
public enum CraftComponent { public enum CraftComponent {
@ -33,7 +34,7 @@ public enum CraftComponent {
} }
public ItemStack makeItemStack() { public ItemStack makeItemStack() {
return new ItemStack(WebDisplays.INSTANCE.itemCraftComp, 1); return new ItemStack(ItemInit.itemCraftComp.get(), 1);
} }
} }

View File

@ -5,26 +5,31 @@
package net.montoyo.wd.core; package net.montoyo.wd.core;
import net.minecraft.util.StringRepresentable; import net.minecraft.util.StringRepresentable;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.montoyo.wd.entity.*; import net.montoyo.wd.entity.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
public enum DefaultPeripheral implements StringRepresentable { public enum DefaultPeripheral implements StringRepresentable {
KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard.class), //WITH FACING (< 3) KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard::new), //WITH FACING (< 3)
// CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class), // CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class),
// OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class), // OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class),
REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl.class), //WITHOUT FACING (>= 3) REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl::new), //WITHOUT FACING (>= 3)
REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl.class), REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl::new),
SERVER("server", "Server", TileEntityServer.class); SERVER("server", "Server", TileEntityServer::new);
private final String name; private final String name;
private final String wikiName; private final String wikiName;
private final Class<? extends BlockEntity> teClass; private final BlockEntityType.BlockEntitySupplier<? extends BlockEntity> teClass;
DefaultPeripheral(String name, String wname, Class<? extends BlockEntity> te) { DefaultPeripheral(String name, String wname, BlockEntityType.BlockEntitySupplier<? extends BlockEntity> factory) {
this.name = name; this.name = name;
wikiName = wname; wikiName = wname;
teClass = te; teClass = factory;
} }
public static DefaultPeripheral fromMetadata(int meta) { public static DefaultPeripheral fromMetadata(int meta) {
@ -34,7 +39,7 @@ public enum DefaultPeripheral implements StringRepresentable {
return values()[meta & 3]; //With facing return values()[meta & 3]; //With facing
} }
public Class<? extends BlockEntity> getTEClass() { public BlockEntityType.BlockEntitySupplier<? extends BlockEntity> getTEClass() {
return teClass; return teClass;
} }

View File

@ -6,6 +6,8 @@ package net.montoyo.wd.core;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.config.ModConfig;
import net.montoyo.wd.init.ItemInit;
public enum DefaultUpgrade { public enum DefaultUpgrade {
@ -28,6 +30,6 @@ public enum DefaultUpgrade {
} }
public boolean matches(ItemStack is) { public boolean matches(ItemStack is) {
return is.getItem() == WebDisplays.INSTANCE.itemUpgrade; return is.getItem() == ItemInit.itemUpgrade.get();
} }
} }

View File

@ -4,8 +4,10 @@
package net.montoyo.wd.data; package net.montoyo.wd.data;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@ -33,7 +35,7 @@ public class RedstoneCtrlData extends GuiData {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
@Override @Override
public Screen createGui(Screen old, Level world) { public Screen createGui(Screen old, Level world) {
return new GuiRedstoneCtrl(dimension, pos, risingEdgeURL, fallingEdgeURL); return new GuiRedstoneCtrl(old.getTitle(), dimension, pos, risingEdgeURL, fallingEdgeURL); //TODO is getTitle() correct?
} }
@Override @Override

View File

@ -16,6 +16,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.KeyboardData; import net.montoyo.wd.data.KeyboardData;
import net.montoyo.wd.init.TileInit;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Util;
@ -23,8 +24,8 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase {
private static final String RANDOM_CHARS = "AZERTYUIOPQSDFGHJKLMWXCVBNazertyuiopqsdfghjklmwxcvbn0123456789"; //Yes I have an AZERTY keyboard, u care? private static final String RANDOM_CHARS = "AZERTYUIOPQSDFGHJKLMWXCVBNazertyuiopqsdfghjklmwxcvbn0123456789"; //Yes I have an AZERTY keyboard, u care?
public TileEntityKeyboard(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) { public TileEntityKeyboard(BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3); super(TileInit.PERIPHERAL.get(), arg2, arg3);
} }
@Override @Override

View File

@ -7,44 +7,46 @@ package net.montoyo.wd.entity;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.data.SetURLData;
import net.montoyo.wd.init.TileInit;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Util;
public class TileEntityRCtrl extends TileEntityPeripheralBase { public class TileEntityRCtrl extends TileEntityPeripheralBase {
public TileEntityRCtrl(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) { public TileEntityRCtrl(BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3); super(TileInit.PERIPHERAL.get(), arg2, arg3);
} }
@Override @Override
public boolean onRightClick(Player player, InteractionHand hand, BlockSide side) { public InteractionResult onRightClick(Player player, InteractionHand hand) {
if(level.isClientSide) if(level.isClientSide)
return true; return InteractionResult.SUCCESS;
if(!isScreenChunkLoaded()) { if(!isScreenChunkLoaded()) {
Util.toast(player, "chunkUnloaded"); Util.toast(player, "chunkUnloaded");
return true; return InteractionResult.SUCCESS;
} }
TileEntityScreen tes = getConnectedScreen(); TileEntityScreen tes = getConnectedScreen();
if(tes == null) { if(tes == null) {
Util.toast(player, "notLinked"); Util.toast(player, "notLinked");
return true; return InteractionResult.SUCCESS;
} }
TileEntityScreen.Screen scr = tes.getScreen(screenSide); TileEntityScreen.Screen scr = tes.getScreen(screenSide);
if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0) { if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0) {
Util.toast(player, "restrictions"); Util.toast(player, "restrictions");
return true; return InteractionResult.SUCCESS;
} }
(new SetURLData(screenPos, screenSide, scr.url, getBlockPos())).sendTo((ServerPlayer) player); (new SetURLData(screenPos, screenSide, scr.url, getBlockPos())).sendTo((ServerPlayer) player);
return true; return InteractionResult.SUCCESS;
} }
} }

View File

@ -8,12 +8,15 @@ import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.RedstoneCtrlData; import net.montoyo.wd.data.RedstoneCtrlData;
import net.montoyo.wd.init.TileInit;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Util;
@ -25,8 +28,8 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
private String fallingEdgeURL = ""; private String fallingEdgeURL = "";
private boolean state = false; private boolean state = false;
public TileEntityRedCtrl(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) { public TileEntityRedCtrl(BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3); super(TileInit.PERIPHERAL.get(), arg2, arg3);
} }
@Override @Override
@ -51,29 +54,29 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
} }
@Override @Override
public boolean onRightClick(Player player, InteractionHand hand, BlockSide side) { public InteractionResult onRightClick(Player player, InteractionHand hand) {
if(level.isClientSide) if(level.isClientSide)
return true; return InteractionResult.SUCCESS;
if(!isScreenChunkLoaded()) { if(!isScreenChunkLoaded()) {
Util.toast(player, "chunkUnloaded"); Util.toast(player, "chunkUnloaded");
return true; return InteractionResult.SUCCESS;
} }
TileEntityScreen tes = getConnectedScreen(); TileEntityScreen tes = getConnectedScreen();
if(tes == null) { if(tes == null) {
Util.toast(player, "notLinked"); Util.toast(player, "notLinked");
return true; return InteractionResult.SUCCESS;
} }
TileEntityScreen.Screen scr = tes.getScreen(screenSide); TileEntityScreen.Screen scr = tes.getScreen(screenSide);
if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0) { if((scr.rightsFor(player) & ScreenRights.CHANGE_URL) == 0) {
Util.toast(player, "restrictions"); Util.toast(player, "restrictions");
return true; return InteractionResult.SUCCESS;
} }
(new RedstoneCtrlData(level.dimension().location(), getBlockPos(), risingEdgeURL, fallingEdgeURL)).sendTo((ServerPlayer) player); (new RedstoneCtrlData(level.dimension().location(), getBlockPos(), risingEdgeURL, fallingEdgeURL)).sendTo((ServerPlayer) player);
return true; return InteractionResult.SUCCESS;
} }
@Override @Override

View File

@ -34,6 +34,7 @@ import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.ScreenConfigData; import net.montoyo.wd.data.ScreenConfigData;
import net.montoyo.wd.init.BlockInit; import net.montoyo.wd.init.BlockInit;
import net.montoyo.wd.init.ItemInit; import net.montoyo.wd.init.ItemInit;
import net.montoyo.wd.init.TileInit;
import net.montoyo.wd.net.Messages; import net.montoyo.wd.net.Messages;
import net.montoyo.wd.net.client.CMessageAddScreen; import net.montoyo.wd.net.client.CMessageAddScreen;
import net.montoyo.wd.net.client.CMessageCloseGui; import net.montoyo.wd.net.client.CMessageCloseGui;
@ -54,7 +55,7 @@ import static net.montoyo.wd.block.BlockPeripheral.point;
public class TileEntityScreen extends BlockEntity{ public class TileEntityScreen extends BlockEntity{
public TileEntityScreen(BlockPos arg2, BlockState arg3) { public TileEntityScreen(BlockPos arg2, BlockState arg3) {
super(null /*TODO: add blockEnityTYpe */ , arg2, arg3); super(TileInit.SCREEN_BLOCK_ENTITY.get(), arg2, arg3);
} }
public static class Screen { public static class Screen {

View File

@ -13,6 +13,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.data.ServerData; import net.montoyo.wd.data.ServerData;
import net.montoyo.wd.init.TileInit;
import net.montoyo.wd.utilities.NameUUIDPair; import net.montoyo.wd.utilities.NameUUIDPair;
import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Util;
@ -22,8 +23,8 @@ public class TileEntityServer extends BlockEntity {
private NameUUIDPair owner; private NameUUIDPair owner;
public TileEntityServer(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) { public TileEntityServer(BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3); super(TileInit.PERIPHERAL.get(), arg2, arg3);
} }
@Override @Override

View File

@ -34,7 +34,7 @@ public class BlockInit {
public static final RegistryObject<Block> blockScreen = registerBlock("screen_block", BlockScreen::new); public static final RegistryObject<Block> blockScreen = registerBlock("screen_block", BlockScreen::new);
public static final RegistryObject<Block> blockPeripheral = registerBlock("peripheral_block", () -> new BlockPeripheral()); public static final RegistryObject<Block> blockPeripheral = registerBlock("peripheral_block", BlockPeripheral::new);
public static final RegistryObject<Block> blockKbRight = registerBlock("kb_right_block", () -> new BlockKeyboardRight()); public static final RegistryObject<Block> blockKbRight = registerBlock("kb_right_block", BlockKeyboardRight::new);
} }

View File

@ -1,13 +1,9 @@
package net.montoyo.wd.init; package net.montoyo.wd.init;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.common.extensions.IForgeBlockEntity;
import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import net.montoyo.wd.core.DefaultPeripheral; import net.montoyo.wd.core.DefaultPeripheral;
import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.entity.TileEntityScreen;
@ -16,13 +12,19 @@ public class TileInit {
public static final DeferredRegister<BlockEntityType<?>> TILE_TYPES = DeferredRegister public static final DeferredRegister<BlockEntityType<?>> TILE_TYPES = DeferredRegister
.create(ForgeRegistries.BLOCK_ENTITIES, "webdisplays"); .create(ForgeRegistries.BLOCK_ENTITIES, "webdisplays");
public static RegistryObject<BlockEntityType<?>> PERIPHERAL;
//Register tile entities //Register tile entities
public static final BlockEntityType<TileEntityScreen> SCREEN_BLOCK_ENTITY = TILE_TYPES.register("screen", () -> BlockEntityType.Builder.of(TileEntityScreen::new, BlockInit.blockScreen).build(null)); public static final RegistryObject<BlockEntityType<TileEntityScreen>> SCREEN_BLOCK_ENTITY = TILE_TYPES
.register("screen", () -> BlockEntityType.Builder
.of(TileEntityScreen::new, BlockInit.blockScreen.get()).build(null));
public static void registerPeripherals() { public static void registerPeripherals() {
for (DefaultPeripheral dp : DefaultPeripheral.values()) { for (DefaultPeripheral dp : DefaultPeripheral.values()) {
if (dp.getTEClass() != null) if (dp.getTEClass() != null)
TILE_TYPES.register(dp.name(), () -> BlockEntityType.Builder.of(dp.getTEClass(), BlockInit.blockPeripheral.get()).build(null)); PERIPHERAL = TILE_TYPES.register(dp.name(), () -> BlockEntityType.Builder
.of(dp.getTEClass(), BlockInit.blockPeripheral.get()).build(null));
} }
} }
} }

View File

@ -8,6 +8,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
@ -18,6 +19,7 @@ import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Multiblock; import net.montoyo.wd.utilities.Multiblock;
import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Util;
import net.montoyo.wd.utilities.Vector3i; import net.montoyo.wd.utilities.Vector3i;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.system.CallbackI; import org.lwjgl.system.CallbackI;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -59,4 +61,8 @@ public class ItemScreenConfigurator extends Item implements WDItem {
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
@Override
public String getWikiName(@NotNull ItemStack is) {
return is.getItem().getName(is).getString();
}
} }