diff --git a/.gitignore b/.gitignore index 070a3df0..1867a942 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +#system +.DS_Store + # eclipse bin *.launch @@ -28,4 +31,4 @@ forge*changelog.txt /src/generated/ #vscode -.vscode +.vscode \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 6a4a3e4a..c81248e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,9 +5,9 @@ org.gradle.daemon=false minecraft_version=1.16.5 minecraft_version_min=1.16.5 -mappings_channel=snapshot -mappings_version=20201028-1.16.3 -forge_version=36.1.13 +mappings_channel=official +mappings_version=1.16.5 +forge_version=36.1.24 forge_version_min=36.1.0 mod_group=li.cil.oc2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7a3265ee..e708b1c0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1c4bcc29..549d8442 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/li/cil/oc2/api/bus/BlockDeviceBusElement.java b/src/main/java/li/cil/oc2/api/bus/BlockDeviceBusElement.java index d529d44d..3fc7e586 100644 --- a/src/main/java/li/cil/oc2/api/bus/BlockDeviceBusElement.java +++ b/src/main/java/li/cil/oc2/api/bus/BlockDeviceBusElement.java @@ -16,7 +16,7 @@ public interface BlockDeviceBusElement extends DeviceBusElement { * * @return the world the bus lives in. */ - IWorld getWorld(); + IWorld getLevel(); /** * The position of this bus element. diff --git a/src/main/java/li/cil/oc2/api/bus/device/provider/BlockDeviceQuery.java b/src/main/java/li/cil/oc2/api/bus/device/provider/BlockDeviceQuery.java index 827f4acf..6fe74438 100644 --- a/src/main/java/li/cil/oc2/api/bus/device/provider/BlockDeviceQuery.java +++ b/src/main/java/li/cil/oc2/api/bus/device/provider/BlockDeviceQuery.java @@ -17,7 +17,7 @@ public interface BlockDeviceQuery { * * @return the world containing the block. */ - World getWorld(); + World getLevel(); /** * The position of the block this query is performed for. diff --git a/src/main/java/li/cil/oc2/client/ClientSetup.java b/src/main/java/li/cil/oc2/client/ClientSetup.java index f77d519f..81df8ec4 100644 --- a/src/main/java/li/cil/oc2/client/ClientSetup.java +++ b/src/main/java/li/cil/oc2/client/ClientSetup.java @@ -38,10 +38,10 @@ public final class ClientSetup { CustomItemModelProperties.initialize(); CustomItemColors.initialize(); - ScreenManager.registerFactory(Containers.COMPUTER_CONTAINER.get(), ComputerInventoryScreen::new); - ScreenManager.registerFactory(Containers.COMPUTER_TERMINAL_CONTAINER.get(), ComputerTerminalScreen::new); - ScreenManager.registerFactory(Containers.ROBOT_CONTAINER.get(), RobotContainerScreen::new); - ScreenManager.registerFactory(Containers.ROBOT_TERMINAL_CONTAINER.get(), RobotTerminalScreen::new); + ScreenManager.register(Containers.COMPUTER_CONTAINER.get(), ComputerInventoryScreen::new); + ScreenManager.register(Containers.COMPUTER_TERMINAL_CONTAINER.get(), ComputerTerminalScreen::new); + ScreenManager.register(Containers.ROBOT_CONTAINER.get(), RobotContainerScreen::new); + ScreenManager.register(Containers.ROBOT_TERMINAL_CONTAINER.get(), RobotTerminalScreen::new); ClientRegistry.bindTileEntityRenderer(TileEntities.COMPUTER_TILE_ENTITY.get(), ComputerTileEntityRenderer::new); ClientRegistry.bindTileEntityRenderer(TileEntities.NETWORK_CONNECTOR_TILE_ENTITY.get(), NetworkConnectorTileEntityRenderer::new); @@ -58,7 +58,7 @@ public final class ClientSetup { @SubscribeEvent public static void handleTextureStitchEvent(final TextureStitchEvent.Pre event) { - if (event.getMap().getTextureLocation() != PlayerContainer.LOCATION_BLOCKS_TEXTURE) { + if (event.getMap().location() != PlayerContainer.BLOCK_ATLAS) { return; } diff --git a/src/main/java/li/cil/oc2/client/audio/LoopingSoundManager.java b/src/main/java/li/cil/oc2/client/audio/LoopingSoundManager.java index fa60809c..20b6e052 100644 --- a/src/main/java/li/cil/oc2/client/audio/LoopingSoundManager.java +++ b/src/main/java/li/cil/oc2/client/audio/LoopingSoundManager.java @@ -17,18 +17,18 @@ public final class LoopingSoundManager { final LoopingTileEntitySound instance = new LoopingTileEntitySound(tileEntity, sound); TILE_ENTITY_SOUNDS.put(tileEntity, instance); - Minecraft.getInstance().getSoundHandler().playDelayed(instance, delay); + Minecraft.getInstance().getSoundManager().playDelayed(instance, delay); } public static void stop(final TileEntity tileEntity) { final ITickableSound instance = TILE_ENTITY_SOUNDS.remove(tileEntity); if (instance != null) { - Minecraft.getInstance().getSoundHandler().stop(instance); + Minecraft.getInstance().getSoundManager().stop(instance); } } public static boolean isPlaying(final TileEntity tileEntity) { final ITickableSound instance = TILE_ENTITY_SOUNDS.get(tileEntity); - return instance != null && !instance.isDonePlaying(); + return instance != null && !instance.isStopped(); } } diff --git a/src/main/java/li/cil/oc2/client/audio/LoopingTileEntitySound.java b/src/main/java/li/cil/oc2/client/audio/LoopingTileEntitySound.java index 0e75c4c0..05e25eee 100644 --- a/src/main/java/li/cil/oc2/client/audio/LoopingTileEntitySound.java +++ b/src/main/java/li/cil/oc2/client/audio/LoopingTileEntitySound.java @@ -23,12 +23,12 @@ public final class LoopingTileEntitySound extends TickableSound { this.tileEntity = tileEntity; this.volume = 0; - final Vector3d position = Vector3d.copyCentered(tileEntity.getPos()); + final Vector3d position = Vector3d.atCenterOf(tileEntity.getBlockPos()); x = position.x; y = position.y; z = position.z; - repeat = true; + looping = true; } /////////////////////////////////////////////////////////////////// @@ -36,9 +36,9 @@ public final class LoopingTileEntitySound extends TickableSound { @Override public void tick() { volume = MathHelper.clamp(volume + FADE_IN_DURATION / Constants.TICK_SECONDS, 0, 1); - final ChunkPos chunkPos = new ChunkPos(tileEntity.getPos()); - if (tileEntity.isRemoved() || !tileEntity.getWorld().chunkExists(chunkPos.x, chunkPos.z)) { - finishPlaying(); + final ChunkPos chunkPos = new ChunkPos(tileEntity.getBlockPos()); + if (tileEntity.isRemoved() || !tileEntity.getLevel().hasChunk(chunkPos.x, chunkPos.z)) { + stop(); } } } diff --git a/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java b/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java index 51989436..90ad1afc 100644 --- a/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java +++ b/src/main/java/li/cil/oc2/client/gui/AbstractTerminalWidget.java @@ -93,7 +93,7 @@ public abstract class AbstractTerminalWidget extends AbstractGui { isMouseOverTerminal = isMouseOverTerminal(mouseX, mouseY); RenderSystem.color4f(1f, 1f, 1f, 1f); - getClient().getTextureManager().bindTexture(BACKGROUND_LOCATION); + getClient().getTextureManager().bind(BACKGROUND_LOCATION); CONTROLS_BACKGROUND.draw(matrixStack, windowLeft - CONTROLS_BACKGROUND.width, windowTop + CONTROLS_TOP); @@ -114,16 +114,16 @@ public abstract class AbstractTerminalWidget extends AbstractGui { public void render(final MatrixStack matrixStack, final int mouseX, final int mouseY, @Nullable final ITextComponent error) { if (isRunning()) { final MatrixStack stack = new MatrixStack(); - stack.translate(windowLeft + TERMINAL_X, windowTop + TERMINAL_Y, getClient().getItemRenderer().zLevel); + stack.translate(windowLeft + TERMINAL_X, windowTop + TERMINAL_Y, getClient().getItemRenderer().blitOffset); stack.scale(TERMINAL_WIDTH / (float) terminal.getWidth(), TERMINAL_HEIGHT / (float) terminal.getHeight(), 1f); terminal.render(stack); } else { - final FontRenderer font = getClient().fontRenderer; + final FontRenderer font = getClient().font; if (error != null) { - final int textWidth = font.getStringPropertyWidth(error); + final int textWidth = font.width(error); final int textOffsetX = (TERMINAL_WIDTH - textWidth) / 2; - final int textOffsetY = (TERMINAL_HEIGHT - font.FONT_HEIGHT) / 2; - font.func_243246_a(matrixStack, + final int textOffsetY = (TERMINAL_HEIGHT - font.lineHeight) / 2; + font.drawShadow(matrixStack, error, windowLeft + TERMINAL_X + textOffsetX, windowTop + TERMINAL_Y + textOffsetY, @@ -139,7 +139,7 @@ public abstract class AbstractTerminalWidget extends AbstractGui { new TranslationTextComponent(Constants.TOOLTIP_ENERGY, withColor(currentEnergy + "/" + maxEnergy, TextFormatting.GREEN)), new TranslationTextComponent(Constants.TOOLTIP_ENERGY_CONSUMPTION, withColor(String.valueOf(energyConsumption), TextFormatting.GREEN)) ); - GuiUtils.drawHoveringText(matrixStack, tooltip, mouseX, mouseY, parent.width, parent.height, 200, getClient().fontRenderer); + GuiUtils.drawHoveringText(matrixStack, tooltip, mouseX, mouseY, parent.width, parent.height, 200, getClient().font); } } } @@ -162,7 +162,7 @@ public abstract class AbstractTerminalWidget extends AbstractGui { } if ((modifiers & GLFW.GLFW_MOD_CONTROL) != 0 && keyCode == GLFW.GLFW_KEY_V) { - final String value = getClient().keyboardListener.getClipboardString(); + final String value = getClient().keyboardHandler.getClipboard(); for (final char ch : value.toCharArray()) { terminal.putInput((byte) ch); } @@ -182,7 +182,7 @@ public abstract class AbstractTerminalWidget extends AbstractGui { this.windowLeft = (parent.width - WIDTH) / 2; this.windowTop = (parent.height - HEIGHT) / 2; - getClient().keyboardListener.enableRepeatEvents(true); + getClient().keyboardHandler.setSendRepeatsToGui(true); addButton(new ToggleImageButton( parent, windowLeft - CONTROLS_BACKGROUND.width + 4, windowTop + CONTROLS_TOP + 4, @@ -228,7 +228,7 @@ public abstract class AbstractTerminalWidget extends AbstractGui { } public void onClose() { - getClient().keyboardListener.enableRepeatEvents(false); + getClient().keyboardHandler.setSendRepeatsToGui(false); } /////////////////////////////////////////////////////////////////// diff --git a/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java b/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java index b25bc8f0..c949ca50 100644 --- a/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java +++ b/src/main/java/li/cil/oc2/client/gui/BusInterfaceScreen.java @@ -44,7 +44,7 @@ public final class BusInterfaceScreen extends Screen { /////////////////////////////////////////////////////////////////// public BusInterfaceScreen(final BusCableTileEntity tileEntity, final Direction side) { - super(Items.BUS_INTERFACE.get().getName()); + super(Items.BUS_INTERFACE.get().getDescription()); this.tileEntity = tileEntity; this.side = side; } @@ -55,7 +55,7 @@ public final class BusInterfaceScreen extends Screen { protected void init() { super.init(); - getMinecraft().keyboardListener.enableRepeatEvents(true); + getMinecraft().keyboardHandler.setSendRepeatsToGui(true); left = (width - BACKGROUND.width) / 2; top = (height - BACKGROUND.height) / 2; @@ -63,11 +63,11 @@ public final class BusInterfaceScreen extends Screen { nameField = new TextFieldWidget(font, left + TEXT_LEFT, top + TEXT_TOP, 192, 12, new TranslationTextComponent("oc2.gui.bus_interface_name")); nameField.setCanLoseFocus(false); nameField.setTextColor(0xFFFFFFFF); - nameField.setEnableBackgroundDrawing(false); - nameField.setMaxStringLength(32); - nameField.setText(tileEntity.getInterfaceName(side)); - addListener(nameField); - setFocusedDefault(nameField); + nameField.setBordered(false); + nameField.setMaxLength(32); + nameField.setValue(tileEntity.getInterfaceName(side)); + addWidget(nameField); + setFocused(nameField); addButton(new ImageButton( this, @@ -81,8 +81,8 @@ public final class BusInterfaceScreen extends Screen { @Override public void onPress() { super.onPress(); - setInterfaceName(nameField.getText()); - closeScreen(); + setInterfaceName(nameField.getValue()); + onClose(); } }); addButton(new ImageButton( @@ -97,7 +97,7 @@ public final class BusInterfaceScreen extends Screen { @Override public void onPress() { super.onPress(); - closeScreen(); + onClose(); } }); } @@ -106,7 +106,7 @@ public final class BusInterfaceScreen extends Screen { public void onClose() { super.onClose(); - getMinecraft().keyboardListener.enableRepeatEvents(false); + getMinecraft().keyboardHandler.setSendRepeatsToGui(false); } @Override @@ -114,9 +114,9 @@ public final class BusInterfaceScreen extends Screen { super.tick(); nameField.tick(); - final Vector3d busCableCenter = Vector3d.copyCentered(tileEntity.getPos()); - if (getMinecraft().player.getDistanceSq(busCableCenter) > 8 * 8) { - closeScreen(); + final Vector3d busCableCenter = Vector3d.atCenterOf(tileEntity.getBlockPos()); + if (getMinecraft().player.distanceToSqr(busCableCenter) > 8 * 8) { + onClose(); } } @@ -124,8 +124,8 @@ public final class BusInterfaceScreen extends Screen { public boolean keyPressed(final int keyCode, final int scanCode, final int modifiers) { if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER) { - setInterfaceName(nameField.getText()); - closeScreen(); + setInterfaceName(nameField.getValue()); + onClose(); return true; } diff --git a/src/main/java/li/cil/oc2/client/gui/ComputerInventoryScreen.java b/src/main/java/li/cil/oc2/client/gui/ComputerInventoryScreen.java index 25a98fd3..024a7061 100644 --- a/src/main/java/li/cil/oc2/client/gui/ComputerInventoryScreen.java +++ b/src/main/java/li/cil/oc2/client/gui/ComputerInventoryScreen.java @@ -22,9 +22,9 @@ public final class ComputerInventoryScreen extends ContainerScreen minecraft.displayGuiScreen(previousScreen)); + minecraft.tell(() -> minecraft.setScreen(previousScreen)); } } @@ -133,12 +133,12 @@ public class FileChooserScreen extends Screen { @Override protected void init() { super.init(); - minecraft.keyboardListener.enableRepeatEvents(true); + minecraft.keyboardHandler.setSendRepeatsToGui(true); final int widgetsWidth = width - MARGIN * 2; final int listHeight = height - MARGIN - WIDGET_SPACING - TEXT_FIELD_HEIGHT - WIDGET_SPACING - BUTTON_HEIGHT - MARGIN; fileList = new FileList(MARGIN, listHeight, LIST_ENTRY_HEIGHT); - addListener(fileList); + addWidget(fileList); final int fileNameTop = MARGIN + listHeight + WIDGET_SPACING; fileNameTextField = new TextFieldWidget(font, MARGIN, fileNameTop, widgetsWidth, TEXT_FIELD_HEIGHT, FILE_NAME_TEXT); @@ -146,8 +146,8 @@ public class FileChooserScreen extends Screen { fileList.setSelected(null); updateButtons(); }); - fileNameTextField.setMaxStringLength(1024); - addListener(fileNameTextField); + fileNameTextField.setMaxLength(1024); + addWidget(fileNameTextField); final int buttonTop = fileNameTop + TEXT_FIELD_HEIGHT + WIDGET_SPACING; final int buttonCount = 2; @@ -172,7 +172,7 @@ public class FileChooserScreen extends Screen { return selected.file == null || selected.file.equals(directory.getParent()); } - final String selectedFileEntry = fileNameTextField.getText(); + final String selectedFileEntry = fileNameTextField.getValue(); return "..".equals(selectedFileEntry); } @@ -187,7 +187,7 @@ public class FileChooserScreen extends Screen { return Optional.empty(); } - final String selectedFileEntry = fileNameTextField.getText(); + final String selectedFileEntry = fileNameTextField.getValue(); if (selectedFileEntry == null || "".equals(selectedFileEntry) || ".".equals(selectedFileEntry)) { return Optional.empty(); } @@ -202,24 +202,24 @@ public class FileChooserScreen extends Screen { private void confirm() { if (isParentPath()) { fileList.refreshFiles(getPath().orElse(null)); - fileNameTextField.setText(""); + fileNameTextField.setValue(""); return; } getPath().ifPresent(path -> { if (path == null || Files.isDirectory(path)) { fileList.refreshFiles(path); - fileNameTextField.setText(""); + fileNameTextField.setValue(""); return; } if (Files.isRegularFile(path)) { isComplete = true; callback.onFileSelected(path); - closeScreen(); + onClose(); } else if (!isLoad) { isComplete = true; callback.onFileSelected(path); - closeScreen(); + onClose(); } // else: cannot load non-existing file }); } @@ -227,7 +227,7 @@ public class FileChooserScreen extends Screen { private void cancel() { isComplete = true; callback.onCanceled(); - closeScreen(); + onClose(); } private void updateButtons() { @@ -326,7 +326,7 @@ public class FileChooserScreen extends Screen { private FileList.FileEntry createDirectoryEntry(final Path path, final String displayName) { return new FileList.FileEntry(path, new StringTextComponent(displayName) - .modifyStyle(s -> s.setColor(Color.fromInt(0xA0A0FF)))); + .withStyle(s -> s.withColor(Color.fromRgb(0xA0A0FF)))); } private final class FileEntry extends ExtendedList.AbstractListEntry { @@ -343,7 +343,7 @@ public class FileChooserScreen extends Screen { @Override public void render(final MatrixStack stack, final int index, final int top, final int left, final int width, final int height, final int mouseX, final int mouseY, final boolean isHovered, final float deltaTime) { - font.func_243246_a(stack, displayName, left, top, 0xFFFFFFFF); + font.drawShadow(stack, displayName, left, top, 0xFFFFFFFF); } @Override @@ -351,13 +351,13 @@ public class FileChooserScreen extends Screen { final boolean isLeftClick = button == 0; if (isLeftClick) { if (file == null || (directory != null && file.equals(directory.getParent()))) { - fileNameTextField.setText(".."); + fileNameTextField.setValue(".."); } else { final Path fileName = file.getFileName(); - fileNameTextField.setText(fileName != null ? fileName.toString() : file.toString()); + fileNameTextField.setValue(fileName != null ? fileName.toString() : file.toString()); } - fileNameTextField.setCursorPositionZero(); - fileNameTextField.setSelectionPos(0); + fileNameTextField.moveCursorToStart(); + fileNameTextField.setHighlightPos(0); setSelected(this); final boolean isDoubleClick = System.currentTimeMillis() - lastEntryClickTime < 250; diff --git a/src/main/java/li/cil/oc2/client/gui/RobotContainerScreen.java b/src/main/java/li/cil/oc2/client/gui/RobotContainerScreen.java index 305e15c3..b2b8f81b 100644 --- a/src/main/java/li/cil/oc2/client/gui/RobotContainerScreen.java +++ b/src/main/java/li/cil/oc2/client/gui/RobotContainerScreen.java @@ -24,7 +24,7 @@ public final class RobotContainerScreen extends ContainerScreen public static void renderSelection(final MatrixStack matrixStack, final int selectedSlot, final int x, final int y, final int columns) { RenderSystem.color4f(1f, 1f, 1f, 1f); - Minecraft.getInstance().getTextureManager().bindTexture(SELECTION); + Minecraft.getInstance().getTextureManager().bind(SELECTION); final int slotX = (selectedSlot % columns) * SLOT_SIZE; final int slotY = (selectedSlot / columns) * SLOT_SIZE; @@ -36,9 +36,9 @@ public final class RobotContainerScreen extends ContainerScreen public RobotContainerScreen(final RobotContainer container, final PlayerInventory playerInventory, final ITextComponent title) { super(container, playerInventory, title); - xSize = 176; - ySize = 197; - playerInventoryTitleY = ySize - 94; + imageWidth = 176; + imageHeight = 197; + inventoryLabelY = imageHeight - 94; } @Override @@ -57,21 +57,21 @@ public final class RobotContainerScreen extends ContainerScreen GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.MEMORY, new TranslationTextComponent(Constants.TOOLTIP_MEMORY_MISSING)); GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.HARD_DRIVE, new TranslationTextComponent(Constants.TOOLTIP_HARD_DRIVE_MISSING)); - renderHoveredTooltip(matrixStack, mouseX, mouseY); + renderTooltip(matrixStack, mouseX, mouseY); } /////////////////////////////////////////////////////////////////// @Override - protected void drawGuiContainerBackgroundLayer(final MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) { + protected void renderBg(final MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) { RenderSystem.color4f(1f, 1f, 1f, 1f); - getMinecraft().getTextureManager().bindTexture(BACKGROUND); - blit(matrixStack, guiLeft, guiTop, 0, 0, xSize, ySize); + getMinecraft().getTextureManager().bind(BACKGROUND); + blit(matrixStack, leftPos, topPos, 0, 0, imageWidth, imageHeight); } /////////////////////////////////////////////////////////////////// private void renderSelection(final MatrixStack matrixStack) { - renderSelection(matrixStack, container.getRobot().getSelectedSlot(), guiLeft + 115, guiTop + 23, 2); + renderSelection(matrixStack, menu.getRobot().getSelectedSlot(), leftPos + 115, topPos + 23, 2); } } diff --git a/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java b/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java index 8002676e..4fa7ac18 100644 --- a/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java +++ b/src/main/java/li/cil/oc2/client/gui/RobotTerminalScreen.java @@ -28,29 +28,30 @@ public final class RobotTerminalScreen extends ContainerScreen void renderMissingDeviceInfoIcon(final MatrixStack matrixStack, final ContainerScreen screen, final DeviceType type, final ResourceLocation icon) { - findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getContainer(), type).ifPresent(slot -> { - screen.getMinecraft().getTextureManager().bindTexture(icon); + findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> { + screen.getMinecraft().getTextureManager().bind(icon); AbstractGui.blit(matrixStack, - screen.getGuiLeft() + slot.xPos - 1 + RELATIVE_ICON_POSITION, - screen.getGuiTop() + slot.yPos - 1 + RELATIVE_ICON_POSITION, + screen.getGuiLeft() + slot.x - 1 + RELATIVE_ICON_POSITION, + screen.getGuiTop() + slot.y - 1 + RELATIVE_ICON_POSITION, 200, 0, 0, @@ -38,17 +38,17 @@ public final class GuiUtils { } public static void renderMissingDeviceInfoTooltip(final MatrixStack matrixStack, final ContainerScreen screen, final int mouseX, final int mouseY, final DeviceType type, final ITextComponent tooltip) { - final boolean isCursorHoldingStack = !screen.getMinecraft().player.inventory.getItemStack().isEmpty(); + final boolean isCursorHoldingStack = !screen.getMinecraft().player.inventory.items.isEmpty(); if (isCursorHoldingStack) { return; } final Slot hoveredSlot = screen.getSlotUnderMouse(); - if (hoveredSlot != null && hoveredSlot.getHasStack()) { + if (hoveredSlot != null && hoveredSlot.hasItem()) { return; } - findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getContainer(), type).ifPresent(slot -> { + findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> { if (slot == hoveredSlot) { screen.renderTooltip(matrixStack, tooltip, mouseX, mouseY); } @@ -57,12 +57,12 @@ public final class GuiUtils { private static Optional findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(final Container container, final DeviceType type) { TypedSlotItemHandler firstSlot = null; - for (final Slot slot : container.inventorySlots) { + for (final Slot slot : container.slots) { if (slot instanceof TypedSlotItemHandler) { final TypedSlotItemHandler typedSlot = (TypedSlotItemHandler) slot; final DeviceType slotType = typedSlot.getDeviceType(); if (slotType == type) { - if (slot.getHasStack()) { + if (slot.hasItem()) { return Optional.empty(); } else if (firstSlot == null) { firstSlot = typedSlot; diff --git a/src/main/java/li/cil/oc2/client/gui/widget/ImageButton.java b/src/main/java/li/cil/oc2/client/gui/widget/ImageButton.java index ab971957..a6281755 100644 --- a/src/main/java/li/cil/oc2/client/gui/widget/ImageButton.java +++ b/src/main/java/li/cil/oc2/client/gui/widget/ImageButton.java @@ -38,7 +38,7 @@ public abstract class ImageButton extends AbstractButton { if (description == null) { this.tooltip = Collections.singletonList(caption); } else { - this.tooltip = Arrays.asList(caption, new StringTextComponent("").modifyStyle(style -> style.setColor(Color.fromTextFormatting(TextFormatting.GRAY))).append(description)); + this.tooltip = Arrays.asList(caption, new StringTextComponent("").withStyle(style -> style.withColor(Color.fromLegacyFormat(TextFormatting.GRAY))).append(description)); } this.baseImage = baseImage; this.pressedImage = pressedImage; @@ -73,6 +73,6 @@ public abstract class ImageButton extends AbstractButton { @Override public void renderToolTip(final MatrixStack stack, final int mouseX, final int mouseY) { - GuiUtils.drawHoveringText(stack, tooltip, mouseX, mouseY, parent.width, parent.height, 200, Minecraft.getInstance().fontRenderer); + GuiUtils.drawHoveringText(stack, tooltip, mouseX, mouseY, parent.width, parent.height, 200, Minecraft.getInstance().font); } } diff --git a/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java b/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java index 624b6aff..15622add 100644 --- a/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java +++ b/src/main/java/li/cil/oc2/client/gui/widget/Sprite.java @@ -21,12 +21,12 @@ public final class Sprite extends AbstractGui { } public void draw(final MatrixStack stack, final int x, final int y) { - Minecraft.getInstance().getTextureManager().bindTexture(image); + Minecraft.getInstance().getTextureManager().bind(image); blit(stack, x, y, u0, v0, width, height, textureSize, textureSize); } public void drawFillY(final MatrixStack stack, final int x, final int y, final float value) { - Minecraft.getInstance().getTextureManager().bindTexture(image); + Minecraft.getInstance().getTextureManager().bind(image); final int h = (int) (this.height * value); blit(stack, x, y + (height - h), u0, v0 + (height - h), width, h, textureSize, textureSize); } diff --git a/src/main/java/li/cil/oc2/client/gui/widget/ToggleImageButton.java b/src/main/java/li/cil/oc2/client/gui/widget/ToggleImageButton.java index bbda5a71..ab647563 100644 --- a/src/main/java/li/cil/oc2/client/gui/widget/ToggleImageButton.java +++ b/src/main/java/li/cil/oc2/client/gui/widget/ToggleImageButton.java @@ -42,7 +42,7 @@ public abstract class ToggleImageButton extends AbstractButton { if (description == null) { this.tooltip = Collections.singletonList(caption); } else { - this.tooltip = Arrays.asList(caption, new StringTextComponent("").modifyStyle(style -> style.setColor(Color.fromTextFormatting(TextFormatting.GRAY))).append(description)); + this.tooltip = Arrays.asList(caption, new StringTextComponent("").withStyle(style -> style.withColor(Color.fromLegacyFormat(TextFormatting.GRAY))).append(description)); } this.baseImage = baseImage; this.pressedImage = pressedImage; @@ -90,6 +90,6 @@ public abstract class ToggleImageButton extends AbstractButton { @Override public void renderToolTip(final MatrixStack stack, final int mouseX, final int mouseY) { - GuiUtils.drawHoveringText(stack, tooltip, mouseX, mouseY, parent.width, parent.height, 200, Minecraft.getInstance().fontRenderer); + GuiUtils.drawHoveringText(stack, tooltip, mouseX, mouseY, parent.width, parent.height, 200, Minecraft.getInstance().font); } } diff --git a/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java b/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java index 9e4914fa..8005d3db 100644 --- a/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java +++ b/src/main/java/li/cil/oc2/client/item/CustomItemModelProperties.java @@ -11,15 +11,15 @@ public final class CustomItemModelProperties { /////////////////////////////////////////////////////////////////// public static void initialize() { - ItemModelsProperties.registerProperty(Items.HARD_DRIVE_SMALL.get(), CustomItemModelProperties.COLOR_PROPERTY, + ItemModelsProperties.register(Items.HARD_DRIVE_SMALL.get(), CustomItemModelProperties.COLOR_PROPERTY, (stack, world, entity) -> CustomItemColors.getColor(stack)); - ItemModelsProperties.registerProperty(Items.HARD_DRIVE_MEDIUM.get(), CustomItemModelProperties.COLOR_PROPERTY, + ItemModelsProperties.register(Items.HARD_DRIVE_MEDIUM.get(), CustomItemModelProperties.COLOR_PROPERTY, (stack, world, entity) -> CustomItemColors.getColor(stack)); - ItemModelsProperties.registerProperty(Items.HARD_DRIVE_LARGE.get(), CustomItemModelProperties.COLOR_PROPERTY, + ItemModelsProperties.register(Items.HARD_DRIVE_LARGE.get(), CustomItemModelProperties.COLOR_PROPERTY, (stack, world, entity) -> CustomItemColors.getColor(stack)); - ItemModelsProperties.registerProperty(Items.HARD_DRIVE_CUSTOM.get(), CustomItemModelProperties.COLOR_PROPERTY, + ItemModelsProperties.register(Items.HARD_DRIVE_CUSTOM.get(), CustomItemModelProperties.COLOR_PROPERTY, (stack, world, entity) -> CustomItemColors.getColor(stack)); - ItemModelsProperties.registerProperty(Items.FLOPPY.get(), CustomItemModelProperties.COLOR_PROPERTY, + ItemModelsProperties.register(Items.FLOPPY.get(), CustomItemModelProperties.COLOR_PROPERTY, (stack, world, entity) -> CustomItemColors.getColor(stack)); } } diff --git a/src/main/java/li/cil/oc2/client/model/BusCableBakedModel.java b/src/main/java/li/cil/oc2/client/model/BusCableBakedModel.java index 4783e9cf..27eb1615 100644 --- a/src/main/java/li/cil/oc2/client/model/BusCableBakedModel.java +++ b/src/main/java/li/cil/oc2/client/model/BusCableBakedModel.java @@ -35,7 +35,7 @@ public final class BusCableBakedModel implements IDynamicBakedModel { @Override public List getQuads(@Nullable final BlockState state, @Nullable final Direction side, final Random rand, final IModelData extraData) { - if (state == null || !state.get(BusCableBlock.HAS_CABLE)) { + if (state == null || !state.getValue(BusCableBlock.HAS_CABLE)) { return proxy.getQuads(null, side, rand, extraData); } @@ -50,15 +50,15 @@ public final class BusCableBakedModel implements IDynamicBakedModel { final BusCableSupportSide supportSide = extraData.getData(BusCableSupportSide.BUS_CABLE_SUPPORT_PROPERTY); if (supportSide != null) { - quads.addAll(supportModelByFace[supportSide.get().getIndex()].getQuads(state, side, rand, extraData)); + quads.addAll(supportModelByFace[supportSide.get().get3DDataValue()].getQuads(state, side, rand, extraData)); } return quads; } @Override - public boolean isAmbientOcclusion() { - return proxy.isAmbientOcclusion(); + public boolean useAmbientOcclusion() { + return proxy.useAmbientOcclusion(); } @Override @@ -66,19 +66,20 @@ public final class BusCableBakedModel implements IDynamicBakedModel { return proxy.isGui3d(); } + @Override - public boolean isSideLit() { - return proxy.isSideLit(); + public boolean usesBlockLight() { + return proxy.usesBlockLight(); } @Override - public boolean isBuiltInRenderer() { - return proxy.isBuiltInRenderer(); + public boolean isCustomRenderer() { + return proxy.isCustomRenderer(); } @Override - public TextureAtlasSprite getParticleTexture() { - return proxy.getParticleTexture(); + public TextureAtlasSprite getParticleIcon() { + return proxy.getParticleIcon(); } @Override @@ -92,7 +93,7 @@ public final class BusCableBakedModel implements IDynamicBakedModel { for (final Direction direction : Constants.DIRECTIONS) { if (isNeighborInDirectionSolid(world, pos, direction)) { final EnumProperty property = BusCableBlock.FACING_TO_CONNECTION_MAP.get(direction); - if (state.hasProperty(property) && state.get(property) == BusCableBlock.ConnectionType.INTERFACE) { + if (state.hasProperty(property) && state.getValue(property) == BusCableBlock.ConnectionType.INTERFACE) { return tileData; // Plug is already supporting us, bail. } @@ -114,19 +115,19 @@ public final class BusCableBakedModel implements IDynamicBakedModel { /////////////////////////////////////////////////////////////////// private static boolean isNeighborInDirectionSolid(final IBlockDisplayReader world, final BlockPos pos, final Direction direction) { - final BlockPos neighborPos = pos.offset(direction); - return world.getBlockState(neighborPos).isSolidSide(world, neighborPos, direction.getOpposite()); + final BlockPos neighborPos = pos.relative(direction); + return world.getBlockState(neighborPos).isFaceSturdy(world, neighborPos, direction.getOpposite()); } private static boolean isStraightAlongAxis(final BlockState state, final Direction.Axis axis) { for (final Direction direction : Constants.DIRECTIONS) { final EnumProperty property = BusCableBlock.FACING_TO_CONNECTION_MAP.get(direction); if (axis.test(direction)) { - if (state.get(property) != BusCableBlock.ConnectionType.CABLE) { + if (state.getValue(property) != BusCableBlock.ConnectionType.CABLE) { return false; } } else { - if (state.get(property) != BusCableBlock.ConnectionType.NONE) { + if (state.getValue(property) != BusCableBlock.ConnectionType.NONE) { return false; } } diff --git a/src/main/java/li/cil/oc2/client/model/BusCableModel.java b/src/main/java/li/cil/oc2/client/model/BusCableModel.java index a82f5974..99ddc3b1 100644 --- a/src/main/java/li/cil/oc2/client/model/BusCableModel.java +++ b/src/main/java/li/cil/oc2/client/model/BusCableModel.java @@ -50,8 +50,8 @@ public final class BusCableModel implements IModelGeometry { @Override public Collection getTextures(final IModelConfiguration owner, final Function modelGetter, final Set> missingTextureErrors) { final ArrayList textures = new ArrayList<>(proxy.getTextures(owner, modelGetter, missingTextureErrors)); - textures.addAll(modelGetter.apply(BUS_CABLE_STRAIGHT_MODEL).getTextures(modelGetter, missingTextureErrors)); - textures.addAll(modelGetter.apply(BUS_CABLE_SUPPORT_MODEL).getTextures(modelGetter, missingTextureErrors)); + textures.addAll(modelGetter.apply(BUS_CABLE_STRAIGHT_MODEL).getMaterials(modelGetter, missingTextureErrors)); + textures.addAll(modelGetter.apply(BUS_CABLE_SUPPORT_MODEL).getMaterials(modelGetter, missingTextureErrors)); return textures; } } diff --git a/src/main/java/li/cil/oc2/client/renderer/BusInterfaceNameRenderer.java b/src/main/java/li/cil/oc2/client/renderer/BusInterfaceNameRenderer.java index c78d0ce3..c0f7c558 100644 --- a/src/main/java/li/cil/oc2/client/renderer/BusInterfaceNameRenderer.java +++ b/src/main/java/li/cil/oc2/client/renderer/BusInterfaceNameRenderer.java @@ -35,19 +35,19 @@ public enum BusInterfaceNameRenderer { public void handleRenderLastEvent(final RenderWorldLastEvent event) { final Minecraft mc = Minecraft.getInstance(); final PlayerEntity player = mc.player; - final World world = player.getEntityWorld(); + final World world = player.getCommandSenderWorld(); if (!Wrenches.isHoldingWrench(player)) { return; } - if (!(mc.objectMouseOver instanceof BlockRayTraceResult)) { + if (!(mc.hitResult instanceof BlockRayTraceResult)) { return; } - final BlockRayTraceResult hit = (BlockRayTraceResult) mc.objectMouseOver; - final BlockPos blockPos = hit.getPos(); - final TileEntity tileEntity = world.getTileEntity(blockPos); + final BlockRayTraceResult hit = (BlockRayTraceResult) mc.hitResult; + final BlockPos blockPos = hit.getBlockPos(); + final TileEntity tileEntity = world.getBlockEntity(blockPos); if (!(tileEntity instanceof BusCableTileEntity)) { return; } @@ -65,39 +65,39 @@ public enum BusInterfaceNameRenderer { final MatrixStack stack = event.getMatrixStack(); - stack.push(); + stack.pushPose(); stack.translate(0.5, 1, 0.5); - stack.translate(side.getXOffset() * 0.5f, 0, side.getZOffset() * 0.5f); + stack.translate(side.getStepX() * 0.5f, 0, side.getStepZ() * 0.5f); - final ActiveRenderInfo info = mc.gameRenderer.getActiveRenderInfo(); + final ActiveRenderInfo info = mc.gameRenderer.getMainCamera(); stack.translate( - blockPos.getX() - info.getProjectedView().getX(), - blockPos.getY() - info.getProjectedView().getY(), - blockPos.getZ() - info.getProjectedView().getZ()); + blockPos.getX() - info.getPosition().x, + blockPos.getY() - info.getPosition().y, + blockPos.getZ() - info.getPosition().z); - final EntityRendererManager renderManager = mc.getRenderManager(); - stack.rotate(renderManager.getCameraOrientation()); + final EntityRendererManager renderManager = mc.getEntityRenderDispatcher(); + stack.mulPose(renderManager.cameraOrientation()); stack.scale(-0.025f, -0.025f, 0.025f); - final Matrix4f matrix = stack.getLast().getMatrix(); + final Matrix4f matrix = stack.last().pose(); - final FontRenderer fontrenderer = renderManager.getFontRenderer(); - final IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer()); + final FontRenderer fontrenderer = renderManager.getFont(); + final IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder()); - final float horizontalTextOffset = -fontrenderer.getStringWidth(name) * 0.5f; - final float backgroundOpacity = Minecraft.getInstance().gameSettings.getTextBackgroundOpacity(0.25F); + final float horizontalTextOffset = -fontrenderer.width(name) * 0.5f; + final float backgroundOpacity = Minecraft.getInstance().options.getBackgroundOpacity(0.25F); final int backgroundColor = (int) (backgroundOpacity * 255.0F) << 24; - final int packedLight = LightTexture.packLight(15, 15); + final int packedLight = LightTexture.pack(15, 15); - fontrenderer.renderString(name, horizontalTextOffset, 0, 0xffffffff, + fontrenderer.drawInBatch(name, horizontalTextOffset, 0, 0xffffffff, false, matrix, buffer, true, backgroundColor, packedLight); - fontrenderer.renderString(name, horizontalTextOffset, 0, 0xffffffff, + fontrenderer.drawInBatch(name, horizontalTextOffset, 0, 0xffffffff, false, matrix, buffer, false, 0, packedLight); - buffer.finish(); + buffer.endBatch(); - stack.pop(); + stack.popPose(); } } diff --git a/src/main/java/li/cil/oc2/client/renderer/CustomRenderType.java b/src/main/java/li/cil/oc2/client/renderer/CustomRenderType.java index 07150e1b..f243f8eb 100644 --- a/src/main/java/li/cil/oc2/client/renderer/CustomRenderType.java +++ b/src/main/java/li/cil/oc2/client/renderer/CustomRenderType.java @@ -10,13 +10,13 @@ import org.lwjgl.opengl.GL11; public abstract class CustomRenderType extends RenderType { public static RenderType getUnlitBlock(final ResourceLocation location) { final TextureState texture = new TextureState(location, false, true); - final RenderType.State state = RenderType.State.getBuilder() - .texture(texture) - .alpha(DEFAULT_ALPHA) - .transparency(ADDITIVE_TRANSPARENCY) - .cull(CULL_DISABLED) - .build(false); - return RenderType.makeType( + final RenderType.State state = RenderType.State.builder() + .setTextureState(texture) + .setAlphaState(DEFAULT_ALPHA) + .setTransparencyState(ADDITIVE_TRANSPARENCY) + .setCullState(NO_CULL) + .createCompositeState(false); + return RenderType.create( API.MOD_ID + ":unlit_block", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, @@ -27,13 +27,13 @@ public abstract class CustomRenderType extends RenderType { } public static RenderType getNetworkCable() { - final State state = State.getBuilder() - .texture(NO_TEXTURE) - .transparency(NO_TRANSPARENCY) - .cull(CULL_DISABLED) - .lightmap(LIGHTMAP_ENABLED) - .build(false); - return RenderType.makeType(API.MOD_ID + ":network_cable", + final State state = State.builder() + .setTextureState(NO_TEXTURE) + .setTransparencyState(NO_TRANSPARENCY) + .setCullState(NO_CULL) + .setLightmapState(LIGHTMAP) + .createCompositeState(false); + return RenderType.create(API.MOD_ID + ":network_cable", DefaultVertexFormats.POSITION_COLOR_LIGHTMAP, GL11.GL_QUAD_STRIP, 256, diff --git a/src/main/java/li/cil/oc2/client/renderer/NetworkCableRenderer.java b/src/main/java/li/cil/oc2/client/renderer/NetworkCableRenderer.java index b7b1d9c0..b257a96e 100644 --- a/src/main/java/li/cil/oc2/client/renderer/NetworkCableRenderer.java +++ b/src/main/java/li/cil/oc2/client/renderer/NetworkCableRenderer.java @@ -82,12 +82,12 @@ public final class NetworkCableRenderer { /////////////////////////////////////////////////////////////////// private static void handleChunkUnloadEvent(final ChunkEvent.Unload event) { - if (event.getWorld().isRemote()) { + if (event.getWorld().isClientSide()) { final ChunkPos chunkPos = event.getChunk().getPos(); final ArrayList list = new ArrayList<>(NetworkCableRenderer.connectors); for (final NetworkConnectorTileEntity connector : list) { - final ChunkPos connectorChunkPos = new ChunkPos(connector.getPos()); + final ChunkPos connectorChunkPos = new ChunkPos(connector.getBlockPos()); if (Objects.equals(connectorChunkPos, chunkPos)) { connectors.remove(connector); } @@ -98,12 +98,12 @@ public final class NetworkCableRenderer { } private static void handleWorldUnloadEvent(final WorldEvent.Unload event) { - if (event.getWorld().isRemote()) { + if (event.getWorld().isClientSide()) { final IWorld world = event.getWorld(); final ArrayList list = new ArrayList<>(NetworkCableRenderer.connectors); for (final NetworkConnectorTileEntity connector : list) { - if (connector.getWorld() == world) { + if (connector.getLevel() == world) { connectors.remove(connector); } } @@ -116,7 +116,7 @@ public final class NetworkCableRenderer { validateConnectors(); validatePairs(); - if (Minecraft.isFabulousGraphicsEnabled()) { + if (Minecraft.useShaderTransparency()) { return; } @@ -125,42 +125,42 @@ public final class NetworkCableRenderer { } final Minecraft client = Minecraft.getInstance(); - final World world = client.world; + final World world = client.level; if (world == null) { return; } final MatrixStack matrixStack = event.getMatrixStack(); - final ActiveRenderInfo activeRenderInfo = client.gameRenderer.getActiveRenderInfo(); - final Vector3d eye = activeRenderInfo.getProjectedView(); + final ActiveRenderInfo activeRenderInfo = client.gameRenderer.getMainCamera(); + final Vector3d eye = activeRenderInfo.getPosition(); - final ClippingHelper frustum = new ClippingHelper(matrixStack.getLast().getMatrix(), event.getProjectionMatrix()); - frustum.setCameraPosition(eye.getX(), eye.getY(), eye.getZ()); + final ClippingHelper frustum = new ClippingHelper(matrixStack.last().pose(), event.getProjectionMatrix()); + frustum.prepare(eye.x, eye.y, eye.z); - matrixStack.push(); - matrixStack.translate(-eye.getX(), -eye.getY(), -eye.getZ()); + matrixStack.pushPose(); + matrixStack.translate(-eye.x, -eye.y, -eye.z); - renderCables(world, matrixStack, eye, connections, frustum::isBoundingBoxInFrustum); + renderCables(world, matrixStack, eye, connections, frustum::isVisible); - matrixStack.pop(); + matrixStack.popPose(); } private static void renderCables(final IBlockDisplayReader world, final MatrixStack matrixStack, final Vector3d eye, final ArrayList connections, final Predicate filter) { - final Matrix4f viewMatrix = matrixStack.getLast().getMatrix(); + final Matrix4f viewMatrix = matrixStack.last().pose(); final RenderType renderType = CustomRenderType.getNetworkCable(); - final IRenderTypeBuffer.Impl bufferSource = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); + final IRenderTypeBuffer.Impl bufferSource = Minecraft.getInstance().renderBuffers().bufferSource(); - final float r = CABLE_COLOR.getX(); - final float g = CABLE_COLOR.getY(); - final float b = CABLE_COLOR.getZ(); + final float r = CABLE_COLOR.x(); + final float g = CABLE_COLOR.y(); + final float b = CABLE_COLOR.z(); for (final Connection connection : connections) { final Vector3d p0 = connection.from; final Vector3d p1 = connection.to; - if (!p0.isWithinDistanceOf(eye, MAX_RENDER_DISTANCE) && !p1.isWithinDistanceOf(eye, MAX_RENDER_DISTANCE)) { + if (!p0.closerThan(eye, MAX_RENDER_DISTANCE) && !p1.closerThan(eye, MAX_RENDER_DISTANCE)) { continue; } @@ -183,24 +183,24 @@ public final class NetworkCableRenderer { final Vector3d n = getExtrusionVector(eye, p, connection.forward); final BlockPos blockPos = new BlockPos(p); - final int blockLight = world.getLightFor(LightType.BLOCK, blockPos); - final int skyLight = world.getLightFor(LightType.SKY, blockPos); - final int packedLight = LightTexture.packLight(blockLight, skyLight); + final int blockLight = world.getBrightness(LightType.BLOCK, blockPos); + final int skyLight = world.getBrightness(LightType.SKY, blockPos); + final int packedLight = LightTexture.pack(blockLight, skyLight); final Vector3f v0 = new Vector3f(p.subtract(n)); final Vector3f v1 = new Vector3f(p.add(n)); - buffer.pos(viewMatrix, v0.getX(), v0.getY(), v0.getZ()) + buffer.vertex(viewMatrix, v0.x(), v0.y(), v0.z()) .color(r, g, b, 1f) - .lightmap(packedLight) + .uv2(packedLight) .endVertex(); - buffer.pos(viewMatrix, v1.getX(), v1.getY(), v1.getZ()) + buffer.vertex(viewMatrix, v1.x(), v1.y(), v1.z()) .color(r, g, b, 1f) - .lightmap(packedLight) + .uv2(packedLight) .endVertex(); } - bufferSource.finish(renderType); + bufferSource.endBatch(renderType); } } @@ -215,7 +215,7 @@ public final class NetworkCableRenderer { } private static Vector3d getExtrusionVector(final Vector3d eye, final Vector3d v, final Vector3d forward) { - return forward.crossProduct(eye.subtract(v)).normalize().scale(CABLE_THICKNESS); + return forward.cross(eye.subtract(v)).normalize().scale(CABLE_THICKNESS); } private static float computeCableHang(final Vector3d a, final Vector3d b) { @@ -237,9 +237,9 @@ public final class NetworkCableRenderer { 0, swingAmount * MathHelper.cos(relRadialTime)); } else { - return c.add(swingAmount * MathHelper.cos(relRadialTime) * right.getX(), + return c.add(swingAmount * MathHelper.cos(relRadialTime) * right.x, 0.5f * swingAmount * MathHelper.sin(relRadialTime * 2 - (float) Math.PI) - swingAmount, - swingAmount * MathHelper.cos(relRadialTime) * right.getZ()); + swingAmount * MathHelper.cos(relRadialTime) * right.z); } } @@ -272,7 +272,7 @@ public final class NetworkCableRenderer { final HashSet seen = new HashSet<>(); for (final NetworkConnectorTileEntity connector : connectors) { - final BlockPos position = connector.getPos(); + final BlockPos position = connector.getBlockPos(); for (final BlockPos connectedPosition : connector.getConnectedPositions()) { final Connection connection = new Connection(position, connectedPosition); if (seen.add(connection)) { @@ -301,12 +301,12 @@ public final class NetworkCableRenderer { this.toPos = toPos; } - from = Vector3d.copyCentered(fromPos); - to = Vector3d.copyCentered(toPos); + from = Vector3d.atCenterOf(fromPos); + to = Vector3d.atCenterOf(toPos); forward = to.subtract(from).normalize(); right = fromPos.getX() == toPos.getX() && fromPos.getZ() == toPos.getZ() - ? null : forward.crossProduct(POS_Y); - bounds = new AxisAlignedBB(from, to).grow(0, CABLE_HANG_MAX, 0); + ? null : forward.cross(POS_Y); + bounds = new AxisAlignedBB(from, to).inflate(0, CABLE_HANG_MAX, 0); } @Override diff --git a/src/main/java/li/cil/oc2/client/renderer/entity/RobotEntityRenderer.java b/src/main/java/li/cil/oc2/client/renderer/entity/RobotEntityRenderer.java index 57cf4311..2a961fb8 100644 --- a/src/main/java/li/cil/oc2/client/renderer/entity/RobotEntityRenderer.java +++ b/src/main/java/li/cil/oc2/client/renderer/entity/RobotEntityRenderer.java @@ -24,30 +24,30 @@ public final class RobotEntityRenderer extends EntityRenderer { /////////////////////////////////////////////////////////////////// @Override - public ResourceLocation getEntityTexture(final RobotEntity entity) { + public ResourceLocation getTextureLocation(final RobotEntity entity) { return RobotModel.ROBOT_ENTITY_TEXTURE; } @Override public void render(final RobotEntity entity, final float entityYaw, final float partialTicks, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int packedLight) { final RobotEntity.AnimationState state = entity.getAnimationState(); - state.update(partialTicks, entity.world.rand); + state.update(partialTicks, entity.level.random); - matrixStack.push(); + matrixStack.pushPose(); // NB: we don't entityYaw given to use because that uses a plain lerp which can lead to ugly // jumps in case we get a wrapped rotationYaw synced from the server (leading to ~360 // degree delta to the last known previous rotation). Haven't figured out where to // alternatively prevent this wrapping or patch the prev value instead. - final float partialRotation = MathHelper.degreesDifferenceAbs(entity.prevRotationYaw, entity.rotationYaw) * partialTicks; - final float rotation = MathHelper.approachDegrees(entity.prevRotationYaw, entity.rotationYaw, partialRotation); - matrixStack.rotate(Vector3f.YN.rotationDegrees(rotation)); + final float partialRotation = MathHelper.degreesDifferenceAbs(entity.yRotO, entity.yRot) * partialTicks; + final float rotation = MathHelper.approachDegrees(entity.yRotO, entity.yRot, partialRotation); + matrixStack.mulPose(Vector3f.YN.rotationDegrees(rotation)); - model.setRotationAngles(entity, 0, 0, 0, 0, 0); + model.setupAnim(entity, 0, 0, 0, 0, 0); - final IVertexBuilder builder = buffer.getBuffer(model.getRenderType(getEntityTexture(entity))); - model.render(matrixStack, builder, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1); + final IVertexBuilder builder = buffer.getBuffer(model.renderType(getTextureLocation(entity))); + model.renderToBuffer(matrixStack, builder, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1); - matrixStack.pop(); + matrixStack.popPose(); // final RayTraceResult hit = Minecraft.getInstance().objectMouseOver; // if (hit instanceof EntityRayTraceResult && entity == ((EntityRayTraceResult) hit).getEntity()) { diff --git a/src/main/java/li/cil/oc2/client/renderer/entity/model/RobotModel.java b/src/main/java/li/cil/oc2/client/renderer/entity/model/RobotModel.java index 0924d18b..bfb66af4 100644 --- a/src/main/java/li/cil/oc2/client/renderer/entity/model/RobotModel.java +++ b/src/main/java/li/cil/oc2/client/renderer/entity/model/RobotModel.java @@ -25,20 +25,20 @@ public final class RobotModel extends EntityModel { public RobotModel() { topRenderer = new ModelRenderer(this, 1, 1) - .setTextureSize(64, 64) + .setTexSize(64, 64) .addBox(-7, 8, -7, 14, 6, 14); baseRenderer = new ModelRenderer(this, 1, 23) - .setTextureSize(64, 64) + .setTexSize(64, 64) .addBox(-7, 0, -7, 14, 7, 14); coreRenderer = new ModelRenderer(this, 1, 34) - .setTextureSize(64, 64) + .setTexSize(64, 64) .addBox(-6, 7, -6, 12, 1, 12); } /////////////////////////////////////////////////////////////////// @Override - public void setRotationAngles(final RobotEntity entity, final float limbSwing, final float limbSwingAmount, final float ageInTicks, final float netHeadYaw, final float headPitch) { + public void setupAnim(final RobotEntity entity, final float limbSwing, final float limbSwingAmount, final float ageInTicks, final float netHeadYaw, final float headPitch) { final RobotEntity.AnimationState state = entity.getAnimationState(); baseY = state.baseRenderOffsetY; topY = state.topRenderOffsetY; @@ -46,17 +46,17 @@ public final class RobotModel extends EntityModel { } @Override - public void render(final MatrixStack matrixStack, final IVertexBuilder buffer, final int packedLight, final int packedOverlay, final float red, final float green, final float blue, final float alpha) { - matrixStack.push(); + public void renderToBuffer(final MatrixStack matrixStack, final IVertexBuilder buffer, final int packedLight, final int packedOverlay, final float red, final float green, final float blue, final float alpha) { + matrixStack.pushPose(); matrixStack.translate(0, topY, 0); - matrixStack.rotate(TransformationHelper.quatFromXYZ(topRotation, true)); + matrixStack.mulPose(TransformationHelper.quatFromXYZ(topRotation, true)); topRenderer.render(matrixStack, buffer, packedLight, packedOverlay); - matrixStack.pop(); + matrixStack.popPose(); - matrixStack.push(); + matrixStack.pushPose(); matrixStack.translate(0, baseY, 0); baseRenderer.render(matrixStack, buffer, packedLight, packedOverlay); - coreRenderer.render(matrixStack, buffer, LightTexture.packLight(15, 15), packedOverlay); - matrixStack.pop(); + coreRenderer.render(matrixStack, buffer, LightTexture.pack(15, 15), packedOverlay); + matrixStack.popPose(); } } diff --git a/src/main/java/li/cil/oc2/client/renderer/tileentity/ChargerTileEntityRenderer.java b/src/main/java/li/cil/oc2/client/renderer/tileentity/ChargerTileEntityRenderer.java index 236fe35d..47e132e1 100644 --- a/src/main/java/li/cil/oc2/client/renderer/tileentity/ChargerTileEntityRenderer.java +++ b/src/main/java/li/cil/oc2/client/renderer/tileentity/ChargerTileEntityRenderer.java @@ -17,7 +17,7 @@ import net.minecraft.util.math.vector.Matrix4f; public final class ChargerTileEntityRenderer extends TileEntityRenderer { public static final ResourceLocation EFFECT_LOCATION = new ResourceLocation(API.MOD_ID, "block/charger/effect"); - private static final RenderMaterial TEXTURE_EFFECT = new RenderMaterial(PlayerContainer.LOCATION_BLOCKS_TEXTURE, EFFECT_LOCATION); + private static final RenderMaterial TEXTURE_EFFECT = new RenderMaterial(PlayerContainer.BLOCK_ATLAS, EFFECT_LOCATION); private static final int EFFECT_LAYERS = 3; private static final float EFFECT_HEIGHT = 0.5f; @@ -41,30 +41,30 @@ public final class ChargerTileEntityRenderer extends TileEntityRenderer wrappedText = renderDispatcher.getFontRenderer().getCharacterManager().func_238362_b_(text, maxWidth, Style.EMPTY); + final FontRenderer fontRenderer = renderer.font; + final List wrappedText = fontRenderer.getSplitter().splitLines(text, maxWidth, Style.EMPTY); if (wrappedText.size() == 1) { - final int textWidth = fontRenderer.getStringPropertyWidth(text); - fontRenderer.func_243248_b(stack, text, (maxWidth - textWidth) * 0.5f, 0, 0xEE3322); + final int textWidth = fontRenderer.width(text); + fontRenderer.draw(stack, text, (maxWidth - textWidth) * 0.5f, 0, 0xEE3322); } else { for (int i = 0; i < wrappedText.size(); i++) { - fontRenderer.drawString(stack, wrappedText.get(i).getString(), 0, i * fontRenderer.FONT_HEIGHT, 0xEE3322); + fontRenderer.draw(stack, wrappedText.get(i).getString(), 0, i * fontRenderer.lineHeight, 0xEE3322); } } - stack.pop(); + stack.popPose(); } private void renderStatus(final Matrix4f matrix, final IRenderTypeBuffer buffer) { @@ -195,12 +195,12 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer connectionType : FACING_TO_CONNECTION_MAP.values()) { - if (state.get(connectionType) == ConnectionType.INTERFACE) { + if (state.getValue(connectionType) == ConnectionType.INTERFACE) { partCount++; } } @@ -104,8 +104,8 @@ public final class BusCableBlock extends Block { } public static Direction getHitSide(final BlockPos pos, final BlockRayTraceResult hit) { - final Vector3d localHitPos = hit.getHitVec().subtract(Vector3d.copyCentered(pos)); - return Direction.getFacingFromVector(localHitPos.x, localHitPos.y, localHitPos.z); + final Vector3d localHitPos = hit.getLocation().subtract(Vector3d.atCenterOf(pos)); + return Direction.getNearest(localHitPos.x, localHitPos.y, localHitPos.z); } /////////////////////////////////////////////////////////////////// @@ -116,16 +116,16 @@ public final class BusCableBlock extends Block { public BusCableBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(1.5f, 6.0f)); + .strength(1.5f, 6.0f)); - BlockState defaultState = getStateContainer().getBaseState(); + BlockState defaultState = getStateDefinition().any(); for (final EnumProperty property : FACING_TO_CONNECTION_MAP.values()) { - defaultState = defaultState.with(property, ConnectionType.NONE); + defaultState = defaultState.setValue(property, ConnectionType.NONE); } - defaultState = defaultState.with(HAS_CABLE, true); - setDefaultState(defaultState); + defaultState = defaultState.setValue(HAS_CABLE, true); + registerDefaultState(defaultState); shapes = makeShapes(); } @@ -134,11 +134,11 @@ public final class BusCableBlock extends Block { public boolean addInterface(final World world, final BlockPos pos, final BlockState state, final Direction side) { final EnumProperty property = FACING_TO_CONNECTION_MAP.get(side); - if (state.get(property) != ConnectionType.NONE) { + if (state.getValue(property) != ConnectionType.NONE) { return false; } - world.setBlockState(pos, state.with(property, ConnectionType.INTERFACE), BlockFlags.DEFAULT_AND_RERENDER); + world.setBlock(pos, state.setValue(property, ConnectionType.INTERFACE), BlockFlags.DEFAULT_AND_RERENDER); onConnectionTypeChanged(world, pos, side); @@ -146,11 +146,11 @@ public final class BusCableBlock extends Block { } public boolean addCable(final World world, final BlockPos pos, final BlockState state) { - if (state.get(HAS_CABLE)) { + if (state.getValue(HAS_CABLE)) { return false; } - world.setBlockState(pos, state.with(HAS_CABLE, true), BlockFlags.DEFAULT_AND_RERENDER); + world.setBlock(pos, state.setValue(HAS_CABLE, true), BlockFlags.DEFAULT_AND_RERENDER); onConnectionTypeChanged(world, pos, null); @@ -170,7 +170,7 @@ public final class BusCableBlock extends Block { @SuppressWarnings("deprecation") @Override public void neighborChanged(final BlockState state, final World world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) { - final TileEntity tileEntity = world.getTileEntity(pos); + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity instanceof BusCableTileEntity) { final BusCableTileEntity busCable = (BusCableTileEntity) tileEntity; busCable.handleNeighborChanged(changedBlockPos); @@ -179,31 +179,31 @@ public final class BusCableBlock extends Block { @SuppressWarnings("deprecation") @Override - public ActionResultType onBlockActivated(final BlockState state, final World world, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult hit) { - if (Wrenches.isWrench(player.getHeldItem(hand))) { - if (player.isSneaking()) { + public ActionResultType use(final BlockState state, final World world, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult hit) { + if (Wrenches.isWrench(player.getItemInHand(hand))) { + if (player.isShiftKeyDown()) { // NB: leave wrenching logic up to wrench when the to-be-removed interface is the last // part of this bus. This ensures we properly remove the block itself without having // to duplicate the logic needed for that. if (getPartCount(state) > 1) if (tryRemovePlug(state, world, pos, player, hit) || tryRemoveCable(state, world, pos, player)) { - return ActionResultType.func_233537_a_(world.isRemote()); + return ActionResultType.sidedSuccess(world.isClientSide); } } else { - final TileEntity tileEntity = world.getTileEntity(pos); + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity instanceof BusCableTileEntity) { final BusCableTileEntity busCableTileEntity = (BusCableTileEntity) tileEntity; final Direction side = getHitSide(pos, hit); if (getConnectionType(state, side) == ConnectionType.INTERFACE) { openBusInterfaceScreen(busCableTileEntity, side); - return ActionResultType.func_233537_a_(world.isRemote()); + return ActionResultType.sidedSuccess(world.isClientSide); } } } } - return super.onBlockActivated(state, world, pos, player, hand, hit); + return super.use(state, world, pos, player, hand, hit); } @SuppressWarnings("deprecation") @@ -211,13 +211,13 @@ public final class BusCableBlock extends Block { public List getDrops(final BlockState state, final LootContext.Builder builder) { final List drops = new ArrayList<>(super.getDrops(state, builder)); - if (state.get(HAS_CABLE)) { + if (state.getValue(HAS_CABLE)) { drops.add(new ItemStack(Items.BUS_CABLE.get())); } int interfaceCount = 0; for (final Direction side : Constants.DIRECTIONS) { - final ConnectionType connectionType = state.get(FACING_TO_CONNECTION_MAP.get(side)); + final ConnectionType connectionType = state.getValue(FACING_TO_CONNECTION_MAP.get(side)); if (connectionType == ConnectionType.INTERFACE) { interfaceCount++; } @@ -232,16 +232,16 @@ public final class BusCableBlock extends Block { @Override public BlockState getStateForPlacement(final BlockItemUseContext context) { - BlockState state = getDefaultState(); + BlockState state = defaultBlockState(); - final World world = context.getWorld(); - final BlockPos position = context.getPos(); + final World world = context.getLevel(); + final BlockPos position = context.getClickedPos(); for (final Map.Entry> entry : FACING_TO_CONNECTION_MAP.entrySet()) { final Direction facing = entry.getKey(); - final BlockPos facingPos = position.offset(facing); - if (context.getItem().getItem() == Items.BUS_CABLE.get() && + final BlockPos facingPos = position.relative(facing); + if (context.getItemInHand().getItem() == Items.BUS_CABLE.get() && canHaveCableTo(world.getBlockState(facingPos), facing.getOpposite())) { - state = state.with(entry.getValue(), ConnectionType.CABLE); + state = state.setValue(entry.getValue(), ConnectionType.CABLE); } } @@ -250,15 +250,15 @@ public final class BusCableBlock extends Block { @SuppressWarnings("deprecation") @Override - public BlockState updatePostPlacement(BlockState state, final Direction facing, final BlockState facingState, final IWorld world, final BlockPos currentPos, final BlockPos facingPos) { - if (state.get(FACING_TO_CONNECTION_MAP.get(facing)) == ConnectionType.INTERFACE) { + public BlockState updateShape(BlockState state, final Direction facing, final BlockState facingState, final IWorld world, final BlockPos currentPos, final BlockPos facingPos) { + if (state.getValue(FACING_TO_CONNECTION_MAP.get(facing)) == ConnectionType.INTERFACE) { return state; } - if (state.get(HAS_CABLE) && canHaveCableTo(facingState, facing.getOpposite())) { - state = state.with(FACING_TO_CONNECTION_MAP.get(facing), ConnectionType.CABLE); + if (state.getValue(HAS_CABLE) && canHaveCableTo(facingState, facing.getOpposite())) { + state = state.setValue(FACING_TO_CONNECTION_MAP.get(facing), ConnectionType.CABLE); } else { - state = state.with(FACING_TO_CONNECTION_MAP.get(facing), ConnectionType.NONE); + state = state.setValue(FACING_TO_CONNECTION_MAP.get(facing), ConnectionType.NONE); } onConnectionTypeChanged(world, currentPos, facing); @@ -275,8 +275,8 @@ public final class BusCableBlock extends Block { /////////////////////////////////////////////////////////////////// @Override - protected void fillStateContainer(final StateContainer.Builder builder) { - super.fillStateContainer(builder); + protected void createBlockStateDefinition(final StateContainer.Builder builder) { + super.createBlockStateDefinition(builder); FACING_TO_CONNECTION_MAP.values().forEach(builder::add); builder.add(HAS_CABLE); } @@ -285,13 +285,13 @@ public final class BusCableBlock extends Block { private static boolean canHaveCableTo(final BlockState state, final Direction side) { return state.getBlock() == Blocks.BUS_CABLE.get() && - state.get(HAS_CABLE) && - state.get(FACING_TO_CONNECTION_MAP.get(side)) != ConnectionType.INTERFACE; + state.getValue(HAS_CABLE) && + state.getValue(FACING_TO_CONNECTION_MAP.get(side)) != ConnectionType.INTERFACE; } private static int getPartCount(final BlockState state) { int partCount = getInterfaceCount(state); - if (state.get(HAS_CABLE)) { + if (state.getValue(HAS_CABLE)) { partCount++; } return partCount; @@ -301,15 +301,15 @@ public final class BusCableBlock extends Block { final Direction side = getHitSide(pos, hit); final EnumProperty property = FACING_TO_CONNECTION_MAP.get(side); - if (state.get(property) != ConnectionType.INTERFACE) { + if (state.getValue(property) != ConnectionType.INTERFACE) { return false; } - final BlockPos neighborPos = pos.offset(side); - if (state.get(HAS_CABLE) && canHaveCableTo(world.getBlockState(neighborPos), side.getOpposite())) { - world.setBlockState(pos, state.with(property, ConnectionType.CABLE)); + final BlockPos neighborPos = pos.relative(side); + if (state.getValue(HAS_CABLE) && canHaveCableTo(world.getBlockState(neighborPos), side.getOpposite())) { + world.setBlockAndUpdate(pos, state.setValue(property, ConnectionType.CABLE)); } else { - world.setBlockState(pos, state.with(property, ConnectionType.NONE)); + world.setBlockAndUpdate(pos, state.setValue(property, ConnectionType.NONE)); } handlePartRemoved(state, world, pos, side, player, new ItemStack(Items.BUS_INTERFACE.get())); @@ -318,11 +318,11 @@ public final class BusCableBlock extends Block { } private static boolean tryRemoveCable(final BlockState state, final World world, final BlockPos pos, final PlayerEntity player) { - if (!state.get(HAS_CABLE)) { + if (!state.getValue(HAS_CABLE)) { return false; } - world.setBlockState(pos, state.with(HAS_CABLE, false)); + world.setBlockAndUpdate(pos, state.setValue(HAS_CABLE, false)); handlePartRemoved(state, world, pos, null, player, new ItemStack(Items.BUS_CABLE.get())); @@ -332,10 +332,10 @@ public final class BusCableBlock extends Block { private static void handlePartRemoved(final BlockState state, final World world, final BlockPos pos, @Nullable final Direction side, final PlayerEntity player, final ItemStack drop) { onConnectionTypeChanged(world, pos, side); - if (!player.isCreative() && world.getGameRules().getBoolean(GameRules.DO_TILE_DROPS)) { + if (!player.isCreative() && world.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) { ItemStackUtils.spawnAsEntity(world, pos, drop, side).ifPresent(entity -> { - entity.setNoPickupDelay(); - entity.onCollideWithPlayer(player); + entity.setNoPickUpDelay(); + entity.playerTouch(player); }); } @@ -343,7 +343,7 @@ public final class BusCableBlock extends Block { } private static void onConnectionTypeChanged(final IWorld world, final BlockPos pos, @Nullable final Direction face) { - final TileEntity tileEntity = world.getTileEntity(pos); + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity instanceof BusCableTileEntity) { final BusCableTileEntity busCable = (BusCableTileEntity) tileEntity; busCable.handleConnectivityChanged(face); @@ -353,11 +353,11 @@ public final class BusCableBlock extends Block { @OnlyIn(Dist.CLIENT) private static void openBusInterfaceScreen(final BusCableTileEntity tileEntity, final Direction side) { final BusInterfaceScreen screen = new BusInterfaceScreen(tileEntity, side); - Minecraft.getInstance().displayGuiScreen(screen); + Minecraft.getInstance().setScreen(screen); } private static VoxelShape[] makeShapes() { - final VoxelShape ownCableBounds = Block.makeCuboidShape(5, 5, 5, 11, 11, 11); + final VoxelShape ownCableBounds = Block.box(5, 5, 5, 11, 11, 11); final VoxelShape[] cableShapes = new VoxelShape[Constants.BLOCK_FACE_COUNT]; final VoxelShape[] interfaceShapes = new VoxelShape[Constants.BLOCK_FACE_COUNT]; for (int i = 0; i < Constants.BLOCK_FACE_COUNT; i++) { @@ -404,20 +404,20 @@ public final class BusCableBlock extends Block { final int zSize = 5; final Direction yDirection = zDirection.getAxis() == Direction.Axis.Y ? Direction.NORTH : Direction.UP; - final Direction xDirection = zDirection.getAxis() == Direction.Axis.Y ? Direction.WEST : zDirection.rotateY(); + final Direction xDirection = zDirection.getAxis() == Direction.Axis.Y ? Direction.WEST : zDirection.getClockWise(); final Vector3i min = new Vector3i(8, 8, 8) - .offset(xDirection, -xSize / 2) - .offset(yDirection, -ySize / 2) - .offset(zDirection, 8 - zSize); + .relative(xDirection, -xSize / 2) + .relative(yDirection, -ySize / 2) + .relative(zDirection, 8 - zSize); final Vector3i max = new Vector3i(8, 8, 8) - .offset(xDirection, xSize / 2) - .offset(yDirection, ySize / 2) - .offset(zDirection, 8); + .relative(xDirection, xSize / 2) + .relative(yDirection, ySize / 2) + .relative(zDirection, 8); final AxisAlignedBB bounds = new AxisAlignedBB( - Vector3d.copy(min).scale(1 / 16.0), - Vector3d.copy(max).scale(1 / 16.0) + Vector3d.atLowerCornerOf(min).scale(1 / 16.0), + Vector3d.atLowerCornerOf(max).scale(1 / 16.0) ); return VoxelShapes.create(bounds); @@ -429,20 +429,20 @@ public final class BusCableBlock extends Block { final int zSize = 1; final Direction yDirection = zDirection.getAxis() == Direction.Axis.Y ? Direction.NORTH : Direction.UP; - final Direction xDirection = zDirection.getAxis() == Direction.Axis.Y ? Direction.WEST : zDirection.rotateY(); + final Direction xDirection = zDirection.getAxis() == Direction.Axis.Y ? Direction.WEST : zDirection.getClockWise(); final Vector3i min = new Vector3i(8, 8, 8) - .offset(xDirection, -xSize / 2) - .offset(yDirection, -ySize / 2) - .offset(zDirection, 8 - zSize); + .relative(xDirection, -xSize / 2) + .relative(yDirection, -ySize / 2) + .relative(zDirection, 8 - zSize); final Vector3i max = new Vector3i(8, 8, 8) - .offset(xDirection, xSize / 2) - .offset(yDirection, ySize / 2) - .offset(zDirection, 8); + .relative(xDirection, xSize / 2) + .relative(yDirection, ySize / 2) + .relative(zDirection, 8); final AxisAlignedBB bounds = new AxisAlignedBB( - Vector3d.copy(min).scale(1 / 16.0), - Vector3d.copy(max).scale(1 / 16.0) + Vector3d.atLowerCornerOf(min).scale(1 / 16.0), + Vector3d.atLowerCornerOf(max).scale(1 / 16.0) ); return VoxelShapes.or(getCableShape(zDirection), VoxelShapes.create(bounds)); @@ -454,7 +454,7 @@ public final class BusCableBlock extends Block { for (int sideIndex = 0; sideIndex < Constants.BLOCK_FACE_COUNT; sideIndex++) { final int cableBit = 1 << sideIndex; final int interfaceBit = cableBit << 6; - switch (state.get(FACING_TO_CONNECTION_MAP.get(Constants.DIRECTIONS[sideIndex]))) { + switch (state.getValue(FACING_TO_CONNECTION_MAP.get(Constants.DIRECTIONS[sideIndex]))) { case CABLE: index |= cableBit; break; @@ -466,7 +466,7 @@ public final class BusCableBlock extends Block { index = index << 1; - if (state.get(HAS_CABLE)) { + if (state.getValue(HAS_CABLE)) { index |= 1; } diff --git a/src/main/java/li/cil/oc2/common/block/ChargerBlock.java b/src/main/java/li/cil/oc2/common/block/ChargerBlock.java index 76383a1c..52c55d1f 100644 --- a/src/main/java/li/cil/oc2/common/block/ChargerBlock.java +++ b/src/main/java/li/cil/oc2/common/block/ChargerBlock.java @@ -16,10 +16,10 @@ import javax.annotation.Nullable; public final class ChargerBlock extends BreakableBlock { public ChargerBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(1.5f, 6.0f)); - setDefaultState(getStateContainer().getBaseState().with(HorizontalBlock.HORIZONTAL_FACING, Direction.NORTH)); + .strength(1.5f, 6.0f)); + registerDefaultState(getStateDefinition().any().setValue(HorizontalBlock.FACING, Direction.NORTH)); } /////////////////////////////////////////////////////////////////// @@ -27,13 +27,13 @@ public final class ChargerBlock extends BreakableBlock { @SuppressWarnings("deprecation") @Override public BlockState rotate(final BlockState state, final Rotation rot) { - return state.with(HorizontalBlock.HORIZONTAL_FACING, rot.rotate(state.get(HorizontalBlock.HORIZONTAL_FACING))); + return state.setValue(HorizontalBlock.FACING, rot.rotate(state.getValue(HorizontalBlock.FACING))); } @SuppressWarnings("deprecation") @Override public BlockState mirror(final BlockState state, final Mirror mirrorIn) { - return state.rotate(mirrorIn.toRotation(state.get(HorizontalBlock.HORIZONTAL_FACING))); + return state.rotate(mirrorIn.getRotation(state.getValue(HorizontalBlock.FACING))); } @Override @@ -49,14 +49,14 @@ public final class ChargerBlock extends BreakableBlock { @Override public BlockState getStateForPlacement(final BlockItemUseContext context) { - return super.getDefaultState().with(HorizontalBlock.HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); + return super.defaultBlockState().setValue(HorizontalBlock.FACING, context.getHorizontalDirection().getOpposite()); } /////////////////////////////////////////////////////////////////// @Override - protected void fillStateContainer(final StateContainer.Builder builder) { - super.fillStateContainer(builder); - builder.add(HorizontalBlock.HORIZONTAL_FACING); + protected void createBlockStateDefinition(final StateContainer.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(HorizontalBlock.FACING); } } diff --git a/src/main/java/li/cil/oc2/common/block/ComputerBlock.java b/src/main/java/li/cil/oc2/common/block/ComputerBlock.java index 551d0dfb..eafd523a 100644 --- a/src/main/java/li/cil/oc2/common/block/ComputerBlock.java +++ b/src/main/java/li/cil/oc2/common/block/ComputerBlock.java @@ -52,11 +52,11 @@ public final class ComputerBlock extends HorizontalBlock { // We bake the "screen" indent on the front into the collision shape to prevent stuff being // placeable on that side, such as network connectors, torches, etc. private static final VoxelShape NEG_Z_SHAPE = VoxelShapes.or( - Block.makeCuboidShape(0, 0, 1, 16, 16, 16), // main body - Block.makeCuboidShape(0, 15, 0, 16, 16, 1), // across top - Block.makeCuboidShape(0, 0, 0, 16, 6, 1), // across bottom - Block.makeCuboidShape(0, 0, 0, 1, 16, 1), // up left - Block.makeCuboidShape(15, 0, 0, 16, 16, 1) // up right + Block.box(0, 0, 1, 16, 16, 16), // main body + Block.box(0, 15, 0, 16, 16, 1), // across top + Block.box(0, 0, 0, 16, 6, 1), // across bottom + Block.box(0, 0, 0, 1, 16, 1), // up left + Block.box(15, 0, 0, 16, 16, 1) // up right ); private static final VoxelShape NEG_X_SHAPE = VoxelShapeUtils.rotateHorizontalClockwise(NEG_Z_SHAPE); private static final VoxelShape POS_Z_SHAPE = VoxelShapeUtils.rotateHorizontalClockwise(NEG_X_SHAPE); @@ -66,25 +66,25 @@ public final class ComputerBlock extends HorizontalBlock { public ComputerBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(1.5f, 6.0f)); - setDefaultState(getStateContainer().getBaseState().with(HORIZONTAL_FACING, Direction.NORTH)); + .strength(1.5f, 6.0f)); + registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH)); } /////////////////////////////////////////////////////////////////// @Override - public void fillItemGroup(final ItemGroup group, final NonNullList items) { - super.fillItemGroup(group, items); + public void fillItemCategory(final ItemGroup group, final NonNullList items) { + super.fillItemCategory(group, items); items.add(getPreconfiguredComputer()); } @OnlyIn(Dist.CLIENT) @Override - public void addInformation(final ItemStack stack, @Nullable final IBlockReader world, final List tooltip, final ITooltipFlag advanced) { - super.addInformation(stack, world, tooltip, advanced); + public void appendHoverText(final ItemStack stack, @Nullable final IBlockReader world, final List tooltip, final ITooltipFlag advanced) { + super.appendHoverText(stack, world, tooltip, advanced); TooltipUtils.addEnergyConsumption(Config.computerEnergyPerTick, tooltip); TooltipUtils.addTileEntityInventoryInformation(stack, tooltip); } @@ -101,14 +101,14 @@ public final class ComputerBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override - public boolean canProvidePower(final BlockState state) { + public boolean isSignalSource(final BlockState state) { return true; } @SuppressWarnings("deprecation") @Override - public int getWeakPower(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { - final TileEntity tileEntity = world.getTileEntity(pos); + public int getSignal(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity != null) { // Redstone requests info for faces with external perspective. Capabilities treat // the Direction from internal perspective, so flip it. @@ -117,13 +117,13 @@ public final class ComputerBlock extends HorizontalBlock { .orElse(0); } - return super.getWeakPower(state, world, pos, side); + return super.getSignal(state, world, pos, side); } @SuppressWarnings("deprecation") @Override - public int getStrongPower(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { - return getWeakPower(state, world, pos, side); + public int getDirectSignal(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { + return getSignal(state, world, pos, side); } @Override @@ -134,7 +134,7 @@ public final class ComputerBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override public void neighborChanged(final BlockState state, final World world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) { - final TileEntity tileEntity = world.getTileEntity(pos); + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity instanceof ComputerTileEntity) { final ComputerTileEntity computer = (ComputerTileEntity) tileEntity; computer.handleNeighborChanged(); @@ -144,7 +144,7 @@ public final class ComputerBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override public VoxelShape getShape(final BlockState state, final IBlockReader world, final BlockPos pos, final ISelectionContext context) { - switch (state.get(HORIZONTAL_FACING)) { + switch (state.getValue(FACING)) { case NORTH: return NEG_Z_SHAPE; case SOUTH: @@ -159,21 +159,21 @@ public final class ComputerBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override - public ActionResultType onBlockActivated(final BlockState state, final World world, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult hit) { - final TileEntity tileEntity = world.getTileEntity(pos); + public ActionResultType use(final BlockState state, final World world, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult hit) { + final TileEntity tileEntity = world.getBlockEntity(pos); if (!(tileEntity instanceof ComputerTileEntity)) { - return super.onBlockActivated(state, world, pos, player, hand, hit); + return super.use(state, world, pos, player, hand, hit); } final ComputerTileEntity computer = (ComputerTileEntity) tileEntity; - final ItemStack heldItem = player.getHeldItem(hand); - if (!world.isRemote()) { + final ItemStack heldItem = player.getItemInHand(hand); + if (!world.isClientSide) { if (Wrenches.isWrench(heldItem)) { if (player instanceof ServerPlayerEntity) { computer.openContainerScreen((ServerPlayerEntity) player); } } else { - if (player.isSneaking()) { + if (player.isShiftKeyDown()) { computer.start(); } else if (player instanceof ServerPlayerEntity) { computer.openTerminalScreen((ServerPlayerEntity) player); @@ -181,13 +181,13 @@ public final class ComputerBlock extends HorizontalBlock { } } - return world.isRemote() ? ActionResultType.SUCCESS : ActionResultType.CONSUME; + return world.isClientSide ? ActionResultType.SUCCESS : ActionResultType.CONSUME; } @Override - public void onBlockHarvested(final World world, final BlockPos pos, final BlockState state, final PlayerEntity player) { - final TileEntity tileEntity = world.getTileEntity(pos); - if (!world.isRemote() && tileEntity instanceof ComputerTileEntity) { + public void playerWillDestroy(final World world, final BlockPos pos, final BlockState state, final PlayerEntity player) { + final TileEntity tileEntity = world.getBlockEntity(pos); + if (!world.isClientSide && tileEntity instanceof ComputerTileEntity) { final ComputerTileEntity computer = (ComputerTileEntity) tileEntity; if (!computer.getItemStackHandlers().isEmpty()) { computer.getItemStackHandlers().exportDeviceDataToItemStacks(); @@ -195,25 +195,25 @@ public final class ComputerBlock extends HorizontalBlock { if (player.isCreative()) { final ItemStack stack = new ItemStack(Items.COMPUTER.get()); computer.exportToItemStack(stack); - spawnAsEntity(world, pos, stack); + popResource(world, pos, stack); } } } - super.onBlockHarvested(world, pos, state, player); + super.playerWillDestroy(world, pos, state, player); } @Override public BlockState getStateForPlacement(final BlockItemUseContext context) { - return super.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); + return super.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()); } /////////////////////////////////////////////////////////////////// @Override - protected void fillStateContainer(final StateContainer.Builder builder) { - super.fillStateContainer(builder); - builder.add(HORIZONTAL_FACING); + protected void createBlockStateDefinition(final StateContainer.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING); } /////////////////////////////////////////////////////////////////// diff --git a/src/main/java/li/cil/oc2/common/block/CreativeEnergyBlock.java b/src/main/java/li/cil/oc2/common/block/CreativeEnergyBlock.java index b6000f40..f87e43d7 100644 --- a/src/main/java/li/cil/oc2/common/block/CreativeEnergyBlock.java +++ b/src/main/java/li/cil/oc2/common/block/CreativeEnergyBlock.java @@ -11,9 +11,9 @@ import net.minecraft.world.IBlockReader; public final class CreativeEnergyBlock extends Block { public CreativeEnergyBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(-1, 3600000) + .strength(-1, 3600000) .noDrops()); } diff --git a/src/main/java/li/cil/oc2/common/block/DiskDriveBlock.java b/src/main/java/li/cil/oc2/common/block/DiskDriveBlock.java index 574f2c6f..97d2df32 100644 --- a/src/main/java/li/cil/oc2/common/block/DiskDriveBlock.java +++ b/src/main/java/li/cil/oc2/common/block/DiskDriveBlock.java @@ -23,17 +23,17 @@ import net.minecraft.world.World; public final class DiskDriveBlock extends HorizontalBlock { public DiskDriveBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(1.5f, 6.0f)); - setDefaultState(getStateContainer().getBaseState().with(HORIZONTAL_FACING, Direction.NORTH)); + .strength(1.5f, 6.0f)); + registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH)); } /////////////////////////////////////////////////////////////////// @Override public BlockState getStateForPlacement(final BlockItemUseContext context) { - return super.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); + return super.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()); } @Override @@ -48,23 +48,23 @@ public final class DiskDriveBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override - public ActionResultType onBlockActivated(final BlockState state, final World world, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult hit) { - final TileEntity tileEntity = world.getTileEntity(pos); + public ActionResultType use(final BlockState state, final World world, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult hit) { + final TileEntity tileEntity = world.getBlockEntity(pos); if (!(tileEntity instanceof DiskDriveTileEntity)) { - return super.onBlockActivated(state, world, pos, player, hand, hit); + return super.use(state, world, pos, player, hand, hit); } - if (world.isRemote()) { + if (world.isClientSide) { return ActionResultType.SUCCESS; } final DiskDriveTileEntity diskDrive = (DiskDriveTileEntity) tileEntity; - final ItemStack stack = player.getHeldItem(hand); + final ItemStack stack = player.getItemInHand(hand); - if (player.isSneaking()) { + if (player.isShiftKeyDown()) { diskDrive.eject(); } else { - player.setHeldItem(hand, diskDrive.insert(stack)); + player.setItemInHand(hand, diskDrive.insert(stack)); } return ActionResultType.CONSUME; @@ -73,8 +73,8 @@ public final class DiskDriveBlock extends HorizontalBlock { /////////////////////////////////////////////////////////////////// @Override - protected void fillStateContainer(final StateContainer.Builder builder) { - super.fillStateContainer(builder); - builder.add(HORIZONTAL_FACING); + protected void createBlockStateDefinition(final StateContainer.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING); } } diff --git a/src/main/java/li/cil/oc2/common/block/NetworkConnectorBlock.java b/src/main/java/li/cil/oc2/common/block/NetworkConnectorBlock.java index 4f3913b5..ad22a98d 100644 --- a/src/main/java/li/cil/oc2/common/block/NetworkConnectorBlock.java +++ b/src/main/java/li/cil/oc2/common/block/NetworkConnectorBlock.java @@ -20,29 +20,29 @@ import net.minecraft.world.World; import java.util.Objects; public final class NetworkConnectorBlock extends HorizontalFaceBlock { - private static final VoxelShape NEG_Z_SHAPE = Block.makeCuboidShape(5, 5, 7, 11, 11, 16); - private static final VoxelShape POS_Z_SHAPE = Block.makeCuboidShape(5, 5, 0, 11, 11, 9); - private static final VoxelShape NEG_X_SHAPE = Block.makeCuboidShape(7, 5, 5, 16, 11, 11); - private static final VoxelShape POS_X_SHAPE = Block.makeCuboidShape(0, 5, 5, 9, 11, 11); - private static final VoxelShape NEG_Y_SHAPE = Block.makeCuboidShape(5, 0, 5, 11, 9, 11); - private static final VoxelShape POS_Y_SHAPE = Block.makeCuboidShape(5, 7, 5, 11, 16, 11); + private static final VoxelShape NEG_Z_SHAPE = Block.box(5, 5, 7, 11, 11, 16); + private static final VoxelShape POS_Z_SHAPE = Block.box(5, 5, 0, 11, 11, 9); + private static final VoxelShape NEG_X_SHAPE = Block.box(7, 5, 5, 16, 11, 11); + private static final VoxelShape POS_X_SHAPE = Block.box(0, 5, 5, 9, 11, 11); + private static final VoxelShape NEG_Y_SHAPE = Block.box(5, 0, 5, 11, 9, 11); + private static final VoxelShape POS_Y_SHAPE = Block.box(5, 7, 5, 11, 16, 11); /////////////////////////////////////////////////////////////////// public NetworkConnectorBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(1.5f, 6.0f)); - setDefaultState(getStateContainer().getBaseState() - .with(HORIZONTAL_FACING, Direction.NORTH) - .with(FACE, AttachFace.WALL)); + .strength(1.5f, 6.0f)); + registerDefaultState(getStateDefinition().any() + .setValue(FACING, Direction.NORTH) + .setValue(FACE, AttachFace.WALL)); } /////////////////////////////////////////////////////////////////// public static Direction getFacing(final BlockState state) { - return HorizontalFaceBlock.getFacing(state); + return HorizontalFaceBlock.getConnectedDirection(state); } @Override @@ -58,8 +58,8 @@ public final class NetworkConnectorBlock extends HorizontalFaceBlock { @SuppressWarnings("deprecation") @Override public void neighborChanged(final BlockState state, final World world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) { - if (Objects.equals(changedBlockPos, pos.offset(getFacing(state).getOpposite()))) { - final TileEntity tileEntity = world.getTileEntity(pos); + if (Objects.equals(changedBlockPos, pos.relative(getFacing(state).getOpposite()))) { + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity instanceof NetworkConnectorTileEntity) { final NetworkConnectorTileEntity connector = (NetworkConnectorTileEntity) tileEntity; connector.setLocalInterfaceChanged(); @@ -70,9 +70,9 @@ public final class NetworkConnectorBlock extends HorizontalFaceBlock { @SuppressWarnings("deprecation") @Override public VoxelShape getShape(final BlockState state, final IBlockReader world, final BlockPos pos, final ISelectionContext context) { - switch (state.get(FACE)) { + switch (state.getValue(FACE)) { case WALL: - switch (state.get(HORIZONTAL_FACING)) { + switch (state.getValue(FACING)) { case EAST: return POS_X_SHAPE; case WEST: @@ -93,7 +93,7 @@ public final class NetworkConnectorBlock extends HorizontalFaceBlock { /////////////////////////////////////////////////////////////////// - protected void fillStateContainer(final StateContainer.Builder builder) { - builder.add(FACE, HORIZONTAL_FACING); + protected void createBlockStateDefinition(final StateContainer.Builder builder) { + builder.add(FACE, FACING); } } diff --git a/src/main/java/li/cil/oc2/common/block/NetworkHubBlock.java b/src/main/java/li/cil/oc2/common/block/NetworkHubBlock.java index 117effe0..125df074 100644 --- a/src/main/java/li/cil/oc2/common/block/NetworkHubBlock.java +++ b/src/main/java/li/cil/oc2/common/block/NetworkHubBlock.java @@ -18,17 +18,17 @@ import net.minecraft.world.World; public final class NetworkHubBlock extends HorizontalBlock { public NetworkHubBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(1.5f, 6.0f)); - setDefaultState(getStateContainer().getBaseState().with(HORIZONTAL_FACING, Direction.NORTH)); + .strength(1.5f, 6.0f)); + registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH)); } /////////////////////////////////////////////////////////////////// @Override public BlockState getStateForPlacement(final BlockItemUseContext context) { - return super.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); + return super.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()); } @Override @@ -44,7 +44,7 @@ public final class NetworkHubBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override public void neighborChanged(final BlockState state, final World world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) { - final TileEntity tileEntity = world.getTileEntity(pos); + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity instanceof NetworkHubTileEntity) { final NetworkHubTileEntity hub = (NetworkHubTileEntity) tileEntity; hub.handleNeighborChanged(); @@ -54,8 +54,8 @@ public final class NetworkHubBlock extends HorizontalBlock { /////////////////////////////////////////////////////////////////// @Override - protected void fillStateContainer(final StateContainer.Builder builder) { - super.fillStateContainer(builder); - builder.add(HORIZONTAL_FACING); + protected void createBlockStateDefinition(final StateContainer.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING); } } diff --git a/src/main/java/li/cil/oc2/common/block/RedstoneInterfaceBlock.java b/src/main/java/li/cil/oc2/common/block/RedstoneInterfaceBlock.java index 21a3e5d7..cb80c695 100644 --- a/src/main/java/li/cil/oc2/common/block/RedstoneInterfaceBlock.java +++ b/src/main/java/li/cil/oc2/common/block/RedstoneInterfaceBlock.java @@ -18,17 +18,17 @@ import net.minecraft.world.IWorldReader; public final class RedstoneInterfaceBlock extends HorizontalBlock { public RedstoneInterfaceBlock() { super(Properties - .create(Material.IRON) + .of(Material.METAL) .sound(SoundType.METAL) - .hardnessAndResistance(1.5f, 6.0f)); - setDefaultState(getStateContainer().getBaseState().with(HORIZONTAL_FACING, Direction.NORTH)); + .strength(1.5f, 6.0f)); + registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH)); } /////////////////////////////////////////////////////////////////// @Override public BlockState getStateForPlacement(final BlockItemUseContext context) { - return super.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); + return super.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite()); } @Override @@ -43,14 +43,14 @@ public final class RedstoneInterfaceBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override - public boolean canProvidePower(final BlockState state) { + public boolean isSignalSource(final BlockState state) { return true; } @SuppressWarnings("deprecation") @Override - public int getWeakPower(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { - final TileEntity tileEntity = world.getTileEntity(pos); + public int getSignal(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity instanceof RedstoneInterfaceTileEntity) { final RedstoneInterfaceTileEntity redstoneInterface = (RedstoneInterfaceTileEntity) tileEntity; // Redstone requests info for faces with external perspective. We treat @@ -58,7 +58,7 @@ public final class RedstoneInterfaceBlock extends HorizontalBlock { return redstoneInterface.getOutputForDirection(side.getOpposite()); } - return super.getWeakPower(state, world, pos, side); + return super.getSignal(state, world, pos, side); } @Override @@ -68,15 +68,15 @@ public final class RedstoneInterfaceBlock extends HorizontalBlock { @SuppressWarnings("deprecation") @Override - public int getStrongPower(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { - return getWeakPower(state, world, pos, side); + public int getDirectSignal(final BlockState state, final IBlockReader world, final BlockPos pos, final Direction side) { + return getSignal(state, world, pos, side); } /////////////////////////////////////////////////////////////////// @Override - protected void fillStateContainer(final StateContainer.Builder builder) { - super.fillStateContainer(builder); - builder.add(HORIZONTAL_FACING); + protected void createBlockStateDefinition(final StateContainer.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(FACING); } } diff --git a/src/main/java/li/cil/oc2/common/bus/AbstractGroupingDeviceBusElement.java b/src/main/java/li/cil/oc2/common/bus/AbstractGroupingDeviceBusElement.java index 89ba55b9..5f6ee021 100644 --- a/src/main/java/li/cil/oc2/common/bus/AbstractGroupingDeviceBusElement.java +++ b/src/main/java/li/cil/oc2/common/bus/AbstractGroupingDeviceBusElement.java @@ -54,7 +54,7 @@ public abstract class AbstractGroupingDeviceBusElement removedChunks = new HashSet<>(trackedChunks); removedChunks.removeAll(newTrackedChunks); diff --git a/src/main/java/li/cil/oc2/common/bus/TileEntityDeviceBusElement.java b/src/main/java/li/cil/oc2/common/bus/TileEntityDeviceBusElement.java index 28c26da5..f228476a 100644 --- a/src/main/java/li/cil/oc2/common/bus/TileEntityDeviceBusElement.java +++ b/src/main/java/li/cil/oc2/common/bus/TileEntityDeviceBusElement.java @@ -40,19 +40,19 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl /////////////////////////////////////////////////////////////////// @Override - public IWorld getWorld() { - return tileEntity.getWorld(); + public IWorld getLevel() { + return tileEntity.getLevel(); } @Override public BlockPos getPosition() { - return tileEntity.getPos(); + return tileEntity.getBlockPos(); } @Override public Optional>> getNeighbors() { - final World world = tileEntity.getWorld(); - if (world == null || world.isRemote()) { + final World world = tileEntity.getLevel(); + if (world == null || world.isClientSide) { return Optional.empty(); } @@ -62,14 +62,14 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl continue; } - final BlockPos neighborPos = tileEntity.getPos().offset(neighborDirection); + final BlockPos neighborPos = tileEntity.getBlockPos().relative(neighborDirection); final ChunkPos chunkPos = new ChunkPos(neighborPos); - if (!world.chunkExists(chunkPos.x, chunkPos.z)) { + if (!world.hasChunk(chunkPos.x, chunkPos.z)) { return Optional.empty(); } - final TileEntity tileEntity = world.getTileEntity(neighborPos); + final TileEntity tileEntity = world.getBlockEntity(neighborPos); if (tileEntity == null) { continue; } @@ -84,18 +84,18 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl } public void handleNeighborChanged(final BlockPos pos) { - final World world = tileEntity.getWorld(); - if (world == null || world.isRemote()) { + final World world = tileEntity.getLevel(); + if (world == null || world.isClientSide) { return; } - final BlockPos toPos = pos.subtract(tileEntity.getPos()); - final Direction direction = Direction.byLong(toPos.getX(), toPos.getY(), toPos.getZ()); + final BlockPos toPos = pos.subtract(tileEntity.getBlockPos()); + final Direction direction = Direction.fromNormal(toPos.getX(), toPos.getY(), toPos.getZ()); if (direction == null) { return; } - final int index = direction.getIndex(); + final int index = direction.get3DDataValue(); final HashSet newDevices = new HashSet<>(); if (canDetectDevicesTowards(direction)) { @@ -112,7 +112,7 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl } public void initialize() { - final World world = requireNonNull(tileEntity.getWorld()); + final World world = requireNonNull(tileEntity.getLevel()); ServerScheduler.schedule(world, () -> { if (tileEntity.isRemoved()) { return; @@ -144,16 +144,16 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl private void scanNeighborsForDevices() { for (final Direction direction : Constants.DIRECTIONS) { - handleNeighborChanged(tileEntity.getPos().offset(direction)); + handleNeighborChanged(tileEntity.getBlockPos().relative(direction)); } } private void scheduleBusScanInAdjacentBusElements() { - final World world = requireNonNull(tileEntity.getWorld()); - final BlockPos pos = tileEntity.getPos(); + final World world = requireNonNull(tileEntity.getLevel()); + final BlockPos pos = tileEntity.getBlockPos(); for (final Direction direction : Constants.DIRECTIONS) { - final BlockPos neighborPos = pos.offset(direction); - final TileEntity tileEntity = WorldUtils.getTileEntityIfChunkExists(world, neighborPos); + final BlockPos neighborPos = pos.relative(direction); + final TileEntity tileEntity = WorldUtils.getBlockEntityIfChunkExists(world, neighborPos); if (tileEntity == null) { continue; } diff --git a/src/main/java/li/cil/oc2/common/bus/device/data/FileSystems.java b/src/main/java/li/cil/oc2/common/bus/device/data/FileSystems.java index e9f82de9..b46a27f9 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/data/FileSystems.java +++ b/src/main/java/li/cil/oc2/common/bus/device/data/FileSystems.java @@ -54,7 +54,7 @@ public final class FileSystems { LOGGER.info("Searching for datapack filesystems..."); final Collection fileSystemDescriptorLocations = resourceManager - .getAllResourceLocations("file_systems", s -> s.endsWith(".json")); + .listResources("file_systems", s -> s.endsWith(".json")); final ArrayList fileSystems = new ArrayList<>(); final Object2IntArrayMap fileSystemOrder = new Object2IntArrayMap<>(); @@ -117,7 +117,7 @@ public final class FileSystems { public CompletableFuture reload(final IFutureReloadListener.IStage stage, final IResourceManager resourceManager, final IProfiler preparationsProfiler, final IProfiler reloadProfiler, final Executor backgroundExecutor, final Executor gameExecutor) { return CompletableFuture .runAsync(() -> FileSystems.reload(resourceManager), backgroundExecutor) - .thenCompose(stage::markCompleteAwaitingOthers); + .thenCompose(stage::wait); } } } diff --git a/src/main/java/li/cil/oc2/common/bus/device/item/AbstractBlockDeviceVMDevice.java b/src/main/java/li/cil/oc2/common/bus/device/item/AbstractBlockDeviceVMDevice.java index 2b0d09e5..2130f054 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/item/AbstractBlockDeviceVMDevice.java +++ b/src/main/java/li/cil/oc2/common/bus/device/item/AbstractBlockDeviceVMDevice.java @@ -111,14 +111,14 @@ public abstract class AbstractBlockDeviceVMDevice blobHandle = BlobStorage.validateHandle(blobHandle)); } if (blobHandle != null) { - nbt.putUniqueId(BLOB_HANDLE_TAG_NAME, blobHandle); + nbt.putUUID(BLOB_HANDLE_TAG_NAME, blobHandle); } } @Override public void importFromItemStack(final CompoundNBT nbt) { - if (nbt.hasUniqueId(BLOB_HANDLE_TAG_NAME)) { - blobHandle = nbt.getUniqueId(BLOB_HANDLE_TAG_NAME); + if (nbt.hasUUID(BLOB_HANDLE_TAG_NAME)) { + blobHandle = nbt.getUUID(BLOB_HANDLE_TAG_NAME); } } @@ -141,7 +141,7 @@ public abstract class AbstractBlockDeviceVMDevice @Override public void deserializeNBT(final CompoundNBT tag) { - lastOperation = MathHelper.clamp(tag.getLong(LAST_OPERATION_TAG_NAME), 0, entity.getEntityWorld().getGameTime()); + lastOperation = MathHelper.clamp(tag.getLong(LAST_OPERATION_TAG_NAME), 0, entity.getCommandSenderWorld().getGameTime()); } @Override @@ -97,7 +97,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy beginCooldown(); - final World world = entity.getEntityWorld(); + final World world = entity.getCommandSenderWorld(); if (!(world instanceof ServerWorld)) { return false; } @@ -107,7 +107,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy final List oldItems = getItemsInRange(); - if (!tryHarvestBlock(world, entity.getPosition().offset(getAdjustedDirection(direction)))) { + if (!tryHarvestBlock(world, entity.blockPosition().relative(getAdjustedDirection(direction)))) { return false; } @@ -131,7 +131,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy beginCooldown(); - final World world = entity.getEntityWorld(); + final World world = entity.getCommandSenderWorld(); if (!(world instanceof ServerWorld)) { return false; } @@ -144,10 +144,10 @@ public final class BlockOperationsModuleDevice extends IdentityProxy return false; } - final BlockPos blockPos = entity.getPosition().offset(getAdjustedDirection(direction)); + final BlockPos blockPos = entity.blockPosition().relative(getAdjustedDirection(direction)); final Direction side = getAdjustedDirection(direction).getOpposite(); final BlockRayTraceResult hit = new BlockRayTraceResult( - Vector3d.copyCentered(blockPos).add(Vector3d.copy(side.getDirectionVec()).scale(0.5)), + Vector3d.atCenterOf(blockPos).add(Vector3d.atCenterOf(side.getNormal()).scale(0.5)), side, blockPos, false); @@ -157,8 +157,8 @@ public final class BlockOperationsModuleDevice extends IdentityProxy final ServerPlayerEntity player = FakePlayerUtils.getFakePlayer((ServerWorld) world, entity); final BlockItemUseContext context = new BlockItemUseContext(player, Hand.MAIN_HAND, itemStack, hit); - final ActionResultType result = blockItem.tryPlace(context); - if (!result.isSuccessOrConsume()) { + final ActionResultType result = blockItem.place(context); + if (!result.consumesAction()) { return false; } @@ -171,7 +171,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy @Callback(synchronize = false) public int durability() { - return identity.getMaxDamage() - identity.getDamage(); + return identity.getMaxDamage() - identity.getDamageValue(); } @Callback @@ -182,7 +182,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy beginCooldown(); - if (identity.getDamage() == 0) { + if (identity.getDamageValue() == 0) { return false; } @@ -196,7 +196,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy return false; } - final int repairValue = tier.getMaxUses(); + final int repairValue = tier.getUses(); if (repairValue == 0) { return false; } @@ -206,7 +206,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy return false; } - identity.setDamage(identity.getDamage() - repairValue); + identity.setDamageValue(identity.getDamageValue() - repairValue); return true; } @@ -214,11 +214,11 @@ public final class BlockOperationsModuleDevice extends IdentityProxy /////////////////////////////////////////////////////////////////// private void beginCooldown() { - lastOperation = entity.getEntityWorld().getGameTime(); + lastOperation = entity.getCommandSenderWorld().getGameTime(); } private boolean isOnCooldown() { - return entity.getEntityWorld().getGameTime() - lastOperation < COOLDOWN; + return entity.getCommandSenderWorld().getGameTime() - lastOperation < COOLDOWN; } private Direction getAdjustedDirection(@Nullable final PlacementDirection placementDirection) { @@ -228,16 +228,16 @@ public final class BlockOperationsModuleDevice extends IdentityProxy return Direction.DOWN; } else { Direction direction = Direction.SOUTH; - final int horizontalIndex = entity.getHorizontalFacing().getHorizontalIndex(); + final int horizontalIndex = entity.getDirection().get2DDataValue(); for (int i = 0; i < horizontalIndex; i++) { - direction = direction.rotateY(); + direction = direction.getClockWise(); } return direction; } } private List getItemsInRange() { - return entity.getEntityWorld().getEntitiesWithinAABB(ItemEntity.class, entity.getBoundingBox().grow(2)); + return entity.getCommandSenderWorld().getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(2)); } private boolean tryHarvestBlock(final World world, final BlockPos blockPos) { @@ -253,10 +253,10 @@ public final class BlockOperationsModuleDevice extends IdentityProxy return false; } - final TileEntity tileEntity = world.getTileEntity(blockPos); + final TileEntity tileEntity = world.getBlockEntity(blockPos); final Block block = blockState.getBlock(); final boolean isCommandBlock = block instanceof CommandBlockBlock || block instanceof StructureBlock || block instanceof JigsawBlock; - if (isCommandBlock && !player.canUseCommandBlock()) { + if (isCommandBlock && !player.canUseGameMasterBlocks()) { return false; } @@ -273,7 +273,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy return false; } - if (identity.attemptDamageItem(1, world.rand, null)) { + if (identity.hurt(1, world.random, null)) { return false; } @@ -281,8 +281,8 @@ public final class BlockOperationsModuleDevice extends IdentityProxy return false; } - block.onPlayerDestroy(world, blockPos, blockState); - block.harvestBlock(world, player, blockPos, blockState, tileEntity, ItemStack.EMPTY); + block.destroy(world, blockPos, blockState); + block.playerDestroy(world, player, blockPos, blockState, tileEntity, ItemStack.EMPTY); return true; } diff --git a/src/main/java/li/cil/oc2/common/bus/device/item/InventoryOperationsModuleDevice.java b/src/main/java/li/cil/oc2/common/bus/device/item/InventoryOperationsModuleDevice.java index ced27f8b..6467399c 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/item/InventoryOperationsModuleDevice.java +++ b/src/main/java/li/cil/oc2/common/bus/device/item/InventoryOperationsModuleDevice.java @@ -78,7 +78,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy getItemStackHandlersInDirection(final Direction direction) { - final Vector3i directionVec = direction.getDirectionVec(); - return getItemStackHandlersAt(entity.getPositionVec().add(Vector3d.copy(directionVec)), direction.getOpposite()); + final Vector3i directionVec = direction.getNormal(); + return getItemStackHandlersAt(entity.position().add(Vector3d.atCenterOf(directionVec)), direction.getOpposite()); } private Stream getItemStackHandlersAt(final Vector3d position, final Direction side) { @@ -218,8 +218,8 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy getEntityItemHandlersAt(final Vector3d position, final Direction side) { - final AxisAlignedBB bounds = AxisAlignedBB.fromVector(position.subtract(0.5, 0.5, 0.5)); - return entity.getEntityWorld().getEntitiesWithinAABBExcludingEntity(entity, bounds).stream() + final AxisAlignedBB bounds = AxisAlignedBB.unitCubeFromLowerCorner(position.subtract(0.5, 0.5, 0.5)); + return entity.getCommandSenderWorld().getEntities(entity, bounds).stream() .map(e -> e.getCapability(Capabilities.ITEM_HANDLER, side)) .filter(LazyOptional::isPresent) .map(c -> c.orElseThrow(AssertionError::new)); @@ -227,7 +227,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy getBlockItemHandlersAt(final Vector3d position, final Direction side) { final BlockPos pos = new BlockPos(position); - final TileEntity tileEntity = entity.getEntityWorld().getTileEntity(pos); + final TileEntity tileEntity = entity.getCommandSenderWorld().getBlockEntity(pos); if (tileEntity == null) { return Stream.empty(); } @@ -241,7 +241,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy getItemsInRange() { - return entity.getEntityWorld().getEntitiesWithinAABB(ItemEntity.class, entity.getBoundingBox().grow(1)); + return entity.getCommandSenderWorld().getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(1)); } private int takeFromWorld(final int count) { @@ -298,7 +298,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy implements VMDe if (device != null) { blobHandle = BlobStorage.validateHandle(blobHandle); - tag.putUniqueId(BLOB_HANDLE_TAG_NAME, blobHandle); + tag.putUUID(BLOB_HANDLE_TAG_NAME, blobHandle); jobHandle = BlobStorage.submitSave(blobHandle, new PhysicalMemoryInputStream(device)); } @@ -96,8 +96,8 @@ public final class MemoryDevice extends IdentityProxy implements VMDe @Override public void deserializeNBT(final CompoundNBT tag) { - if (tag.hasUniqueId(BLOB_HANDLE_TAG_NAME)) { - blobHandle = tag.getUniqueId(BLOB_HANDLE_TAG_NAME); + if (tag.hasUUID(BLOB_HANDLE_TAG_NAME)) { + blobHandle = tag.getUUID(BLOB_HANDLE_TAG_NAME); } if (tag.contains(ADDRESS_TAG_NAME, NBTTagIds.TAG_LONG)) { address.set(tag.getLong(ADDRESS_TAG_NAME)); diff --git a/src/main/java/li/cil/oc2/common/bus/device/item/RedstoneInterfaceCardItemDevice.java b/src/main/java/li/cil/oc2/common/bus/device/item/RedstoneInterfaceCardItemDevice.java index 6fd98215..9e4202f0 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/item/RedstoneInterfaceCardItemDevice.java +++ b/src/main/java/li/cil/oc2/common/bus/device/item/RedstoneInterfaceCardItemDevice.java @@ -64,7 +64,7 @@ public final class RedstoneInterfaceCardItemDevice extends IdentityProxy LazyOptional getCapability(@Nonnull final Capability capability, @Nullable final Direction side) { if (capability == Capabilities.REDSTONE_EMITTER && side != null) { - return LazyOptional.of(() -> capabilities[side.getIndex()]).cast(); + return LazyOptional.of(() -> capabilities[side.get3DDataValue()]).cast(); } return LazyOptional.empty(); @@ -95,37 +95,37 @@ public final class RedstoneInterfaceCardItemDevice extends IdentityProxy getDevice(final BlockDeviceQuery query) { - final World world = query.getWorld(); + final World world = query.getLevel(); final BlockPos position = query.getQueryPosition(); final BlockState blockState = world.getBlockState(position); diff --git a/src/main/java/li/cil/oc2/common/bus/device/provider/block/DiskDriveDeviceProvider.java b/src/main/java/li/cil/oc2/common/bus/device/provider/block/DiskDriveDeviceProvider.java index 3c9f26e0..b0fa07c7 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/provider/block/DiskDriveDeviceProvider.java +++ b/src/main/java/li/cil/oc2/common/bus/device/provider/block/DiskDriveDeviceProvider.java @@ -17,7 +17,7 @@ public final class DiskDriveDeviceProvider extends AbstractTileEntityDeviceProvi protected LazyOptional getBlockDevice(final BlockDeviceQuery query, final DiskDriveTileEntity tileEntity) { // We only allow connecting to exactly one face of the disk drive to ensure only one // bus (and thus, one VM) will access the device at any single time. - if (query.getQuerySide() != tileEntity.getBlockState().get(HorizontalBlock.HORIZONTAL_FACING)) { + if (query.getQuerySide() != tileEntity.getBlockState().getValue(HorizontalBlock.FACING)) { return LazyOptional.empty(); } diff --git a/src/main/java/li/cil/oc2/common/bus/device/provider/util/AbstractTileEntityDeviceProvider.java b/src/main/java/li/cil/oc2/common/bus/device/provider/util/AbstractTileEntityDeviceProvider.java index 39d14807..765373ea 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/provider/util/AbstractTileEntityDeviceProvider.java +++ b/src/main/java/li/cil/oc2/common/bus/device/provider/util/AbstractTileEntityDeviceProvider.java @@ -25,7 +25,7 @@ public abstract class AbstractTileEntityDeviceProvider ext @SuppressWarnings("unchecked") @Override public final LazyOptional getDevice(final BlockDeviceQuery query) { - final TileEntity tileEntity = WorldUtils.getTileEntityIfChunkExists(query.getWorld(), query.getQueryPosition()); + final TileEntity tileEntity = WorldUtils.getBlockEntityIfChunkExists(query.getLevel(), query.getQueryPosition()); if (tileEntity == null) { return LazyOptional.empty(); } diff --git a/src/main/java/li/cil/oc2/common/bus/device/util/Devices.java b/src/main/java/li/cil/oc2/common/bus/device/util/Devices.java index f185572d..3b1113ac 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/util/Devices.java +++ b/src/main/java/li/cil/oc2/common/bus/device/util/Devices.java @@ -24,8 +24,8 @@ import static java.util.Objects.requireNonNull; public final class Devices { public static BlockDeviceQuery makeQuery(final TileEntity tileEntity, @Nullable final Direction side) { - final World world = requireNonNull(tileEntity.getWorld()); - final BlockPos pos = tileEntity.getPos(); + final World world = requireNonNull(tileEntity.getLevel()); + final BlockPos pos = tileEntity.getBlockPos(); return new BlockQuery(world, pos, side); } @@ -106,7 +106,7 @@ public final class Devices { } @Override - public World getWorld() { + public World getLevel() { return world; } diff --git a/src/main/java/li/cil/oc2/common/container/AbstractContainer.java b/src/main/java/li/cil/oc2/common/container/AbstractContainer.java index 52adc638..088d507a 100644 --- a/src/main/java/li/cil/oc2/common/container/AbstractContainer.java +++ b/src/main/java/li/cil/oc2/common/container/AbstractContainer.java @@ -21,46 +21,46 @@ public abstract class AbstractContainer extends Container { } @Override - public ItemStack transferStackInSlot(final PlayerEntity player, final int index) { - final Slot from = inventorySlots.get(index); + public ItemStack quickMoveStack(final PlayerEntity player, final int index) { + final Slot from = slots.get(index); if (from == null) { return ItemStack.EMPTY; } - final ItemStack stack = from.getStack().copy(); + final ItemStack stack = from.getItem().copy(); if (stack.isEmpty()) { return ItemStack.EMPTY; } - final boolean intoPlayerInventory = from.inventory != player.inventory; - final ItemStack fromStack = from.getStack(); + final boolean intoPlayerInventory = from.container != player.inventory; + final ItemStack fromStack = from.getItem(); final int step, begin; if (intoPlayerInventory) { step = -1; - begin = inventorySlots.size() - 1; + begin = slots.size() - 1; } else { step = 1; begin = 0; } if (fromStack.getMaxStackSize() > 1) { - for (int i = begin; i >= 0 && i < inventorySlots.size(); i += step) { - final Slot into = inventorySlots.get(i); - if (into.inventory == from.inventory) { + for (int i = begin; i >= 0 && i < slots.size(); i += step) { + final Slot into = slots.get(i); + if (into.container == from.container) { continue; } - final ItemStack intoStack = into.getStack(); + final ItemStack intoStack = into.getItem(); if (intoStack.isEmpty()) { continue; } - final boolean itemsAreEqual = fromStack.isItemEqual(intoStack) && ItemStack.areItemStackTagsEqual(fromStack, intoStack); + final boolean itemsAreEqual = fromStack.sameItem(intoStack) && ItemStack.tagMatches(fromStack, intoStack); if (!itemsAreEqual) { continue; } - final int maxSizeInSlot = Math.min(fromStack.getMaxStackSize(), into.getItemStackLimit(stack)); + final int maxSizeInSlot = Math.min(fromStack.getMaxStackSize(), into.getMaxStackSize(stack)); final int spaceInSlot = maxSizeInSlot - intoStack.getCount(); if (spaceInSlot <= 0) { continue; @@ -71,39 +71,39 @@ public abstract class AbstractContainer extends Container { continue; } - intoStack.grow(from.decrStackSize(itemsMoved).getCount()); - into.onSlotChanged(); + intoStack.grow(from.remove(itemsMoved).getCount()); + into.setChanged(); - if (from.getStack().isEmpty()) { + if (from.getItem().isEmpty()) { break; } } } - for (int i = begin; i >= 0 && i < inventorySlots.size(); i += step) { - if (from.getStack().isEmpty()) { + for (int i = begin; i >= 0 && i < slots.size(); i += step) { + if (from.getItem().isEmpty()) { break; } - final Slot into = inventorySlots.get(i); - if (into.inventory == from.inventory) { + final Slot into = slots.get(i); + if (into.container == from.container) { continue; } - if (into.getHasStack()) { + if (into.hasItem()) { continue; } - if (!into.isItemValid(fromStack)) { + if (!into.mayPlace(fromStack)) { continue; } - final int maxSizeInSlot = Math.min(fromStack.getMaxStackSize(), into.getItemStackLimit(fromStack)); + final int maxSizeInSlot = Math.min(fromStack.getMaxStackSize(), into.getMaxStackSize(fromStack)); final int itemsMoved = Math.min(maxSizeInSlot, fromStack.getCount()); - into.putStack(from.decrStackSize(itemsMoved)); + into.set(from.remove(itemsMoved)); } - return from.getStack().getCount() < stack.getCount() ? from.getStack() : ItemStack.EMPTY; + return from.getItem().getCount() < stack.getCount() ? from.getItem() : ItemStack.EMPTY; } protected int createPlayerInventoryAndHotbarSlots(final PlayerInventory inventory, final int startX, final int startY) { diff --git a/src/main/java/li/cil/oc2/common/container/ComputerInventoryContainer.java b/src/main/java/li/cil/oc2/common/container/ComputerInventoryContainer.java index 0b2e1f02..2bf9e5f1 100644 --- a/src/main/java/li/cil/oc2/common/container/ComputerInventoryContainer.java +++ b/src/main/java/li/cil/oc2/common/container/ComputerInventoryContainer.java @@ -17,7 +17,7 @@ public final class ComputerInventoryContainer extends AbstractContainer { @Nullable public static ComputerInventoryContainer create(final int id, final PlayerInventory playerInventory, final PacketBuffer data) { final BlockPos pos = data.readBlockPos(); - final TileEntity tileEntity = playerInventory.player.getEntityWorld().getTileEntity(pos); + final TileEntity tileEntity = playerInventory.player.getCommandSenderWorld().getBlockEntity(pos); if (!(tileEntity instanceof ComputerTileEntity)) { return null; } @@ -66,7 +66,7 @@ public final class ComputerInventoryContainer extends AbstractContainer { /////////////////////////////////////////////////////////////////// @Override - public boolean canInteractWith(final PlayerEntity player) { - return isWithinUsableDistance(IWorldPosCallable.of(computer.getWorld(), computer.getPos()), player, Blocks.COMPUTER.get()); + public boolean stillValid(final PlayerEntity player) { + return stillValid(IWorldPosCallable.create(computer.getLevel(), computer.getBlockPos()), player, Blocks.COMPUTER.get()); } } diff --git a/src/main/java/li/cil/oc2/common/container/ComputerTerminalContainer.java b/src/main/java/li/cil/oc2/common/container/ComputerTerminalContainer.java index 30e8f551..8ca4958d 100644 --- a/src/main/java/li/cil/oc2/common/container/ComputerTerminalContainer.java +++ b/src/main/java/li/cil/oc2/common/container/ComputerTerminalContainer.java @@ -21,7 +21,7 @@ public final class ComputerTerminalContainer extends AbstractContainer { @Nullable public static ComputerTerminalContainer create(final int id, final PlayerInventory playerInventory, final PacketBuffer data) { final BlockPos pos = data.readBlockPos(); - final TileEntity tileEntity = playerInventory.player.getEntityWorld().getTileEntity(pos); + final TileEntity tileEntity = playerInventory.player.getCommandSenderWorld().getBlockEntity(pos); if (!(tileEntity instanceof ComputerTileEntity)) { return null; } @@ -42,8 +42,8 @@ public final class ComputerTerminalContainer extends AbstractContainer { this.computer.addTerminalUser(player); - assertIntArraySize(energyInfo, ENERGY_INFO_SIZE); - trackIntArray(energyInfo); + checkContainerDataCount(energyInfo, ENERGY_INFO_SIZE); + addDataSlots(energyInfo); } /////////////////////////////////////////////////////////////////// @@ -65,13 +65,13 @@ public final class ComputerTerminalContainer extends AbstractContainer { } @Override - public boolean canInteractWith(final PlayerEntity player) { - return isWithinUsableDistance(IWorldPosCallable.of(computer.getWorld(), computer.getPos()), player, Blocks.COMPUTER.get()); + public boolean stillValid(final PlayerEntity player) { + return stillValid(IWorldPosCallable.create(computer.getLevel(), computer.getBlockPos()), player, Blocks.COMPUTER.get()); } @Override - public void onContainerClosed(final PlayerEntity player) { - super.onContainerClosed(player); + public void removed(final PlayerEntity player) { + super.removed(player); this.computer.removeTerminalUser(player); } diff --git a/src/main/java/li/cil/oc2/common/container/RobotContainer.java b/src/main/java/li/cil/oc2/common/container/RobotContainer.java index ecf5687c..af03f386 100644 --- a/src/main/java/li/cil/oc2/common/container/RobotContainer.java +++ b/src/main/java/li/cil/oc2/common/container/RobotContainer.java @@ -16,7 +16,7 @@ public final class RobotContainer extends AbstractContainer { @Nullable public static RobotContainer create(final int id, final PlayerInventory inventory, final PacketBuffer data) { final int entityId = data.readVarInt(); - final Entity entity = inventory.player.getEntityWorld().getEntityByID(entityId); + final Entity entity = inventory.player.getCommandSenderWorld().getEntity(entityId); if (!(entity instanceof RobotEntity)) { return null; } @@ -76,7 +76,7 @@ public final class RobotContainer extends AbstractContainer { } @Override - public boolean canInteractWith(final PlayerEntity player) { - return robot.isEntityInRange(player, 8); + public boolean stillValid(final PlayerEntity player) { + return robot.closerThan(player, 8); } } diff --git a/src/main/java/li/cil/oc2/common/container/RobotTerminalContainer.java b/src/main/java/li/cil/oc2/common/container/RobotTerminalContainer.java index 99017eed..53346fc4 100644 --- a/src/main/java/li/cil/oc2/common/container/RobotTerminalContainer.java +++ b/src/main/java/li/cil/oc2/common/container/RobotTerminalContainer.java @@ -21,7 +21,7 @@ public final class RobotTerminalContainer extends AbstractContainer { @Nullable public static RobotTerminalContainer create(final int id, final PlayerInventory inventory, final PacketBuffer data) { final int entityId = data.readVarInt(); - final Entity entity = inventory.player.getEntityWorld().getEntityByID(entityId); + final Entity entity = inventory.player.getCommandSenderWorld().getEntity(entityId); if (!(entity instanceof RobotEntity)) { return null; } @@ -40,8 +40,8 @@ public final class RobotTerminalContainer extends AbstractContainer { this.robot = robot; this.energyInfo = energyInfo; - assertIntArraySize(energyInfo, ENERGY_INFO_SIZE); - trackIntArray(energyInfo); + checkContainerDataCount(energyInfo, ENERGY_INFO_SIZE); + addDataSlots(energyInfo); final ItemStackHandler inventory = robot.getInventory(); for (int slot = 0; slot < inventory.getSlots(); slot++) { @@ -69,7 +69,7 @@ public final class RobotTerminalContainer extends AbstractContainer { } @Override - public boolean canInteractWith(final PlayerEntity player) { - return robot.isEntityInRange(player, 8); + public boolean stillValid(final PlayerEntity player) { + return robot.closerThan(player, 8); } } diff --git a/src/main/java/li/cil/oc2/common/container/TypedSlotItemHandler.java b/src/main/java/li/cil/oc2/common/container/TypedSlotItemHandler.java index f9ed4e4f..83332cb4 100644 --- a/src/main/java/li/cil/oc2/common/container/TypedSlotItemHandler.java +++ b/src/main/java/li/cil/oc2/common/container/TypedSlotItemHandler.java @@ -23,11 +23,11 @@ public final class TypedSlotItemHandler extends SlotItemHandler { @Nullable @Override - public Pair getBackground() { - if (getHasStack()) { - return super.getBackground(); + public Pair getNoItemIcon() { + if (hasItem()) { + return super.getNoItemIcon(); } else { - return Pair.of(PlayerContainer.LOCATION_BLOCKS_TEXTURE, deviceType.getBackgroundIcon()); + return Pair.of(PlayerContainer.BLOCK_ATLAS, deviceType.getBackgroundIcon()); } } } diff --git a/src/main/java/li/cil/oc2/common/entity/Entities.java b/src/main/java/li/cil/oc2/common/entity/Entities.java index e5723c8a..ac1e6592 100644 --- a/src/main/java/li/cil/oc2/common/entity/Entities.java +++ b/src/main/java/li/cil/oc2/common/entity/Entities.java @@ -16,7 +16,7 @@ public final class Entities { /////////////////////////////////////////////////////////////////// - public static final RegistryObject> ROBOT = register("robot", RobotEntity::new, EntityClassification.MISC, b -> b.size(14f / 16f, 14f / 16f).immuneToFire().disableSummoning()); + public static final RegistryObject> ROBOT = register("robot", RobotEntity::new, EntityClassification.MISC, b -> b.sized(14f / 16f, 14f / 16f).fireImmune().noSummon()); /////////////////////////////////////////////////////////////////// @@ -27,6 +27,6 @@ public final class Entities { /////////////////////////////////////////////////////////////////// private static RegistryObject> register(final String name, final EntityType.IFactory factory, final EntityClassification classification, final Function, EntityType.Builder> customizer) { - return ENTITIES.register(name, () -> customizer.apply(EntityType.Builder.create(factory, classification)).build(name)); + return ENTITIES.register(name, () -> customizer.apply(EntityType.Builder.of(factory, classification)).build(name)); } } diff --git a/src/main/java/li/cil/oc2/common/entity/RobotEntity.java b/src/main/java/li/cil/oc2/common/entity/RobotEntity.java index dd379fd7..7e773f2f 100644 --- a/src/main/java/li/cil/oc2/common/entity/RobotEntity.java +++ b/src/main/java/li/cil/oc2/common/entity/RobotEntity.java @@ -81,9 +81,9 @@ import java.util.function.Consumer; import static li.cil.oc2.common.Constants.*; public final class RobotEntity extends Entity implements Robot { - public static final DataParameter TARGET_POSITION = EntityDataManager.createKey(RobotEntity.class, DataSerializers.BLOCK_POS); - public static final DataParameter TARGET_DIRECTION = EntityDataManager.createKey(RobotEntity.class, DataSerializers.DIRECTION); - public static final DataParameter SELECTED_SLOT = EntityDataManager.createKey(RobotEntity.class, DataSerializers.BYTE); + public static final DataParameter TARGET_POSITION = EntityDataManager.defineId(RobotEntity.class, DataSerializers.BLOCK_POS); + public static final DataParameter TARGET_DIRECTION = EntityDataManager.defineId(RobotEntity.class, DataSerializers.DIRECTION); + public static final DataParameter SELECTED_SLOT = EntityDataManager.defineId(RobotEntity.class, DataSerializers.BYTE); private static final String TERMINAL_TAG_NAME = "terminal"; private static final String STATE_TAG_NAME = "state"; @@ -121,7 +121,7 @@ public final class RobotEntity extends Entity implements Robot { public RobotEntity(final EntityType type, final World world) { super(type, world); - this.preventEntitySpawning = true; + this.blocksBuilding = true; setNoGravity(true); final CommonDeviceBusController busController = new CommonDeviceBusController(busElement, Config.robotEnergyPerTick); @@ -157,12 +157,12 @@ public final class RobotEntity extends Entity implements Robot { @Override public int getSelectedSlot() { - return getDataManager().get(SELECTED_SLOT); + return getEntityData().get(SELECTED_SLOT); } @Override public void setSelectedSlot(final int value) { - getDataManager().set(SELECTED_SLOT, (byte) MathHelper.clamp(value, 0, INVENTORY_SIZE - 1)); + getEntityData().set(SELECTED_SLOT, (byte) MathHelper.clamp(value, 0, INVENTORY_SIZE - 1)); } @Override @@ -199,8 +199,8 @@ public final class RobotEntity extends Entity implements Robot { } public void start() { - final World world = getEntityWorld(); - if (world == null || world.isRemote()) { + final World world = getCommandSenderWorld(); + if (world.isClientSide) { return; } @@ -208,8 +208,8 @@ public final class RobotEntity extends Entity implements Robot { } public void stop() { - final World world = getEntityWorld(); - if (world == null || world.isRemote()) { + final World world = getCommandSenderWorld(); + if (world.isClientSide) { return; } @@ -223,18 +223,17 @@ public final class RobotEntity extends Entity implements Robot { final ItemStack stack = new ItemStack(Items.ROBOT.get()); exportToItemStack(stack); - entityDropItem(stack); + spawnAtLocation(stack); remove(); - WorldUtils.playSound(world, getPosition(), SoundType.METAL, SoundType::getBreakSound); + WorldUtils.playSound(level, blockPosition(), SoundType.METAL, SoundType::getBreakSound); } @Override public void tick() { - final World world = getEntityWorld(); - final boolean isClient = world.isRemote(); + final boolean isClient = level.isClientSide; - if (firstUpdate) { + if (firstTick) { if (isClient) { requestInitialState(); } else { @@ -254,35 +253,35 @@ public final class RobotEntity extends Entity implements Robot { actionProcessor.tick(); - if (!isClient && world instanceof ServerWorld) { + if (!isClient && level instanceof ServerWorld) { final VoxelShape shape = VoxelShapes.create(getBoundingBox()); final CubeCoordinateIterator iterator = getBlockPosIterator(); - while (iterator.hasNext()) { - final int x = iterator.getX(); - final int y = iterator.getY(); - final int z = iterator.getZ(); - mutablePosition.setPos(x, y, z); - final BlockState blockState = world.getBlockState(mutablePosition); - if (blockState.isAir(world, mutablePosition) || - blockState.isIn(Blocks.MOVING_PISTON) || - blockState.isIn(Blocks.PISTON_HEAD)) { + while (iterator.advance()) { + final int x = iterator.nextX(); + final int y = iterator.nextY(); + final int z = iterator.nextZ(); + mutablePosition.set(x, y, z); + final BlockState blockState = level.getBlockState(mutablePosition); + if (blockState.isAir(level, mutablePosition) || + blockState.is(Blocks.MOVING_PISTON) || + blockState.is(Blocks.PISTON_HEAD)) { continue; } - final VoxelShape blockShape = blockState.getCollisionShape(world, mutablePosition); - if (VoxelShapes.compare(shape, blockShape.withOffset(x, y, z), IBooleanFunction.AND)) { - final TileEntity tileEntity = blockState.hasTileEntity() ? world.getTileEntity(mutablePosition) : null; - final LootContext.Builder builder = new LootContext.Builder((ServerWorld) world) - .withRandom(world.rand) + final VoxelShape blockShape = blockState.getCollisionShape(level, mutablePosition); + if (VoxelShapes.joinIsNotEmpty(shape, blockShape.move(x, y, z), IBooleanFunction.AND)) { + final TileEntity tileEntity = blockState.hasTileEntity() ? level.getBlockEntity(mutablePosition) : null; + final LootContext.Builder builder = new LootContext.Builder((ServerWorld) level) + .withRandom(level.random) .withParameter(LootParameters.THIS_ENTITY, this) - .withParameter(LootParameters.field_237457_g_, getPositionVec()) + .withParameter(LootParameters.ORIGIN, position()) .withParameter(LootParameters.TOOL, ItemStack.EMPTY) .withParameter(LootParameters.BLOCK_STATE, blockState) - .withNullableParameter(LootParameters.BLOCK_ENTITY, tileEntity); + .withOptionalParameter(LootParameters.BLOCK_ENTITY, tileEntity); final List drops = blockState.getDrops(builder); - world.setBlockState(mutablePosition, Blocks.AIR.getDefaultState()); + level.setBlockAndUpdate(mutablePosition, Blocks.AIR.defaultBlockState()); for (final ItemStack drop : drops) { - Block.spawnAsEntity(world, mutablePosition, drop); + Block.popResource(level, mutablePosition, drop); } } } @@ -290,17 +289,17 @@ public final class RobotEntity extends Entity implements Robot { } @Override - public ActionResultType processInitialInteract(final PlayerEntity player, final Hand hand) { - final ItemStack stack = player.getHeldItem(hand); - if (!world.isRemote()) { + public ActionResultType interact(final PlayerEntity player, final Hand hand) { + final ItemStack stack = player.getItemInHand(hand); + if (!level.isClientSide) { if (Wrenches.isWrench(stack)) { - if (player.isSneaking()) { + if (player.isShiftKeyDown()) { dropSelf(); } else if (player instanceof ServerPlayerEntity) { openContainerScreen((ServerPlayerEntity) player); } } else { - if (player.isSneaking()) { + if (player.isShiftKeyDown()) { start(); } else if (player instanceof ServerPlayerEntity) { openTerminalScreen((ServerPlayerEntity) player); @@ -312,7 +311,7 @@ public final class RobotEntity extends Entity implements Robot { } @Override - public IPacket createSpawnPacket() { + public IPacket getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } @@ -326,27 +325,27 @@ public final class RobotEntity extends Entity implements Robot { virtualMachine.state.vmAdapter.unload(); } + @Override + public boolean isPickable() { + return true; + } + + @Override + public boolean canCollideWith(final Entity entity) { + return entity != this; + } + + @Override + public void push(final Entity entity) { + } + @Override public boolean canBeCollidedWith() { return true; } @Override - public boolean canCollide(final Entity entity) { - return entity != this; - } - - @Override - public void applyEntityCollision(final Entity entity) { - } - - @Override - public boolean func_241845_aY() { - return true; - } - - @Override - public boolean shouldSpawnRunningEffects() { + public boolean canSpawnSprintParticle() { return false; } @@ -370,15 +369,15 @@ public final class RobotEntity extends Entity implements Robot { /////////////////////////////////////////////////////////////////// @Override - protected void registerData() { - final EntityDataManager dataManager = getDataManager(); - dataManager.register(TARGET_POSITION, BlockPos.ZERO); - dataManager.register(TARGET_DIRECTION, Direction.NORTH); - dataManager.register(SELECTED_SLOT, (byte) 0); + protected void defineSynchedData() { + final EntityDataManager dataManager = getEntityData(); + dataManager.define(TARGET_POSITION, BlockPos.ZERO); + dataManager.define(TARGET_DIRECTION, Direction.NORTH); + dataManager.define(SELECTED_SLOT, (byte) 0); } @Override - protected void writeAdditional(final CompoundNBT tag) { + protected void addAdditionalSaveData(final CompoundNBT tag) { tag.put(STATE_TAG_NAME, virtualMachine.serialize()); tag.put(TERMINAL_TAG_NAME, NBTSerialization.serialize(terminal)); tag.put(COMMAND_PROCESSOR_TAG_NAME, actionProcessor.serialize()); @@ -386,11 +385,11 @@ public final class RobotEntity extends Entity implements Robot { tag.put(Constants.ITEMS_TAG_NAME, deviceItems.serialize()); tag.put(ENERGY_TAG_NAME, energy.serializeNBT()); tag.put(INVENTORY_TAG_NAME, inventory.serializeNBT()); - tag.putByte(SELECTED_SLOT_TAG_NAME, dataManager.get(SELECTED_SLOT)); + tag.putByte(SELECTED_SLOT_TAG_NAME, getEntityData().get(SELECTED_SLOT)); } @Override - protected void readAdditional(final CompoundNBT tag) { + protected void readAdditionalSaveData(final CompoundNBT tag) { virtualMachine.deserialize(tag.getCompound(STATE_TAG_NAME)); NBTSerialization.deserialize(tag.getCompound(TERMINAL_TAG_NAME), terminal); actionProcessor.deserialize(tag.getCompound(COMMAND_PROCESSOR_TAG_NAME)); @@ -402,18 +401,19 @@ public final class RobotEntity extends Entity implements Robot { } @Override - protected boolean canTriggerWalking() { + protected boolean isMovementNoisy() { return false; } @Override - protected void doBlockCollisions() { + protected void checkInsideBlocks() { } + @Override - protected Vector3d handlePistonMovement(final Vector3d pos) { - lastPistonMovement = getEntityWorld().getGameTime(); - return super.handlePistonMovement(pos); + protected Vector3d limitPistonMovement(final Vector3d pos) { + lastPistonMovement = getCommandSenderWorld().getGameTime(); + return super.limitPistonMovement(pos); } /////////////////////////////////////////////////////////////////// @@ -434,11 +434,11 @@ public final class RobotEntity extends Entity implements Robot { } private void handleChunkUnload(final ChunkEvent.Unload event) { - if (event.getWorld() != getEntityWorld()) { + if (event.getWorld() != getCommandSenderWorld()) { return; } - final ChunkPos chunkPos = new ChunkPos(getPosition()); + final ChunkPos chunkPos = new ChunkPos(blockPosition()); if (!Objects.equals(chunkPos, event.getChunk().getPos())) { return; } @@ -448,7 +448,7 @@ public final class RobotEntity extends Entity implements Robot { } private void handleWorldUnload(final WorldEvent.Unload event) { - if (event.getWorld() != getEntityWorld()) { + if (event.getWorld() != getCommandSenderWorld()) { return; } @@ -489,12 +489,12 @@ public final class RobotEntity extends Entity implements Robot { } @Override - public int size() { + public int getCount() { return 3; } }); } - }, b -> b.writeVarInt(getEntityId())); + }, b -> b.writeVarInt(getId())); } private void openContainerScreen(final ServerPlayerEntity player) { @@ -508,7 +508,7 @@ public final class RobotEntity extends Entity implements Robot { public Container createMenu(final int id, final PlayerInventory inventory, final PlayerEntity player) { return new RobotContainer(id, RobotEntity.this, inventory); } - }, b -> b.writeVarInt(getEntityId())); + }, b -> b.writeVarInt(getId())); } private CubeCoordinateIterator getBlockPosIterator() { @@ -639,7 +639,7 @@ public final class RobotEntity extends Entity implements Robot { } public void tick() { - if (getEntityWorld().isRemote()) { + if (getCommandSenderWorld().isClientSide) { RobotActions.performClient(RobotEntity.this); } else { if (action != null) { @@ -722,7 +722,7 @@ public final class RobotEntity extends Entity implements Robot { } private boolean addAction(final AbstractRobotAction action) { - if (getEntityWorld().isRemote()) { + if (getCommandSenderWorld().isClientSide) { return false; } @@ -785,13 +785,13 @@ public final class RobotEntity extends Entity implements Robot { public CompoundNBT serialize() { final CompoundNBT tag = new CompoundNBT(); - tag.putUniqueId(DEVICE_ID_TAG_NAME, deviceId); + tag.putUUID(DEVICE_ID_TAG_NAME, deviceId); return tag; } public void deserialize(final CompoundNBT tag) { - if (tag.hasUniqueId(DEVICE_ID_TAG_NAME)) { - deviceId = tag.getUniqueId(DEVICE_ID_TAG_NAME); + if (tag.hasUUID(DEVICE_ID_TAG_NAME)) { + deviceId = tag.getUUID(DEVICE_ID_TAG_NAME); } } } diff --git a/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementAction.java b/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementAction.java index 852c2cdd..535dd011 100644 --- a/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementAction.java +++ b/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementAction.java @@ -50,12 +50,12 @@ public final class RobotMovementAction extends AbstractRobotAction { /////////////////////////////////////////////////////////////////// public static Vector3d getTargetPositionInBlock(final BlockPos position) { - return Vector3d.copyCenteredHorizontally(position).add(0, 0.5f * (1 - Entities.ROBOT.get().getHeight()), 0); + return Vector3d.atBottomCenterOf(position).add(0, 0.5f * (1 - Entities.ROBOT.get().getHeight()), 0); } public static void moveTowards(final RobotEntity robot, final Vector3d targetPosition) { - Vector3d delta = targetPosition.subtract(robot.getPositionVec()); - if (delta.lengthSquared() > MOVEMENT_SPEED * MOVEMENT_SPEED) { + Vector3d delta = targetPosition.subtract(robot.position()); + if (delta.lengthSqr() > MOVEMENT_SPEED * MOVEMENT_SPEED) { delta = delta.normalize().scale(MOVEMENT_SPEED); } @@ -67,27 +67,27 @@ public final class RobotMovementAction extends AbstractRobotAction { @Override public void initialize(final RobotEntity robot) { if (origin == null || start == null || target == null) { - origin = robot.getPosition(); + origin = robot.blockPosition(); start = origin; target = start; switch (direction) { case UP: - target = target.offset(Direction.UP); + target = target.relative(Direction.UP); break; case DOWN: - target = target.offset(Direction.DOWN); + target = target.relative(Direction.DOWN); break; case FORWARD: - target = target.offset(robot.getHorizontalFacing()); + target = target.relative(robot.getDirection()); break; case BACKWARD: - target = target.offset(robot.getHorizontalFacing().getOpposite()); + target = target.relative(robot.getDirection().getOpposite()); break; } } targetPos = getTargetPositionInBlock(target); - robot.getDataManager().set(RobotEntity.TARGET_POSITION, target); + robot.getEntityData().set(RobotEntity.TARGET_POSITION, target); } @Override @@ -100,7 +100,7 @@ public final class RobotMovementAction extends AbstractRobotAction { moveAndResolveCollisions(robot); - if (robot.getPositionVec().squareDistanceTo(targetPos) < TARGET_EPSILON) { + if (robot.position().distanceToSqr(targetPos) < TARGET_EPSILON) { if (Objects.equals(target, origin)) { return RobotActionResult.FAILURE; // Collided and returned. } else { @@ -149,20 +149,20 @@ public final class RobotMovementAction extends AbstractRobotAction { private void moveAndResolveCollisions(final RobotEntity robot) { moveTowards(robot, targetPos); - final boolean didCollide = robot.collidedHorizontally || robot.collidedVertically; - final long gameTime = robot.getEntityWorld().getGameTime(); - if (didCollide && !robot.getEntityWorld().isRemote() + final boolean didCollide = robot.horizontalCollision || robot.verticalCollision; + final long gameTime = robot.level.getGameTime(); + if (didCollide && !robot.level.isClientSide && robot.getLastPistonMovement() < gameTime - 1) { final BlockPos newStart = target; target = start; start = newStart; targetPos = getTargetPositionInBlock(target); - robot.getDataManager().set(RobotEntity.TARGET_POSITION, target); + robot.getEntityData().set(RobotEntity.TARGET_POSITION, target); } } private void validateTarget(final RobotEntity robot) { - final BlockPos currentPosition = robot.getPosition(); + final BlockPos currentPosition = robot.blockPosition(); if (Objects.equals(currentPosition, start) || Objects.equals(currentPosition, target)) { return; } @@ -176,13 +176,13 @@ public final class RobotMovementAction extends AbstractRobotAction { if (deltaStart < deltaTarget) { start = currentPosition; - target = target.add(fromStart); + target = target.offset(fromStart); } else { - start = start.add(fromTarget); + start = start.offset(fromTarget); target = currentPosition; } targetPos = getTargetPositionInBlock(target); - robot.getDataManager().set(RobotEntity.TARGET_POSITION, target); + robot.getEntityData().set(RobotEntity.TARGET_POSITION, target); } } diff --git a/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementActionType.java b/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementActionType.java index a73cdf4f..9668f14e 100644 --- a/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementActionType.java +++ b/src/main/java/li/cil/oc2/common/entity/robot/RobotMovementActionType.java @@ -13,20 +13,20 @@ public final class RobotMovementActionType extends AbstractRobotActionType { @Override public void initializeData(final RobotEntity robot) { - robot.getDataManager().set(RobotEntity.TARGET_POSITION, robot.getPosition()); + robot.getEntityData().set(RobotEntity.TARGET_POSITION, robot.blockPosition()); } @Override public void performServer(final RobotEntity robot, final AbstractRobotAction currentAction) { if (!(currentAction instanceof RobotMovementAction)) { - robot.getDataManager().set(RobotEntity.TARGET_POSITION, robot.getPosition()); + robot.getEntityData().set(RobotEntity.TARGET_POSITION, robot.blockPosition()); } } @Override public void performClient(final RobotEntity robot) { - final Vector3d target = RobotMovementAction.getTargetPositionInBlock(robot.getDataManager().get(RobotEntity.TARGET_POSITION)); - if (robot.getPositionVec().squareDistanceTo(target) > RobotMovementAction.TARGET_EPSILON) { + final Vector3d target = RobotMovementAction.getTargetPositionInBlock(robot.getEntityData().get(RobotEntity.TARGET_POSITION)); + if (robot.position().distanceToSqr(target) > RobotMovementAction.TARGET_EPSILON) { RobotMovementAction.moveTowards(robot, target); } } diff --git a/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationAction.java b/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationAction.java index 217e330e..0f6681a1 100644 --- a/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationAction.java +++ b/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationAction.java @@ -40,7 +40,7 @@ public final class RobotRotationAction extends AbstractRobotAction { /////////////////////////////////////////////////////////////////// public static void rotateTowards(final RobotEntity robot, final Direction targetRotation) { - robot.rotationYaw = MathHelper.approachDegrees(robot.rotationYaw, targetRotation.getHorizontalAngle(), ROTATION_SPEED); + robot.yRot = MathHelper.approachDegrees(robot.yRot, targetRotation.toYRot(), ROTATION_SPEED); } /////////////////////////////////////////////////////////////////// @@ -48,18 +48,18 @@ public final class RobotRotationAction extends AbstractRobotAction { @Override public void initialize(final RobotEntity robot) { if (target == null) { - target = robot.getHorizontalFacing(); + target = robot.getDirection(); switch (direction) { case LEFT: - target = target.rotateYCCW(); + target = target.getCounterClockWise(); break; case RIGHT: - target = target.rotateY(); + target = target.getClockWise(); break; } } - robot.getDataManager().set(RobotEntity.TARGET_DIRECTION, target); + robot.getEntityData().set(RobotEntity.TARGET_DIRECTION, target); } @Override @@ -70,7 +70,7 @@ public final class RobotRotationAction extends AbstractRobotAction { rotateTowards(robot, target); - if (MathHelper.degreesDifferenceAbs(robot.rotationYaw, target.getHorizontalAngle()) < TARGET_EPSILON) { + if (MathHelper.degreesDifferenceAbs(robot.yRot, target.toYRot()) < TARGET_EPSILON) { return RobotActionResult.SUCCESS; } diff --git a/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationActionType.java b/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationActionType.java index 5fe2fad9..56ab7b4d 100644 --- a/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationActionType.java +++ b/src/main/java/li/cil/oc2/common/entity/robot/RobotRotationActionType.java @@ -14,20 +14,20 @@ public final class RobotRotationActionType extends AbstractRobotActionType { @Override public void initializeData(final RobotEntity robot) { - robot.getDataManager().set(RobotEntity.TARGET_DIRECTION, robot.getHorizontalFacing()); + robot.getEntityData().set(RobotEntity.TARGET_DIRECTION, robot.getDirection()); } @Override public void performServer(final RobotEntity robot, final AbstractRobotAction currentAction) { if (!(currentAction instanceof RobotRotationAction)) { - robot.getDataManager().set(RobotEntity.TARGET_DIRECTION, robot.getHorizontalFacing()); + robot.getEntityData().set(RobotEntity.TARGET_DIRECTION, robot.getDirection()); } } @Override public void performClient(final RobotEntity robot) { - final Direction target = robot.getDataManager().get(RobotEntity.TARGET_DIRECTION); - if (MathHelper.degreesDifferenceAbs(robot.rotationYaw, target.getHorizontalAngle()) > RobotRotationAction.TARGET_EPSILON) { + final Direction target = robot.getEntityData().get(RobotEntity.TARGET_DIRECTION); + if (MathHelper.degreesDifferenceAbs(robot.yRot, target.toYRot()) > RobotRotationAction.TARGET_EPSILON) { RobotRotationAction.rotateTowards(robot, target); } } diff --git a/src/main/java/li/cil/oc2/common/integration/Wrenches.java b/src/main/java/li/cil/oc2/common/integration/Wrenches.java index f1ace486..61e79b66 100644 --- a/src/main/java/li/cil/oc2/common/integration/Wrenches.java +++ b/src/main/java/li/cil/oc2/common/integration/Wrenches.java @@ -13,11 +13,11 @@ public final class Wrenches { } public static boolean isWrench(final Item item) { - return item.isIn(ItemTags.WRENCHES); + return item.is(ItemTags.WRENCHES); } public static boolean isHoldingWrench(final Entity entity) { - for (final ItemStack stack : entity.getHeldEquipment()) { + for (final ItemStack stack : entity.getHandSlots()) { if (isWrench(stack.getItem())) { return true; } diff --git a/src/main/java/li/cil/oc2/common/item/AbstractBlockDeviceItem.java b/src/main/java/li/cil/oc2/common/item/AbstractBlockDeviceItem.java index 300985f2..8c550820 100644 --- a/src/main/java/li/cil/oc2/common/item/AbstractBlockDeviceItem.java +++ b/src/main/java/li/cil/oc2/common/item/AbstractBlockDeviceItem.java @@ -22,7 +22,7 @@ public abstract class AbstractBlockDeviceItem extends ModItem { /////////////////////////////////////////////////////////////////// protected AbstractBlockDeviceItem(final Properties properties, final ResourceLocation defaultData) { - super(properties.maxStackSize(1)); + super(properties.stacksTo(1)); this.defaultData = defaultData; } @@ -71,16 +71,16 @@ public abstract class AbstractBlockDeviceItem extends ModItem { } @Override - public ITextComponent getDisplayName(final ItemStack stack) { + public ITextComponent getName(final ItemStack stack) { final BlockDeviceData data = getData(stack); if (data != null) { return new StringTextComponent("") - .append(super.getDisplayName(stack)) - .appendString(" (") + .append(super.getName(stack)) + .append(" (") .append(data.getDisplayName()) - .appendString(")"); + .append(")"); } else { - return super.getDisplayName(stack); + return super.getName(stack); } } } diff --git a/src/main/java/li/cil/oc2/common/item/AbstractStorageItem.java b/src/main/java/li/cil/oc2/common/item/AbstractStorageItem.java index 7e15da6b..74387bf3 100644 --- a/src/main/java/li/cil/oc2/common/item/AbstractStorageItem.java +++ b/src/main/java/li/cil/oc2/common/item/AbstractStorageItem.java @@ -47,12 +47,12 @@ public abstract class AbstractStorageItem extends ModItem { } @Override - public ITextComponent getDisplayName(final ItemStack stack) { + public ITextComponent getName(final ItemStack stack) { final int capacity = getCapacity(stack); return new StringTextComponent("") - .append(super.getDisplayName(stack)) - .appendString(" (") - .appendString(TextFormatUtils.formatSize(capacity)) - .appendString(")"); + .append(super.getName(stack)) + .append(" (") + .append(TextFormatUtils.formatSize(capacity)) + .append(")"); } } diff --git a/src/main/java/li/cil/oc2/common/item/BlockOperationsModule.java b/src/main/java/li/cil/oc2/common/item/BlockOperationsModule.java index aaa3de4e..60a6eca0 100644 --- a/src/main/java/li/cil/oc2/common/item/BlockOperationsModule.java +++ b/src/main/java/li/cil/oc2/common/item/BlockOperationsModule.java @@ -6,6 +6,6 @@ public final class BlockOperationsModule extends ModItem { /////////////////////////////////////////////////////////////////// public BlockOperationsModule() { - super(createProperties().maxDamage(DURABILITY)); + super(createProperties().durability(DURABILITY)); } } diff --git a/src/main/java/li/cil/oc2/common/item/BusCableItem.java b/src/main/java/li/cil/oc2/common/item/BusCableItem.java index 2150f31f..f7f6bf02 100644 --- a/src/main/java/li/cil/oc2/common/item/BusCableItem.java +++ b/src/main/java/li/cil/oc2/common/item/BusCableItem.java @@ -34,21 +34,21 @@ public final class BusCableItem extends ModBlockItem { @OnlyIn(Dist.CLIENT) @Override - public void addInformation(final ItemStack stack, final @Nullable World world, final List tooltip, final ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(final ItemStack stack, final @Nullable World world, final List tooltip, final ITooltipFlag flag) { + super.appendHoverText(stack, world, tooltip, flag); TooltipUtils.addEnergyConsumption(Config.busCableEnergyPerTick, tooltip); } @Override - public ActionResultType onItemUse(final ItemUseContext context) { + public ActionResultType useOn(final ItemUseContext context) { final ActionResultType result = tryAddToBlock(context); - return result.isSuccessOrConsume() ? result : super.onItemUse(context); + return result.consumesAction() ? result : super.useOn(context); } @Override - public ActionResultType tryPlace(final BlockItemUseContext context) { + public ActionResultType place(final BlockItemUseContext context) { final ActionResultType result = tryAddToBlock(context); - return result.isSuccessOrConsume() ? result : super.tryPlace(context); + return result.consumesAction() ? result : super.place(context); } /////////////////////////////////////////////////////////////////// @@ -56,13 +56,13 @@ public final class BusCableItem extends ModBlockItem { private ActionResultType tryAddToBlock(final ItemUseContext context) { final BusCableBlock busCableBlock = Blocks.BUS_CABLE.get(); - final World world = context.getWorld(); - final BlockPos pos = context.getPos(); + final World world = context.getLevel(); + final BlockPos pos = context.getClickedPos(); final BlockState state = world.getBlockState(pos); if (state.getBlock() == busCableBlock && busCableBlock.addCable(world, pos, state)) { final PlayerEntity player = context.getPlayer(); - final ItemStack stack = context.getItem(); + final ItemStack stack = context.getItemInHand(); if (player instanceof ServerPlayerEntity) { CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity) player, pos, stack); @@ -70,11 +70,11 @@ public final class BusCableItem extends ModBlockItem { WorldUtils.playSound(world, pos, state.getSoundType(world, pos, player), SoundType::getPlaceSound); - if (player == null || !player.abilities.isCreativeMode) { + if (player == null || !player.abilities.instabuild) { stack.shrink(1); } - return ActionResultType.func_233537_a_(world.isRemote); + return ActionResultType.sidedSuccess(world.isClientSide); } return ActionResultType.PASS; diff --git a/src/main/java/li/cil/oc2/common/item/BusInterfaceItem.java b/src/main/java/li/cil/oc2/common/item/BusInterfaceItem.java index fe21b4a9..1ebc666f 100644 --- a/src/main/java/li/cil/oc2/common/item/BusInterfaceItem.java +++ b/src/main/java/li/cil/oc2/common/item/BusInterfaceItem.java @@ -39,39 +39,39 @@ public final class BusInterfaceItem extends ModBlockItem { @OnlyIn(Dist.CLIENT) @Override - public void addInformation(final ItemStack stack, final @Nullable World world, final List tooltip, final ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(final ItemStack stack, final @Nullable World world, final List tooltip, final ITooltipFlag flag) { + super.appendHoverText(stack, world, tooltip, flag); TooltipUtils.addEnergyConsumption(Config.busInterfaceEnergyPerTick, tooltip); } @Override - public ActionResultType onItemUse(final ItemUseContext context) { - final Vector3d localHitPos = context.getHitVec().subtract(Vector3d.copyCentered(context.getPos())); - final Direction side = Direction.getFacingFromVector(localHitPos.x, localHitPos.y, localHitPos.z); + public ActionResultType useOn(final ItemUseContext context) { + final Vector3d localHitPos = context.getClickLocation().subtract(Vector3d.atCenterOf(context.getClickedPos())); + final Direction side = Direction.getNearest(localHitPos.x, localHitPos.y, localHitPos.z); final ActionResultType result = tryAddToBlock(context, side); - return result.isSuccessOrConsume() ? result : super.onItemUse(context); + return result.consumesAction() ? result : super.useOn(context); } @Override - public ActionResultType tryPlace(final BlockItemUseContext context) { - final ActionResultType result = tryAddToBlock(context, context.getFace().getOpposite()); - return result.isSuccessOrConsume() ? result : super.tryPlace(context); + public ActionResultType place(final BlockItemUseContext context) { + final ActionResultType result = tryAddToBlock(context, context.getClickedFace().getOpposite()); + return result.consumesAction() ? result : super.place(context); } @Override - public String getTranslationKey() { - return getDefaultTranslationKey(); + public String getDescriptionId() { + return getOrCreateDescriptionId(); } @Override - public void fillItemGroup(final ItemGroup group, final NonNullList items) { - if (isInGroup(group)) { + public void fillItemCategory(final ItemGroup group, final NonNullList items) { + if (allowdedIn(group)) { items.add(new ItemStack(this)); } } @Override - public void addToBlockToItemMap(final Map map, final Item item) { + public void registerBlocks(final Map map, final Item item) { } @Override @@ -82,13 +82,13 @@ public final class BusInterfaceItem extends ModBlockItem { @Nullable @Override - protected BlockState getStateForPlacement(final BlockItemUseContext context) { - final BlockState state = super.getStateForPlacement(context); + protected BlockState getPlacementState(final BlockItemUseContext context) { + final BlockState state = super.getPlacementState(context); final EnumProperty connectionTypeProperty = - BusCableBlock.FACING_TO_CONNECTION_MAP.get(context.getFace().getOpposite()); + BusCableBlock.FACING_TO_CONNECTION_MAP.get(context.getClickedFace().getOpposite()); return state - .with(BusCableBlock.HAS_CABLE, false) - .with(connectionTypeProperty, ConnectionType.INTERFACE); + .setValue(BusCableBlock.HAS_CABLE, false) + .setValue(connectionTypeProperty, ConnectionType.INTERFACE); } /////////////////////////////////////////////////////////////////// @@ -96,13 +96,13 @@ public final class BusInterfaceItem extends ModBlockItem { private ActionResultType tryAddToBlock(final ItemUseContext context, final Direction side) { final BusCableBlock busCableBlock = Blocks.BUS_CABLE.get(); - final World world = context.getWorld(); - final BlockPos pos = context.getPos(); + final World world = context.getLevel(); + final BlockPos pos = context.getClickedPos(); final BlockState state = world.getBlockState(pos); if (state.getBlock() == busCableBlock && busCableBlock.addInterface(world, pos, state, side)) { final PlayerEntity player = context.getPlayer(); - final ItemStack stack = context.getItem(); + final ItemStack stack = context.getItemInHand(); if (player instanceof ServerPlayerEntity) { CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity) player, pos, stack); @@ -110,11 +110,11 @@ public final class BusInterfaceItem extends ModBlockItem { WorldUtils.playSound(world, pos, state.getSoundType(world, pos, player), SoundType::getPlaceSound); - if (player == null || !player.abilities.isCreativeMode) { + if (player == null || !player.abilities.instabuild) { stack.shrink(1); } - return ActionResultType.func_233537_a_(world.isRemote); + return ActionResultType.sidedSuccess(world.isClientSide); } return ActionResultType.PASS; diff --git a/src/main/java/li/cil/oc2/common/item/ChargerItem.java b/src/main/java/li/cil/oc2/common/item/ChargerItem.java index 52947fcf..d81df610 100644 --- a/src/main/java/li/cil/oc2/common/item/ChargerItem.java +++ b/src/main/java/li/cil/oc2/common/item/ChargerItem.java @@ -14,9 +14,9 @@ public final class ChargerItem extends ModBlockItem { /////////////////////////////////////////////////////////////////// @Override - public void fillItemGroup(final ItemGroup group, final NonNullList items) { + public void fillItemCategory(final ItemGroup group, final NonNullList items) { if (Config.chargerUseEnergy()) { - super.fillItemGroup(group, items); + super.fillItemCategory(group, items); } } } diff --git a/src/main/java/li/cil/oc2/common/item/FlashMemoryItem.java b/src/main/java/li/cil/oc2/common/item/FlashMemoryItem.java index 2415f3e3..d1de83e8 100644 --- a/src/main/java/li/cil/oc2/common/item/FlashMemoryItem.java +++ b/src/main/java/li/cil/oc2/common/item/FlashMemoryItem.java @@ -10,7 +10,7 @@ import javax.annotation.Nullable; public final class FlashMemoryItem extends AbstractStorageItem { public FlashMemoryItem(final int defaultCapacity) { - super(createProperties().maxStackSize(1), defaultCapacity); + super(createProperties().stacksTo(1), defaultCapacity); } /////////////////////////////////////////////////////////////////// @@ -28,7 +28,7 @@ public final class FlashMemoryItem extends AbstractStorageItem { /////////////////////////////////////////////////////////////////// @Override - protected String getDefaultTranslationKey() { + protected String getOrCreateDescriptionId() { return "item.oc2.flash_memory"; } } diff --git a/src/main/java/li/cil/oc2/common/item/FlashMemoryWithExternalDataItem.java b/src/main/java/li/cil/oc2/common/item/FlashMemoryWithExternalDataItem.java index 97f26281..389c0825 100644 --- a/src/main/java/li/cil/oc2/common/item/FlashMemoryWithExternalDataItem.java +++ b/src/main/java/li/cil/oc2/common/item/FlashMemoryWithExternalDataItem.java @@ -22,7 +22,7 @@ public final class FlashMemoryWithExternalDataItem extends ModItem { /////////////////////////////////////////////////////////////////// public FlashMemoryWithExternalDataItem(final ResourceLocation defaultData) { - super(createProperties().maxStackSize(1)); + super(createProperties().stacksTo(1)); this.defaultData = defaultData; } @@ -67,23 +67,23 @@ public final class FlashMemoryWithExternalDataItem extends ModItem { } @Override - public ITextComponent getDisplayName(final ItemStack stack) { + public ITextComponent getName(final ItemStack stack) { final Firmware firmware = getFirmware(stack); if (firmware != null) { return new StringTextComponent("") - .append(super.getDisplayName(stack)) - .appendString(" (") + .append(super.getName(stack)) + .append(" (") .append(firmware.getDisplayName()) - .appendString(")"); + .append(")"); } else { - return super.getDisplayName(stack); + return super.getName(stack); } } /////////////////////////////////////////////////////////////////// @Override - protected String getDefaultTranslationKey() { + protected String getOrCreateDescriptionId() { return "item.oc2.flash_memory"; } } diff --git a/src/main/java/li/cil/oc2/common/item/HardDriveItem.java b/src/main/java/li/cil/oc2/common/item/HardDriveItem.java index 08e4beaa..236d4196 100644 --- a/src/main/java/li/cil/oc2/common/item/HardDriveItem.java +++ b/src/main/java/li/cil/oc2/common/item/HardDriveItem.java @@ -18,13 +18,13 @@ public final class HardDriveItem extends AbstractStorageItem implements IDyeable @Override public int getColor(final ItemStack stack) { - return hasColor(stack) ? IDyeableArmorItem.super.getColor(stack) : defaultColor; + return hasCustomColor(stack) ? IDyeableArmorItem.super.getColor(stack) : defaultColor; } /////////////////////////////////////////////////////////////////// @Override - protected String getDefaultTranslationKey() { + protected String getOrCreateDescriptionId() { return "item.oc2.hard_drive"; } } diff --git a/src/main/java/li/cil/oc2/common/item/HardDriveWithExternalDataItem.java b/src/main/java/li/cil/oc2/common/item/HardDriveWithExternalDataItem.java index cadc294e..d04ed0ac 100644 --- a/src/main/java/li/cil/oc2/common/item/HardDriveWithExternalDataItem.java +++ b/src/main/java/li/cil/oc2/common/item/HardDriveWithExternalDataItem.java @@ -19,13 +19,13 @@ public final class HardDriveWithExternalDataItem extends AbstractBlockDeviceItem @Override public int getColor(final ItemStack stack) { - return hasColor(stack) ? IDyeableArmorItem.super.getColor(stack) : defaultColor; + return hasCustomColor(stack) ? IDyeableArmorItem.super.getColor(stack) : defaultColor; } /////////////////////////////////////////////////////////////////// @Override - protected String getDefaultTranslationKey() { + protected String getOrCreateDescriptionId() { return "item.oc2.hard_drive"; } } diff --git a/src/main/java/li/cil/oc2/common/item/ItemGroup.java b/src/main/java/li/cil/oc2/common/item/ItemGroup.java index 69b17989..ed1a486c 100644 --- a/src/main/java/li/cil/oc2/common/item/ItemGroup.java +++ b/src/main/java/li/cil/oc2/common/item/ItemGroup.java @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack; public final class ItemGroup { public static final net.minecraft.item.ItemGroup COMMON = new net.minecraft.item.ItemGroup(API.MOD_ID + ".common") { @Override - public ItemStack createIcon() { + public ItemStack makeIcon() { return new ItemStack(Items.COMPUTER.get()); } }; diff --git a/src/main/java/li/cil/oc2/common/item/MemoryItem.java b/src/main/java/li/cil/oc2/common/item/MemoryItem.java index 7aadf5b3..35471d48 100644 --- a/src/main/java/li/cil/oc2/common/item/MemoryItem.java +++ b/src/main/java/li/cil/oc2/common/item/MemoryItem.java @@ -8,7 +8,8 @@ public final class MemoryItem extends AbstractStorageItem { /////////////////////////////////////////////////////////////////// @Override - protected String getDefaultTranslationKey() { + protected String getOrCreateDescriptionId() { return "item.oc2.memory"; } + } diff --git a/src/main/java/li/cil/oc2/common/item/ModBlockItem.java b/src/main/java/li/cil/oc2/common/item/ModBlockItem.java index 9dffe063..c4e36ada 100644 --- a/src/main/java/li/cil/oc2/common/item/ModBlockItem.java +++ b/src/main/java/li/cil/oc2/common/item/ModBlockItem.java @@ -15,7 +15,7 @@ import java.util.List; public class ModBlockItem extends BlockItem { public ModBlockItem(final Block block, final Properties properties) { - super(block, properties.group(ItemGroup.COMMON)); + super(block, properties.tab(ItemGroup.COMMON)); } public ModBlockItem(final Block block) { @@ -26,9 +26,9 @@ public class ModBlockItem extends BlockItem { @OnlyIn(Dist.CLIENT) @Override - public void addInformation(final ItemStack stack, @Nullable final World world, final List tooltip, final ITooltipFlag flag) { + public void appendHoverText(final ItemStack stack, @Nullable final World world, final List tooltip, final ITooltipFlag flag) { TooltipUtils.tryAddDescription(stack, tooltip); - super.addInformation(stack, world, tooltip, flag); + super.appendHoverText(stack, world, tooltip, flag); } /////////////////////////////////////////////////////////////////// diff --git a/src/main/java/li/cil/oc2/common/item/ModItem.java b/src/main/java/li/cil/oc2/common/item/ModItem.java index b0e2531b..250715fb 100644 --- a/src/main/java/li/cil/oc2/common/item/ModItem.java +++ b/src/main/java/li/cil/oc2/common/item/ModItem.java @@ -14,7 +14,7 @@ import java.util.List; public class ModItem extends Item { public ModItem(final Properties properties) { - super(properties.group(ItemGroup.COMMON)); + super(properties.tab(ItemGroup.COMMON)); } public ModItem() { @@ -25,8 +25,8 @@ public class ModItem extends Item { @OnlyIn(Dist.CLIENT) @Override - public void addInformation(final ItemStack stack, @Nullable final World world, final List tooltip, final ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(final ItemStack stack, @Nullable final World world, final List tooltip, final ITooltipFlag flag) { + super.appendHoverText(stack, world, tooltip, flag); TooltipUtils.tryAddDescription(stack, tooltip); } diff --git a/src/main/java/li/cil/oc2/common/item/NetworkCableItem.java b/src/main/java/li/cil/oc2/common/item/NetworkCableItem.java index 48c24f66..68bf9926 100644 --- a/src/main/java/li/cil/oc2/common/item/NetworkCableItem.java +++ b/src/main/java/li/cil/oc2/common/item/NetworkCableItem.java @@ -24,51 +24,51 @@ public final class NetworkCableItem extends ModItem { /////////////////////////////////////////////////////////////////// @Override - public ActionResult onItemRightClick(final World world, final PlayerEntity player, final Hand hand) { - if (player.isSneaking()) { + public ActionResult use(final World world, final PlayerEntity player, final Hand hand) { + if (player.isShiftKeyDown()) { if (player instanceof ServerPlayerEntity) { LINK_STARTS.remove(player); } - return ActionResult.resultSuccess(player.getHeldItem(hand)); + return ActionResult.success(player.getItemInHand(hand)); } - return super.onItemRightClick(world, player, hand); + return super.use(world, player, hand); } @Override - public ActionResultType onItemUse(final ItemUseContext context) { + public ActionResultType useOn(final ItemUseContext context) { final PlayerEntity player = context.getPlayer(); if (player == null) { - return super.onItemUse(context); + return super.useOn(context); } - final ItemStack stack = player.getHeldItem(context.getHand()); + final ItemStack stack = player.getItemInHand(context.getHand()); if (stack.isEmpty() || stack.getItem() != this) { - return super.onItemUse(context); + return super.useOn(context); } - final World world = context.getWorld(); - final BlockPos currentPos = context.getPos(); + final World world = context.getLevel(); + final BlockPos currentPos = context.getClickedPos(); - final TileEntity currentTileEntity = world.getTileEntity(currentPos); + final TileEntity currentTileEntity = world.getBlockEntity(currentPos); if (!(currentTileEntity instanceof NetworkConnectorTileEntity)) { - return super.onItemUse(context); + return super.useOn(context); } - if (!world.isRemote() && player instanceof ServerPlayerEntity) { + if (!world.isClientSide && player instanceof ServerPlayerEntity) { final BlockPos startPos = LINK_STARTS.remove(player); if (startPos == null || Objects.equals(startPos, currentPos)) { if (((NetworkConnectorTileEntity) currentTileEntity).canConnectMore()) { LINK_STARTS.put((ServerPlayerEntity) player, currentPos); } else { - player.sendStatusMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_FULL), true); + player.displayClientMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_FULL), true); } } else { - final TileEntity startTileEntity = world.getTileEntity(startPos); + final TileEntity startTileEntity = world.getBlockEntity(startPos); if (!(startTileEntity instanceof NetworkConnectorTileEntity)) { // Starting connector was removed in the meantime. - return super.onItemUse(context); + return super.useOn(context); } final NetworkConnectorTileEntity connectorA = (NetworkConnectorTileEntity) startTileEntity; @@ -87,15 +87,15 @@ public final class NetworkCableItem extends ModItem { break; case FAILURE_FULL: LINK_STARTS.put((ServerPlayerEntity) player, startPos); - player.sendStatusMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_FULL), true); + player.displayClientMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_FULL), true); break; case FAILURE_TOO_FAR: LINK_STARTS.put((ServerPlayerEntity) player, startPos); - player.sendStatusMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_TOO_FAR), true); + player.displayClientMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_TOO_FAR), true); break; case FAILURE_OBSTRUCTED: LINK_STARTS.put((ServerPlayerEntity) player, startPos); - player.sendStatusMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_OBSTRUCTED), true); + player.displayClientMessage(new TranslationTextComponent(Constants.CONNECTOR_ERROR_OBSTRUCTED), true); break; } } diff --git a/src/main/java/li/cil/oc2/common/item/RobotItem.java b/src/main/java/li/cil/oc2/common/item/RobotItem.java index 3de03622..bdc03678 100644 --- a/src/main/java/li/cil/oc2/common/item/RobotItem.java +++ b/src/main/java/li/cil/oc2/common/item/RobotItem.java @@ -37,8 +37,8 @@ public final class RobotItem extends ModItem { /////////////////////////////////////////////////////////////////// @Override - public void addInformation(final ItemStack stack, @Nullable final World world, final List tooltip, final ITooltipFlag flag) { - super.addInformation(stack, world, tooltip, flag); + public void appendHoverText(final ItemStack stack, @Nullable final World world, final List tooltip, final ITooltipFlag flag) { + super.appendHoverText(stack, world, tooltip, flag); TooltipUtils.addEnergyConsumption(Config.robotEnergyPerTick, tooltip); TooltipUtils.addEntityEnergyInformation(stack, tooltip); TooltipUtils.addEntityInventoryInformation(stack, tooltip); @@ -55,37 +55,37 @@ public final class RobotItem extends ModItem { } @Override - public ActionResultType onItemUse(final ItemUseContext context) { - final World world = context.getWorld(); - final BlockPos pos = context.getPos(); + public ActionResultType useOn(final ItemUseContext context) { + final World world = context.getLevel(); + final BlockPos pos = context.getClickedPos(); final Vector3d position; - if (world.getBlockState(pos).isReplaceable(new BlockItemUseContext(context))) { - position = Vector3d.copyCentered(pos); + if (world.getBlockState(pos).canBeReplaced(new BlockItemUseContext(context))) { + position = Vector3d.atCenterOf(pos); } else { - position = Vector3d.copyCentered(pos.offset(context.getFace())); + position = Vector3d.atCenterOf(pos.relative(context.getClickedFace())); } - final RobotEntity robot = Entities.ROBOT.get().create(context.getWorld()); - robot.setLocationAndAngles(position.getX(), position.getY() - robot.getHeight() * 0.5f, position.getZ(), - Direction.fromAngle(context.getPlacementYaw()).getOpposite().getHorizontalAngle(), 0); - if (!world.hasNoCollisions(robot)) { - return super.onItemUse(context); + final RobotEntity robot = Entities.ROBOT.get().create(context.getLevel()); + robot.moveTo(position.x, position.y - robot.getBbHeight() * 0.5f, position.z, + Direction.fromYRot(context.getRotation()).getOpposite().toYRot(), 0); + if (!world.noCollision(robot)) { + return super.useOn(context); } - if (!world.isRemote()) { + if (!world.isClientSide) { RobotActions.initializeData(robot); - robot.importFromItemStack(context.getItem()); + robot.importFromItemStack(context.getItemInHand()); - world.addEntity(robot); + world.addFreshEntity(robot); WorldUtils.playSound(world, new BlockPos(position), SoundType.METAL, SoundType::getPlaceSound); if (!context.getPlayer().isCreative()) { - context.getItem().shrink(1); + context.getItemInHand().shrink(1); } } - context.getPlayer().addStat(Stats.ITEM_USED.get(this)); + context.getPlayer().awardStat(Stats.ITEM_USED.get(this)); return ActionResultType.SUCCESS; } diff --git a/src/main/java/li/cil/oc2/common/item/WrenchItem.java b/src/main/java/li/cil/oc2/common/item/WrenchItem.java index 9ca83d36..7cc8f9a2 100644 --- a/src/main/java/li/cil/oc2/common/item/WrenchItem.java +++ b/src/main/java/li/cil/oc2/common/item/WrenchItem.java @@ -14,26 +14,26 @@ import net.minecraft.world.World; public final class WrenchItem extends ModItem { @Override - public ActionResultType onItemUse(final ItemUseContext context) { + public ActionResultType useOn(final ItemUseContext context) { final PlayerEntity player = context.getPlayer(); - if (!player.isSneaking()) { - return super.onItemUse(context); + if (!player.isShiftKeyDown()) { + return super.useOn(context); } - final World world = context.getWorld(); - final BlockPos pos = context.getPos(); + final World world = context.getLevel(); + final BlockPos pos = context.getClickedPos(); final BlockState state = world.getBlockState(pos); - if (!state.isIn(BlockTags.WRENCH_BREAKABLE)) { - return super.onItemUse(context); + if (!state.is(BlockTags.WRENCH_BREAKABLE)) { + return super.useOn(context); } - if (world.isRemote()) { - Minecraft.getInstance().playerController.onPlayerDestroyBlock(pos); + if (world.isClientSide) { + Minecraft.getInstance().gameMode.destroyBlock(pos); } else if (player instanceof ServerPlayerEntity) { - ((ServerPlayerEntity) player).interactionManager.tryHarvestBlock(pos); + ((ServerPlayerEntity) player).gameMode.destroyBlock(pos); } - return ActionResultType.func_233537_a_(world.isRemote); + return ActionResultType.sidedSuccess(world.isClientSide); } @Override diff --git a/src/main/java/li/cil/oc2/common/item/crafting/WrenchRecipe.java b/src/main/java/li/cil/oc2/common/item/crafting/WrenchRecipe.java index fda1ee0d..8a01feee 100644 --- a/src/main/java/li/cil/oc2/common/item/crafting/WrenchRecipe.java +++ b/src/main/java/li/cil/oc2/common/item/crafting/WrenchRecipe.java @@ -14,15 +14,15 @@ import org.jetbrains.annotations.Nullable; public final class WrenchRecipe extends ShapelessRecipe { public WrenchRecipe(final ShapelessRecipe recipe) { - super(recipe.getId(), recipe.getGroup(), recipe.getRecipeOutput(), recipe.getIngredients()); + super(recipe.getId(), recipe.getGroup(), recipe.getResultItem(), recipe.getIngredients()); } @Override public NonNullList getRemainingItems(final CraftingInventory inventory) { - final NonNullList result = NonNullList.withSize(inventory.getSizeInventory(), ItemStack.EMPTY); + final NonNullList result = NonNullList.withSize(inventory.getContainerSize(), ItemStack.EMPTY); - for (int slot = 0; slot < inventory.getSizeInventory(); slot++) { - final ItemStack stack = inventory.getStackInSlot(slot); + for (int slot = 0; slot < inventory.getContainerSize(); slot++) { + final ItemStack stack = inventory.getItem(slot); if (stack.hasContainerItem()) { result.set(slot, stack.getContainerItem()); } else if (Wrenches.isWrench(stack)) { @@ -42,19 +42,19 @@ public final class WrenchRecipe extends ShapelessRecipe { public static final class Serializer extends ForgeRegistryEntry> implements IRecipeSerializer { @Override - public WrenchRecipe read(final ResourceLocation location, final JsonObject json) { - return new WrenchRecipe(CRAFTING_SHAPELESS.read(location, json)); + public WrenchRecipe fromJson(final ResourceLocation location, final JsonObject json) { + return new WrenchRecipe(SHAPELESS_RECIPE.fromJson(location, json)); } @Nullable @Override - public WrenchRecipe read(final ResourceLocation location, final PacketBuffer buffer) { - return new WrenchRecipe(CRAFTING_SHAPELESS.read(location, buffer)); + public WrenchRecipe fromNetwork(final ResourceLocation location, final PacketBuffer buffer) { + return new WrenchRecipe(SHAPELESS_RECIPE.fromNetwork(location, buffer)); } @Override - public void write(final PacketBuffer buffer, final WrenchRecipe recipe) { - CRAFTING_SHAPELESS.write(buffer, recipe); + public void toNetwork(final PacketBuffer buffer, final WrenchRecipe recipe) { + SHAPELESS_RECIPE.toNetwork(buffer, recipe); } } } diff --git a/src/main/java/li/cil/oc2/common/network/MessageUtils.java b/src/main/java/li/cil/oc2/common/network/MessageUtils.java index d7927a37..31870579 100644 --- a/src/main/java/li/cil/oc2/common/network/MessageUtils.java +++ b/src/main/java/li/cil/oc2/common/network/MessageUtils.java @@ -21,8 +21,8 @@ public final class MessageUtils { return; } - final ServerWorld world = player.getServerWorld(); - final TileEntity tileEntity = WorldUtils.getTileEntityIfChunkExists(world, pos); + final ServerWorld world = player.getLevel(); + final TileEntity tileEntity = WorldUtils.getBlockEntityIfChunkExists(world, pos); if (type.isInstance(tileEntity)) { callback.accept((T) tileEntity); } @@ -35,8 +35,8 @@ public final class MessageUtils { return; } - final ServerWorld world = player.getServerWorld(); - final Entity entity = world.getEntityByID(id); + final ServerWorld world = player.getLevel(); + final Entity entity = world.getEntity(id); if (type.isInstance(entity)) { callback.accept((T) entity); } @@ -44,12 +44,12 @@ public final class MessageUtils { @SuppressWarnings("unchecked") public static void withClientTileEntityAt(final BlockPos pos, final Class type, final Consumer callback) { - final ClientWorld world = Minecraft.getInstance().world; + final ClientWorld world = Minecraft.getInstance().level; if (world == null) { return; } - final TileEntity tileEntity = world.getTileEntity(pos); + final TileEntity tileEntity = world.getBlockEntity(pos); if (type.isInstance(tileEntity)) { callback.accept((T) tileEntity); } @@ -57,12 +57,12 @@ public final class MessageUtils { @SuppressWarnings("unchecked") public static void withClientEntity(final int id, final Class type, final Consumer callback) { - final ClientWorld world = Minecraft.getInstance().world; + final ClientWorld world = Minecraft.getInstance().level; if (world == null) { return; } - final Entity entity = world.getEntityByID(id); + final Entity entity = world.getEntity(id); if (type.isInstance(entity)) { callback.accept((T) entity); } diff --git a/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalBlockMessage.java b/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalBlockMessage.java index 16738ef3..b3f7badf 100644 --- a/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalBlockMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalBlockMessage.java @@ -13,7 +13,7 @@ public abstract class AbstractTerminalBlockMessage { /////////////////////////////////////////////////////////////////// protected AbstractTerminalBlockMessage(final ComputerTileEntity tileEntity, final ByteBuffer data) { - this.pos = tileEntity.getPos(); + this.pos = tileEntity.getBlockPos(); this.data = data.array(); } diff --git a/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalEntityMessage.java b/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalEntityMessage.java index 3089a61e..3e986266 100644 --- a/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalEntityMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/AbstractTerminalEntityMessage.java @@ -12,7 +12,7 @@ public abstract class AbstractTerminalEntityMessage { /////////////////////////////////////////////////////////////////// protected AbstractTerminalEntityMessage(final Entity entity, final ByteBuffer data) { - this.entityId = entity.getEntityId(); + this.entityId = entity.getId(); this.data = data.array(); } diff --git a/src/main/java/li/cil/oc2/common/network/message/BusInterfaceNameMessage.java b/src/main/java/li/cil/oc2/common/network/message/BusInterfaceNameMessage.java index 2d654740..5679a012 100644 --- a/src/main/java/li/cil/oc2/common/network/message/BusInterfaceNameMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/BusInterfaceNameMessage.java @@ -18,7 +18,7 @@ public abstract class BusInterfaceNameMessage { /////////////////////////////////////////////////////////////////// protected BusInterfaceNameMessage(final BusCableTileEntity tileEntity, final Direction side, final String value) { - this.pos = tileEntity.getPos(); + this.pos = tileEntity.getBlockPos(); this.side = side; this.value = value; } @@ -38,8 +38,8 @@ public abstract class BusInterfaceNameMessage { public static boolean handleMessageServer(final BusInterfaceNameMessage message, final Supplier context) { context.get().enqueueWork(() -> MessageUtils.withServerTileEntityAt(context, message.pos, BusCableTileEntity.class, (tileEntity) -> { - final Vector3d busCableCenter = Vector3d.copyCentered(tileEntity.getPos()); - if (context.get().getSender().getDistanceSq(busCableCenter) <= 8 * 8) { + final Vector3d busCableCenter = Vector3d.atCenterOf(tileEntity.getBlockPos()); + if (context.get().getSender().distanceToSqr(busCableCenter) <= 8 * 8) { tileEntity.setInterfaceName(message.side, message.value); } })); @@ -48,14 +48,14 @@ public abstract class BusInterfaceNameMessage { public void fromBytes(final PacketBuffer buffer) { pos = buffer.readBlockPos(); - side = buffer.readEnumValue(Direction.class); - value = buffer.readString(32); + side = buffer.readEnum(Direction.class); + value = buffer.readUtf(32); } public static void toBytes(final BusInterfaceNameMessage message, final PacketBuffer buffer) { buffer.writeBlockPos(message.pos); - buffer.writeEnumValue(message.side); - buffer.writeString(message.value, 32); + buffer.writeEnum(message.side); + buffer.writeUtf(message.value, 32); } /////////////////////////////////////////////////////////////////// diff --git a/src/main/java/li/cil/oc2/common/network/message/ComputerBootErrorMessage.java b/src/main/java/li/cil/oc2/common/network/message/ComputerBootErrorMessage.java index 4fcc7f82..8680d764 100644 --- a/src/main/java/li/cil/oc2/common/network/message/ComputerBootErrorMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/ComputerBootErrorMessage.java @@ -16,7 +16,7 @@ public final class ComputerBootErrorMessage { /////////////////////////////////////////////////////////////////// public ComputerBootErrorMessage(final ComputerTileEntity tileEntity) { - this.pos = tileEntity.getPos(); + this.pos = tileEntity.getBlockPos(); this.value = tileEntity.getVirtualMachine().getBootError(); } @@ -34,11 +34,11 @@ public final class ComputerBootErrorMessage { public void fromBytes(final PacketBuffer buffer) { pos = buffer.readBlockPos(); - value = buffer.readTextComponent(); + value = buffer.readComponent(); } public static void toBytes(final ComputerBootErrorMessage message, final PacketBuffer buffer) { buffer.writeBlockPos(message.pos); - buffer.writeTextComponent(message.value); + buffer.writeComponent(message.value); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/ComputerBusStateMessage.java b/src/main/java/li/cil/oc2/common/network/message/ComputerBusStateMessage.java index ef93b03c..062045b4 100644 --- a/src/main/java/li/cil/oc2/common/network/message/ComputerBusStateMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/ComputerBusStateMessage.java @@ -16,7 +16,7 @@ public final class ComputerBusStateMessage { /////////////////////////////////////////////////////////////////// public ComputerBusStateMessage(final ComputerTileEntity tileEntity) { - this.pos = tileEntity.getPos(); + this.pos = tileEntity.getBlockPos(); this.value = tileEntity.getVirtualMachine().getBusState(); } @@ -34,11 +34,11 @@ public final class ComputerBusStateMessage { public void fromBytes(final PacketBuffer buffer) { pos = buffer.readBlockPos(); - value = buffer.readEnumValue(CommonDeviceBusController.BusState.class); + value = buffer.readEnum(CommonDeviceBusController.BusState.class); } public static void toBytes(final ComputerBusStateMessage message, final PacketBuffer buffer) { buffer.writeBlockPos(message.pos); - buffer.writeEnumValue(message.value); + buffer.writeEnum(message.value); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/ComputerPowerMessage.java b/src/main/java/li/cil/oc2/common/network/message/ComputerPowerMessage.java index 5f7f7c07..bc3f8e6c 100644 --- a/src/main/java/li/cil/oc2/common/network/message/ComputerPowerMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/ComputerPowerMessage.java @@ -16,7 +16,7 @@ public final class ComputerPowerMessage { /////////////////////////////////////////////////////////////////// public ComputerPowerMessage(final ComputerTileEntity computer, final boolean power) { - this.pos = computer.getPos(); + this.pos = computer.getBlockPos(); this.power = power; } @@ -30,7 +30,7 @@ public final class ComputerPowerMessage { context.get().enqueueWork(() -> MessageUtils.withServerTileEntityAt(context, message.pos, ComputerTileEntity.class, (computer) -> { final ServerPlayerEntity player = context.get().getSender(); - if (player != null && computer.getPos().withinDistance(player.getPositionVec(), 8)) { + if (player != null && computer.getBlockPos().closerThan(player.position(), 8)) { if (message.power) { computer.start(); } else { diff --git a/src/main/java/li/cil/oc2/common/network/message/ComputerRunStateMessage.java b/src/main/java/li/cil/oc2/common/network/message/ComputerRunStateMessage.java index edb3a5d6..abb20e02 100644 --- a/src/main/java/li/cil/oc2/common/network/message/ComputerRunStateMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/ComputerRunStateMessage.java @@ -16,7 +16,7 @@ public final class ComputerRunStateMessage { /////////////////////////////////////////////////////////////////// public ComputerRunStateMessage(final ComputerTileEntity tileEntity) { - this.pos = tileEntity.getPos(); + this.pos = tileEntity.getBlockPos(); this.value = tileEntity.getVirtualMachine().getRunState(); } @@ -34,11 +34,11 @@ public final class ComputerRunStateMessage { public void fromBytes(final PacketBuffer buffer) { pos = buffer.readBlockPos(); - value = buffer.readEnumValue(VMRunState.class); + value = buffer.readEnum(VMRunState.class); } public static void toBytes(final ComputerRunStateMessage message, final PacketBuffer buffer) { buffer.writeBlockPos(message.pos); - buffer.writeEnumValue(message.value); + buffer.writeEnum(message.value); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/DiskDriveFloppyMessage.java b/src/main/java/li/cil/oc2/common/network/message/DiskDriveFloppyMessage.java index f5afe7e8..a8caed78 100644 --- a/src/main/java/li/cil/oc2/common/network/message/DiskDriveFloppyMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/DiskDriveFloppyMessage.java @@ -17,7 +17,7 @@ public final class DiskDriveFloppyMessage { /////////////////////////////////////////////////////////////////// public DiskDriveFloppyMessage(final DiskDriveTileEntity diskDrive) { - this.pos = diskDrive.getPos(); + this.pos = diskDrive.getBlockPos(); this.data = diskDrive.getFloppy().serializeNBT(); } @@ -29,17 +29,17 @@ public final class DiskDriveFloppyMessage { public static boolean handleMessage(final DiskDriveFloppyMessage message, final Supplier context) { context.get().enqueueWork(() -> MessageUtils.withClientTileEntityAt(message.pos, DiskDriveTileEntity.class, - (diskDrive) -> diskDrive.setFloppyClient(ItemStack.read(message.data)))); + (diskDrive) -> diskDrive.setFloppyClient(ItemStack.of(message.data)))); return true; } public void fromBytes(final PacketBuffer buffer) { pos = buffer.readBlockPos(); - data = buffer.readCompoundTag(); + data = buffer.readNbt(); } public static void toBytes(final DiskDriveFloppyMessage message, final PacketBuffer buffer) { buffer.writeBlockPos(message.pos); - buffer.writeCompoundTag(message.data); + buffer.writeNbt(message.data); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/ExportedFileMessage.java b/src/main/java/li/cil/oc2/common/network/message/ExportedFileMessage.java index 37f4fe98..7a7cda98 100644 --- a/src/main/java/li/cil/oc2/common/network/message/ExportedFileMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/ExportedFileMessage.java @@ -44,12 +44,12 @@ public final class ExportedFileMessage { } public static void toBytes(final ExportedFileMessage message, final PacketBuffer buffer) { - buffer.writeString(message.name); + buffer.writeUtf(message.name); buffer.writeByteArray(message.data); } public void fromBytes(final PacketBuffer buffer) { - name = buffer.readString(); + name = buffer.readUtf(); data = buffer.readByteArray(); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/NetworkConnectorConnectionsMessage.java b/src/main/java/li/cil/oc2/common/network/message/NetworkConnectorConnectionsMessage.java index c675a2c8..c8fcfbbd 100644 --- a/src/main/java/li/cil/oc2/common/network/message/NetworkConnectorConnectionsMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/NetworkConnectorConnectionsMessage.java @@ -16,7 +16,7 @@ public final class NetworkConnectorConnectionsMessage { /////////////////////////////////////////////////////////////////// public NetworkConnectorConnectionsMessage(final NetworkConnectorTileEntity connector) { - this.pos = connector.getPos(); + this.pos = connector.getBlockPos(); this.connectedPositions = new ArrayList<>(connector.getConnectedPositions()); } diff --git a/src/main/java/li/cil/oc2/common/network/message/RequestImportedFileMessage.java b/src/main/java/li/cil/oc2/common/network/message/RequestImportedFileMessage.java index 83bfd9b2..ae5b5d02 100644 --- a/src/main/java/li/cil/oc2/common/network/message/RequestImportedFileMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/RequestImportedFileMessage.java @@ -44,8 +44,8 @@ public final class RequestImportedFileMessage { final byte[] data = Files.readAllBytes(path); if (data.length > FileImportExportCardItemDevice.MAX_TRANSFERRED_FILE_SIZE) { Network.INSTANCE.sendToServer(new ClientCanceledImportFileMessage(message.id)); - Minecraft.getInstance().player.sendStatusMessage(FILE_TOO_LARGE_TEXT - .modifyStyle(s -> s.setColor(Color.fromInt(0xFFA0A0))), false); + Minecraft.getInstance().player.displayClientMessage(FILE_TOO_LARGE_TEXT + .withStyle(s -> s.withColor(Color.fromRgb(0xFFA0A0))), false); } else { Network.INSTANCE.sendToServer(new ImportedFileMessage(message.id, data)); } diff --git a/src/main/java/li/cil/oc2/common/network/message/RobotBootErrorMessage.java b/src/main/java/li/cil/oc2/common/network/message/RobotBootErrorMessage.java index 56529752..5f607ce0 100644 --- a/src/main/java/li/cil/oc2/common/network/message/RobotBootErrorMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/RobotBootErrorMessage.java @@ -15,7 +15,7 @@ public final class RobotBootErrorMessage { /////////////////////////////////////////////////////////////////// public RobotBootErrorMessage(final RobotEntity robot) { - this.entityId = robot.getEntityId(); + this.entityId = robot.getId(); this.value = robot.getVirtualMachine().getBootError(); } @@ -33,11 +33,11 @@ public final class RobotBootErrorMessage { public void fromBytes(final PacketBuffer buffer) { entityId = buffer.readVarInt(); - value = buffer.readTextComponent(); + value = buffer.readComponent(); } public static void toBytes(final RobotBootErrorMessage message, final PacketBuffer buffer) { buffer.writeVarInt(message.entityId); - buffer.writeTextComponent(message.value); + buffer.writeComponent(message.value); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/RobotBusStateMessage.java b/src/main/java/li/cil/oc2/common/network/message/RobotBusStateMessage.java index aee2ed19..f8632203 100644 --- a/src/main/java/li/cil/oc2/common/network/message/RobotBusStateMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/RobotBusStateMessage.java @@ -15,7 +15,7 @@ public final class RobotBusStateMessage { /////////////////////////////////////////////////////////////////// public RobotBusStateMessage(final RobotEntity robot) { - this.entityId = robot.getEntityId(); + this.entityId = robot.getId(); this.value = robot.getVirtualMachine().getBusState(); } @@ -33,11 +33,11 @@ public final class RobotBusStateMessage { public void fromBytes(final PacketBuffer buffer) { entityId = buffer.readVarInt(); - value = buffer.readEnumValue(CommonDeviceBusController.BusState.class); + value = buffer.readEnum(CommonDeviceBusController.BusState.class); } public static void toBytes(final RobotBusStateMessage message, final PacketBuffer buffer) { buffer.writeVarInt(message.entityId); - buffer.writeEnumValue(message.value); + buffer.writeEnum(message.value); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/RobotInitializationMessage.java b/src/main/java/li/cil/oc2/common/network/message/RobotInitializationMessage.java index 6ba8851b..4ec89cc5 100644 --- a/src/main/java/li/cil/oc2/common/network/message/RobotInitializationMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/RobotInitializationMessage.java @@ -22,7 +22,7 @@ public final class RobotInitializationMessage { /////////////////////////////////////////////////////////////////// public RobotInitializationMessage(final RobotEntity robot) { - this.entityId = robot.getEntityId(); + this.entityId = robot.getId(); this.busState = robot.getVirtualMachine().getBusState(); this.runState = robot.getVirtualMachine().getRunState(); this.bootError = robot.getVirtualMachine().getBootError(); @@ -48,17 +48,17 @@ public final class RobotInitializationMessage { public void fromBytes(final PacketBuffer buffer) { entityId = buffer.readVarInt(); - busState = buffer.readEnumValue(CommonDeviceBusController.BusState.class); - runState = buffer.readEnumValue(VMRunState.class); - bootError = buffer.readTextComponent(); - terminal = buffer.readCompoundTag(); + busState = buffer.readEnum(CommonDeviceBusController.BusState.class); + runState = buffer.readEnum(VMRunState.class); + bootError = buffer.readComponent(); + terminal = buffer.readNbt(); } public static void toBytes(final RobotInitializationMessage message, final PacketBuffer buffer) { buffer.writeVarInt(message.entityId); - buffer.writeEnumValue(message.busState); - buffer.writeEnumValue(message.runState); - buffer.writeTextComponent(message.bootError); - buffer.writeCompoundTag(message.terminal); + buffer.writeEnum(message.busState); + buffer.writeEnum(message.runState); + buffer.writeComponent(message.bootError); + buffer.writeNbt(message.terminal); } } diff --git a/src/main/java/li/cil/oc2/common/network/message/RobotInitializationRequestMessage.java b/src/main/java/li/cil/oc2/common/network/message/RobotInitializationRequestMessage.java index 0ecf1af5..a16ab68e 100644 --- a/src/main/java/li/cil/oc2/common/network/message/RobotInitializationRequestMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/RobotInitializationRequestMessage.java @@ -14,7 +14,7 @@ public final class RobotInitializationRequestMessage { /////////////////////////////////////////////////////////////////// public RobotInitializationRequestMessage(final RobotEntity robot) { - this.entityId = robot.getEntityId(); + this.entityId = robot.getId(); } public RobotInitializationRequestMessage(final PacketBuffer buffer) { diff --git a/src/main/java/li/cil/oc2/common/network/message/RobotPowerMessage.java b/src/main/java/li/cil/oc2/common/network/message/RobotPowerMessage.java index 497ec0dd..7d5ad07c 100644 --- a/src/main/java/li/cil/oc2/common/network/message/RobotPowerMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/RobotPowerMessage.java @@ -15,7 +15,7 @@ public final class RobotPowerMessage { /////////////////////////////////////////////////////////////////// public RobotPowerMessage(final RobotEntity robot, final boolean power) { - this.entityId = robot.getEntityId(); + this.entityId = robot.getId(); this.power = power; } @@ -29,7 +29,7 @@ public final class RobotPowerMessage { context.get().enqueueWork(() -> MessageUtils.withServerEntity(context, message.entityId, RobotEntity.class, (robot) -> { final ServerPlayerEntity player = context.get().getSender(); - if (player != null && robot.isEntityInRange(player, 8)) { + if (player != null && robot.closerThan(player, 8)) { if (message.power) { robot.start(); } else { diff --git a/src/main/java/li/cil/oc2/common/network/message/RobotRunStateMessage.java b/src/main/java/li/cil/oc2/common/network/message/RobotRunStateMessage.java index c2c192f3..7d0973e0 100644 --- a/src/main/java/li/cil/oc2/common/network/message/RobotRunStateMessage.java +++ b/src/main/java/li/cil/oc2/common/network/message/RobotRunStateMessage.java @@ -15,7 +15,7 @@ public final class RobotRunStateMessage { /////////////////////////////////////////////////////////////////// public RobotRunStateMessage(final RobotEntity robot) { - this.entityId = robot.getEntityId(); + this.entityId = robot.getId(); this.value = robot.getVirtualMachine().getRunState(); } @@ -33,11 +33,11 @@ public final class RobotRunStateMessage { public void fromBytes(final PacketBuffer buffer) { entityId = buffer.readVarInt(); - value = buffer.readEnumValue(VMRunState.class); + value = buffer.readEnum(VMRunState.class); } public static void toBytes(final RobotRunStateMessage message, final PacketBuffer buffer) { buffer.writeVarInt(message.entityId); - buffer.writeEnumValue(message.value); + buffer.writeEnum(message.value); } } diff --git a/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java b/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java index 44b71a72..a3688599 100644 --- a/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java +++ b/src/main/java/li/cil/oc2/common/serialization/BlobStorage.java @@ -118,7 +118,7 @@ public final class BlobStorage { */ public static void setServer(final MinecraftServer server) { synchronize(); - dataDirectory = server.func_240776_a_(BLOBS_FOLDER_NAME); + dataDirectory = server.getWorldPath(BLOBS_FOLDER_NAME); try { Files.createDirectories(dataDirectory); } catch (final IOException e) { diff --git a/src/main/java/li/cil/oc2/common/serialization/NBTSerialization.java b/src/main/java/li/cil/oc2/common/serialization/NBTSerialization.java index 1fadf3f4..a1fe03e2 100644 --- a/src/main/java/li/cil/oc2/common/serialization/NBTSerialization.java +++ b/src/main/java/li/cil/oc2/common/serialization/NBTSerialization.java @@ -132,7 +132,7 @@ public final class NBTSerialization { tag.putString(name, (String) value); } else if (type == UUID.class) { final CompoundNBT uuidTag = new CompoundNBT(); - uuidTag.putUniqueId(name, (UUID) value); + uuidTag.putUUID(name, (UUID) value); tag.put(name, uuidTag); } else { final CompoundNBT valueTag = new CompoundNBT(); @@ -277,7 +277,7 @@ public final class NBTSerialization { } else if (type == String.class) { return tag.getString(name); } else if (type == UUID.class) { - return tag.getCompound(name).getUniqueId(name); + return tag.getCompound(name).getUUID(name); } else { final CompoundNBT valueTag = tag.getCompound(name); return Ceres.getSerializer(type).deserialize(new Deserializer(valueTag), (Class) type, into); @@ -382,7 +382,7 @@ public final class NBTSerialization { public Object deserialize(final INBT tag, final Class type, @Nullable final Object into) { boolean[] data = (boolean[]) into; if (tag instanceof ByteArrayNBT) { - final byte[] convertedData = ((ByteArrayNBT) tag).getByteArray(); + final byte[] convertedData = ((ByteArrayNBT) tag).getAsByteArray(); if (data == null || data.length != convertedData.length) { data = new boolean[convertedData.length]; } @@ -404,7 +404,7 @@ public final class NBTSerialization { public Object deserialize(final INBT tag, final Class type, @Nullable final Object into) { final byte[] data = (byte[]) into; if (tag instanceof ByteArrayNBT) { - final byte[] serializedData = ((ByteArrayNBT) tag).getByteArray(); + final byte[] serializedData = ((ByteArrayNBT) tag).getAsByteArray(); if (data == null || data.length != serializedData.length) { return serializedData; } @@ -429,7 +429,7 @@ public final class NBTSerialization { public Object deserialize(final INBT tag, final Class type, @Nullable final Object into) { char[] data = (char[]) into; if (tag instanceof IntArrayNBT) { - final int[] convertedData = ((IntArrayNBT) tag).getIntArray(); + final int[] convertedData = ((IntArrayNBT) tag).getAsIntArray(); if (data == null || data.length != convertedData.length) { data = new char[convertedData.length]; } @@ -456,7 +456,7 @@ public final class NBTSerialization { public Object deserialize(final INBT tag, final Class type, @Nullable final Object into) { short[] data = (short[]) into; if (tag instanceof IntArrayNBT) { - final int[] convertedData = ((IntArrayNBT) tag).getIntArray(); + final int[] convertedData = ((IntArrayNBT) tag).getAsIntArray(); if (data == null || data.length != convertedData.length) { data = new short[convertedData.length]; } @@ -478,7 +478,7 @@ public final class NBTSerialization { public Object deserialize(final INBT tag, final Class type, @Nullable final Object into) { final int[] data = (int[]) into; if (tag instanceof IntArrayNBT) { - final int[] serializedData = ((IntArrayNBT) tag).getIntArray(); + final int[] serializedData = ((IntArrayNBT) tag).getAsIntArray(); if (data == null || data.length != serializedData.length) { return serializedData; } @@ -523,7 +523,7 @@ public final class NBTSerialization { public Object deserialize(final INBT tag, final Class type, @Nullable final Object into) { float[] data = (float[]) into; if (tag instanceof IntArrayNBT) { - final int[] convertedData = ((IntArrayNBT) tag).getIntArray(); + final int[] convertedData = ((IntArrayNBT) tag).getAsIntArray(); if (data == null || data.length != convertedData.length) { data = new float[convertedData.length]; } @@ -581,7 +581,7 @@ public final class NBTSerialization { Enum[] data = (Enum[]) into; if (tag instanceof IntArrayNBT) { - final int[] serializedData = ((IntArrayNBT) tag).getIntArray(); + final int[] serializedData = ((IntArrayNBT) tag).getAsIntArray(); if (data == null || data.length != serializedData.length) { data = (Enum[]) Array.newInstance(componentType, serializedData.length); } @@ -609,7 +609,7 @@ public final class NBTSerialization { String[] data = (String[]) into; if (tag instanceof ListNBT) { final ListNBT serializedData = (ListNBT) tag; - if (serializedData.isEmpty() || serializedData.getTagType() == NBTTagIds.TAG_STRING) { + if (serializedData.isEmpty() || serializedData.getElementType() == NBTTagIds.TAG_STRING) { if (data == null || data.length != serializedData.size()) { data = new String[serializedData.size()]; } @@ -638,7 +638,7 @@ public final class NBTSerialization { UUID[] data = (UUID[]) into; if (tag instanceof ListNBT) { final ListNBT serializedData = (ListNBT) tag; - if (serializedData.isEmpty() || serializedData.getTagType() == NBTTagIds.TAG_STRING) { + if (serializedData.isEmpty() || serializedData.getElementType() == NBTTagIds.TAG_STRING) { if (data == null || data.length != serializedData.size()) { data = new UUID[serializedData.size()]; } diff --git a/src/main/java/li/cil/oc2/common/serialization/NBTToJsonConverter.java b/src/main/java/li/cil/oc2/common/serialization/NBTToJsonConverter.java index a4fa0b44..a18d9d4e 100644 --- a/src/main/java/li/cil/oc2/common/serialization/NBTToJsonConverter.java +++ b/src/main/java/li/cil/oc2/common/serialization/NBTToJsonConverter.java @@ -14,33 +14,33 @@ public final class NBTToJsonConverter { switch (tag.getId()) { case NBTTagIds.TAG_BYTE: { - return new JsonPrimitive(((ByteNBT) tag).getByte()); + return new JsonPrimitive(((ByteNBT) tag).getAsByte()); } case NBTTagIds.TAG_SHORT: { - return new JsonPrimitive(((ShortNBT) tag).getShort()); + return new JsonPrimitive(((ShortNBT) tag).getAsShort()); } case NBTTagIds.TAG_INT: { - return new JsonPrimitive(((IntNBT) tag).getInt()); + return new JsonPrimitive(((IntNBT) tag).getAsInt()); } case NBTTagIds.TAG_LONG: { - return new JsonPrimitive(((LongNBT) tag).getLong()); + return new JsonPrimitive(((LongNBT) tag).getAsLong()); } case NBTTagIds.TAG_FLOAT: { - return new JsonPrimitive(((FloatNBT) tag).getFloat()); + return new JsonPrimitive(((FloatNBT) tag).getAsFloat()); } case NBTTagIds.TAG_DOUBLE: { - return new JsonPrimitive(((DoubleNBT) tag).getDouble()); + return new JsonPrimitive(((DoubleNBT) tag).getAsDouble()); } case NBTTagIds.TAG_BYTE_ARRAY: { final JsonArray json = new JsonArray(); - final byte[] array = ((ByteArrayNBT) tag).getByteArray(); + final byte[] array = ((ByteArrayNBT) tag).getAsByteArray(); for (int i = 0; i < array.length; i++) { json.add(array[i]); } return json; } case NBTTagIds.TAG_STRING: { - return new JsonPrimitive(tag.getString()); + return new JsonPrimitive(tag.getAsString()); } case NBTTagIds.TAG_LIST: { final JsonArray json = new JsonArray(); @@ -53,14 +53,14 @@ public final class NBTToJsonConverter { case NBTTagIds.TAG_COMPOUND: { final JsonObject json = new JsonObject(); final CompoundNBT compoundTag = (CompoundNBT) tag; - for (final String key : compoundTag.keySet()) { + for (final String key : compoundTag.getAllKeys()) { json.add(key, convert(compoundTag.get(key))); } return json; } case NBTTagIds.TAG_INT_ARRAY: { final JsonArray json = new JsonArray(); - final int[] array = ((IntArrayNBT) tag).getIntArray(); + final int[] array = ((IntArrayNBT) tag).getAsIntArray(); for (int i = 0; i < array.length; i++) { json.add(array[i]); } diff --git a/src/main/java/li/cil/oc2/common/serialization/serializers/DirectionJsonSerializer.java b/src/main/java/li/cil/oc2/common/serialization/serializers/DirectionJsonSerializer.java index 60a6fb01..d4c18e0f 100644 --- a/src/main/java/li/cil/oc2/common/serialization/serializers/DirectionJsonSerializer.java +++ b/src/main/java/li/cil/oc2/common/serialization/serializers/DirectionJsonSerializer.java @@ -24,7 +24,7 @@ public final class DirectionJsonSerializer implements JsonDeserializer } final String json = (String) visitor.getObject("value", String.class, null); - return ITextComponent.Serializer.getComponentFromJson(json); + return ITextComponent.Serializer.fromJson(json); } } diff --git a/src/main/java/li/cil/oc2/common/tileentity/AbstractTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/AbstractTileEntity.java index 1c150606..d24da42d 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/AbstractTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/AbstractTileEntity.java @@ -68,18 +68,17 @@ public abstract class AbstractTileEntity extends TileEntity { public void onLoad() { super.onLoad(); - final World world = getWorld(); - if (world == null) { + if (level == null) { return; } - if (world.isRemote()) { + if (level.isClientSide) { loadClient(); } else { loadServer(); if (needsWorldUnloadEvent) { - ServerScheduler.scheduleOnUnload(world, onWorldUnloaded); + ServerScheduler.scheduleOnUnload(level, onWorldUnloaded); } } } @@ -96,8 +95,8 @@ public abstract class AbstractTileEntity extends TileEntity { } @Override - public void remove() { - super.remove(); // -> invalidateCaps() + public void setRemoved() { + super.setRemoved(); // -> invalidateCaps() onUnload(); } @@ -122,10 +121,9 @@ public abstract class AbstractTileEntity extends TileEntity { } protected void onUnload() { - final World world = getWorld(); - if (world != null && !world.isRemote()) { + if (level != null && !level.isClientSide) { unloadServer(); - ServerScheduler.cancelOnUnload(world, onWorldUnloaded); + ServerScheduler.cancelOnUnload(level, onWorldUnloaded); } } diff --git a/src/main/java/li/cil/oc2/common/tileentity/BusCableTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/BusCableTileEntity.java index be91b6c3..d642e60a 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/BusCableTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/BusCableTileEntity.java @@ -41,21 +41,21 @@ public final class BusCableTileEntity extends AbstractTileEntity { /////////////////////////////////////////////////////////////////// public String getInterfaceName(final Direction side) { - final String interfaceName = interfaceNames[side.getIndex()]; + final String interfaceName = interfaceNames[side.get3DDataValue()]; return interfaceName == null ? "" : interfaceName; } public void setInterfaceName(final Direction side, final String name) { final String validatedName = validateName(name); - if (Objects.equals(validatedName, interfaceNames[side.getIndex()])) { + if (Objects.equals(validatedName, interfaceNames[side.get3DDataValue()])) { return; } - interfaceNames[side.getIndex()] = validatedName; - if (!getWorld().isRemote()) { - final BusInterfaceNameMessage message = new BusInterfaceNameMessage.ToClient(this, side, interfaceNames[side.getIndex()]); - Network.sendToClientsTrackingChunk(message, getWorld().getChunkAt(getPos())); - handleNeighborChanged(getPos().offset(side)); + interfaceNames[side.get3DDataValue()] = validatedName; + if (!level.isClientSide) { + final BusInterfaceNameMessage message = new BusInterfaceNameMessage.ToClient(this, side, interfaceNames[side.get3DDataValue()]); + Network.sendToClientsTrackingChunk(message, level.getChunkAt(getBlockPos())); + handleNeighborChanged(getBlockPos().relative(side)); } } @@ -73,13 +73,13 @@ public final class BusCableTileEntity extends AbstractTileEntity { setInterfaceName(side, ""); invalidateCapability(Capabilities.DEVICE_BUS_ELEMENT, side); - handleNeighborChanged(getPos().offset(side)); + handleNeighborChanged(getBlockPos().relative(side)); } } @Override - public void remove() { - super.remove(); + public void setRemoved() { + super.setRemoved(); // Bus element will usually be discovered via bus scan, not via capability request, so // automatic invalidation via capability will *not* necessarily schedule a scan on the @@ -102,8 +102,8 @@ public final class BusCableTileEntity extends AbstractTileEntity { } @Override - public CompoundNBT write(CompoundNBT tag) { - tag = super.write(tag); + public CompoundNBT save(CompoundNBT tag) { + tag = super.save(tag); tag.put(BUS_ELEMENT_TAG_NAME, busElement.serializeNBT()); tag.put(INTERFACE_NAMES_TAG_NAME, serializeInterfaceNames()); @@ -111,8 +111,8 @@ public final class BusCableTileEntity extends AbstractTileEntity { } @Override - public void read(final BlockState state, final CompoundNBT tag) { - super.read(state, tag); + public void load(final BlockState state, final CompoundNBT tag) { + super.load(state, tag); busElement.deserializeNBT(tag.getList(BUS_ELEMENT_TAG_NAME, NBTTagIds.TAG_COMPOUND)); deserializeInterfaceNames(tag.getList(INTERFACE_NAMES_TAG_NAME, NBTTagIds.TAG_STRING)); } @@ -138,7 +138,7 @@ public final class BusCableTileEntity extends AbstractTileEntity { private ListNBT serializeInterfaceNames() { final ListNBT tag = new ListNBT(); for (int i = 0; i < Constants.BLOCK_FACE_COUNT; i++) { - tag.add(StringNBT.valueOf(getInterfaceName(Direction.byIndex(i)))); + tag.add(StringNBT.valueOf(getInterfaceName(Direction.from3DDataValue(i)))); } return tag; } @@ -178,7 +178,7 @@ public final class BusCableTileEntity extends AbstractTileEntity { @Override protected void collectSyntheticDevices(final World world, final BlockPos pos, final Direction direction, final HashSet devices) { super.collectSyntheticDevices(world, pos, direction, devices); - final String interfaceName = interfaceNames[direction.getIndex()]; + final String interfaceName = interfaceNames[direction.get3DDataValue()]; if (!StringUtils.isNullOrEmpty(interfaceName)) { devices.add(new BlockDeviceInfo(null, new TypeNameRPCDevice(interfaceName))); } diff --git a/src/main/java/li/cil/oc2/common/tileentity/ChargerTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/ChargerTileEntity.java index 96280bc7..dfd5a881 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/ChargerTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/ChargerTileEntity.java @@ -37,8 +37,8 @@ public final class ChargerTileEntity extends AbstractTileEntity implements ITick } @Override - public CompoundNBT write(CompoundNBT tag) { - tag = super.write(tag); + public CompoundNBT save(CompoundNBT tag) { + tag = super.save(tag); tag.put(Constants.ENERGY_TAG_NAME, energy.serializeNBT()); @@ -46,8 +46,8 @@ public final class ChargerTileEntity extends AbstractTileEntity implements ITick } @Override - public void read(final BlockState state, final CompoundNBT tag) { - super.read(state, tag); + public void load(final BlockState state, final CompoundNBT tag) { + super.load(state, tag); energy.deserializeNBT(tag.getCompound(Constants.ENERGY_TAG_NAME)); } @@ -66,7 +66,7 @@ public final class ChargerTileEntity extends AbstractTileEntity implements ITick return; } - final TileEntity tileEntity = getWorld().getTileEntity(getPos().up()); + final TileEntity tileEntity = getLevel().getBlockEntity(getBlockPos().above()); if (tileEntity != null) { chargeCapabilityProvider(tileEntity); } @@ -77,7 +77,7 @@ public final class ChargerTileEntity extends AbstractTileEntity implements ITick return; } - final List entities = getWorld().getEntitiesInAABBexcluding(null, new AxisAlignedBB(getPos().up()), null); + final List entities = getLevel().getEntities((Entity) null, new AxisAlignedBB(getBlockPos().above()), null); for (final Entity entity : entities) { chargeCapabilityProvider(entity); } diff --git a/src/main/java/li/cil/oc2/common/tileentity/ComputerTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/ComputerTileEntity.java index 1609a597..f519d0b0 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/ComputerTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/ComputerTileEntity.java @@ -103,8 +103,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic } public void start() { - final World world = getWorld(); - if (world == null || world.isRemote()) { + if (level == null || level.isClientSide) { return; } @@ -112,8 +111,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic } public void stop() { - final World world = getWorld(); - if (world == null || world.isRemote()) { + if (level == null || level.isClientSide) { return; } @@ -124,7 +122,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic NetworkHooks.openGui(player, new INamedContainerProvider() { @Override public ITextComponent getDisplayName() { - return new TranslationTextComponent(getBlockState().getBlock().getTranslationKey()); + return new TranslationTextComponent(getBlockState().getBlock().getDescriptionId()); } @Override @@ -149,26 +147,26 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic } @Override - public int size() { + public int getCount() { return 3; } }); } - }, getPos()); + }, getBlockPos()); } public void openContainerScreen(final ServerPlayerEntity player) { NetworkHooks.openGui(player, new INamedContainerProvider() { @Override public ITextComponent getDisplayName() { - return new TranslationTextComponent(getBlockState().getBlock().getTranslationKey()); + return new TranslationTextComponent(getBlockState().getBlock().getDescriptionId()); } @Override public Container createMenu(final int id, final PlayerInventory inventory, final PlayerEntity player) { return new ComputerInventoryContainer(id, ComputerTileEntity.this, inventory); } - }, getPos()); + }, getBlockPos()); } public void addTerminalUser(final PlayerEntity player) { @@ -214,8 +212,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic @Override public void tick() { - final World world = getWorld(); - if (world == null || world.isRemote()) { + if (level == null || level.isClientSide) { return; } @@ -231,15 +228,15 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic if (isNeighborUpdateScheduled) { isNeighborUpdateScheduled = false; - world.notifyNeighborsOfStateChange(getPos(), getBlockState().getBlock()); + level.updateNeighborsAt(getBlockPos(), getBlockState().getBlock()); } virtualMachine.tick(); } @Override - public void remove() { - super.remove(); + public void setRemoved() { + super.setRemoved(); // super.remove() calls onUnload. This in turn only suspends, but we want to do // a full clean-up when we get destroyed, so stuff inside us can delete out-of-nbt @@ -266,12 +263,12 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic NBTSerialization.deserialize(tag.getCompound(TERMINAL_TAG_NAME), terminal); virtualMachine.setBusStateClient(CommonDeviceBusController.BusState.values()[tag.getInt(AbstractVirtualMachine.BUS_STATE_TAG_NAME)]); virtualMachine.setRunStateClient(VMRunState.values()[tag.getInt(AbstractVirtualMachine.RUN_STATE_TAG_NAME)]); - virtualMachine.setBootErrorClient(ITextComponent.Serializer.getComponentFromJson(tag.getString(AbstractVirtualMachine.BOOT_ERROR_TAG_NAME))); + virtualMachine.setBootErrorClient(ITextComponent.Serializer.fromJson(tag.getString(AbstractVirtualMachine.BOOT_ERROR_TAG_NAME))); } @Override - public CompoundNBT write(CompoundNBT tag) { - tag = super.write(tag); + public CompoundNBT save(final CompoundNBT tag) { + super.save(tag); tag.put(STATE_TAG_NAME, virtualMachine.serialize()); tag.put(TERMINAL_TAG_NAME, NBTSerialization.serialize(terminal)); @@ -282,8 +279,8 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic } @Override - public void read(final BlockState blockState, final CompoundNBT tag) { - super.read(blockState, tag); + public void load(final BlockState blockState, final CompoundNBT tag) { + super.load(blockState, tag); virtualMachine.deserialize(tag.getCompound(STATE_TAG_NAME)); NBTSerialization.deserialize(tag.getCompound(TERMINAL_TAG_NAME), terminal); @@ -324,7 +321,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic super.loadServer(); busElement.initialize(); - virtualMachine.state.builtinDevices.rtcMinecraft.setWorld(getWorld()); + virtualMachine.state.builtinDevices.rtcMinecraft.setWorld(level); } @Override @@ -361,7 +358,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic @Override protected void onContentsChanged(final DeviceItemStackHandler itemStackHandler, final int slot) { super.onContentsChanged(itemStackHandler, slot); - markDirty(); + setChanged(); isNeighborUpdateScheduled = true; } } @@ -382,7 +379,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic @Override public boolean canScanContinueTowards(@Nullable final Direction direction) { - return getBlockState().get(ComputerBlock.HORIZONTAL_FACING) != direction; + return getBlockState().getValue(ComputerBlock.FACING) != direction; } } @@ -411,7 +408,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic if (value == VMRunState.RUNNING) { if (!LoopingSoundManager.isPlaying(ComputerTileEntity.this)) { - LoopingSoundManager.play(ComputerTileEntity.this, SoundEvents.COMPUTER_RUNNING.get(), getWorld().getRandom().nextInt(MAX_RUNNING_SOUND_DELAY)); + LoopingSoundManager.play(ComputerTileEntity.this, SoundEvents.COMPUTER_RUNNING.get(), level.getRandom().nextInt(MAX_RUNNING_SOUND_DELAY)); } } else { LoopingSoundManager.stop(ComputerTileEntity.this); @@ -421,11 +418,11 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic @Override public void tick() { if (chunk == null) { - chunk = world.getChunkAt(getPos()); + chunk = level.getChunkAt(getBlockPos()); } if (isRunning()) { - chunk.markDirty(); + chunk.markUnsaved(); } super.tick(); @@ -465,7 +462,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements ITic if (value == CommonDeviceBusController.BusState.READY) { // Bus just became ready, meaning new devices may be available, meaning new // capabilities may be available, so we need to tell our neighbors. - world.notifyNeighborsOfStateChange(getPos(), getBlockState().getBlock()); + level.updateNeighborsAt(getBlockPos(), getBlockState().getBlock()); } } diff --git a/src/main/java/li/cil/oc2/common/tileentity/CreativeEnergyTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/CreativeEnergyTileEntity.java index 488f239e..9a927e22 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/CreativeEnergyTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/CreativeEnergyTileEntity.java @@ -21,10 +21,10 @@ public final class CreativeEnergyTileEntity extends TileEntity implements ITicka @Override public void tick() { for (final Direction side : SIDES) { - final BlockPos neighborPos = getPos().offset(side); + final BlockPos neighborPos = getBlockPos().relative(side); final ChunkPos neighborChunkPos = new ChunkPos(neighborPos); - if (getWorld().chunkExists(neighborChunkPos.x, neighborChunkPos.z)) { - final TileEntity tileEntity = getWorld().getTileEntity(neighborPos); + if (getLevel().hasChunk(neighborChunkPos.x, neighborChunkPos.z)) { + final TileEntity tileEntity = getLevel().getBlockEntity(neighborPos); if (tileEntity != null) { tileEntity.getCapability(Capabilities.ENERGY_STORAGE, side.getOpposite()).ifPresent(energy -> { energy.receiveEnergy(Integer.MAX_VALUE, false); diff --git a/src/main/java/li/cil/oc2/common/tileentity/DiskDriveTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/DiskDriveTileEntity.java index 8591504f..ecc227e4 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/DiskDriveTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/DiskDriveTileEntity.java @@ -89,8 +89,8 @@ public final class DiskDriveTileEntity extends AbstractTileEntity { public void eject() { final ItemStack stack = itemHandler.extractItem(0, 1, false); if (!stack.isEmpty()) { - final Direction facing = getBlockState().get(DiskDriveBlock.HORIZONTAL_FACING); - ItemStackUtils.spawnAsEntity(getWorld(), getPos().offset(facing), stack, facing); + final Direction facing = getBlockState().getValue(DiskDriveBlock.FACING); + ItemStackUtils.spawnAsEntity(level, getBlockPos().relative(facing), stack, facing); ejectSoundEmitter.play(); } } @@ -123,8 +123,8 @@ public final class DiskDriveTileEntity extends AbstractTileEntity { } @Override - public CompoundNBT write(CompoundNBT tag) { - tag = super.write(tag); + public CompoundNBT save(CompoundNBT tag) { + tag = super.save(tag); tag.put(Constants.ITEMS_TAG_NAME, itemHandler.serializeNBT()); @@ -132,8 +132,8 @@ public final class DiskDriveTileEntity extends AbstractTileEntity { } @Override - public void read(final BlockState state, final CompoundNBT tag) { - super.read(state, tag); + public void load(final BlockState state, final CompoundNBT tag) { + super.load(state, tag); itemHandler.deserializeNBT(tag.getCompound(Constants.ITEMS_TAG_NAME)); } @@ -174,8 +174,7 @@ public final class DiskDriveTileEntity extends AbstractTileEntity { protected void onContentsChanged(final int slot) { super.onContentsChanged(slot); - final World world = getWorld(); - if (world == null || world.isRemote()) { + if (level == null || level.isClientSide) { return; } @@ -187,7 +186,7 @@ public final class DiskDriveTileEntity extends AbstractTileEntity { device.updateBlockDevice(tag); } - Network.sendToClientsTrackingChunk(new DiskDriveFloppyMessage(DiskDriveTileEntity.this), world.getChunkAt(getPos())); + Network.sendToClientsTrackingChunk(new DiskDriveFloppyMessage(DiskDriveTileEntity.this), level.getChunkAt(getBlockPos())); } private void exportDeviceDataToItemStack(final ItemStack stack) { @@ -195,8 +194,7 @@ public final class DiskDriveTileEntity extends AbstractTileEntity { return; } - final World world = getWorld(); - if (world == null || world.isRemote()) { + if (level == null || level.isClientSide) { return; } diff --git a/src/main/java/li/cil/oc2/common/tileentity/NetworkConnectorTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/NetworkConnectorTileEntity.java index c9d2a2ee..e5a86e56 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/NetworkConnectorTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/NetworkConnectorTileEntity.java @@ -81,12 +81,12 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme return ConnectionResult.FAILURE; } - final World world = connectorA.getWorld(); - if (world == null || world.isRemote()) { + final World world = connectorA.level; + if (world == null || world.isClientSide) { return ConnectionResult.FAILURE; } - if (connectorB.getWorld() != world) { + if (connectorB.level != world) { return ConnectionResult.FAILURE; } @@ -94,10 +94,10 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme return ConnectionResult.FAILURE_FULL; } - final BlockPos posA = connectorA.getPos(); - final BlockPos posB = connectorB.getPos(); + final BlockPos posA = connectorA.getBlockPos(); + final BlockPos posB = connectorB.getBlockPos(); - if (!posA.withinDistance(posB, MAX_CONNECTION_DISTANCE)) { + if (!posA.closerThan(posB, MAX_CONNECTION_DISTANCE)) { return ConnectionResult.FAILURE_TOO_FAR; } @@ -125,8 +125,8 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme result = ConnectionResult.SUCCESS; } - connectorA.markDirty(); - connectorB.markDirty(); + connectorA.setChanged(); + connectorB.setChanged(); return result; } @@ -136,10 +136,9 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme connectors.remove(pos); if (ownedCables.remove(pos)) { - final World world = getWorld(); - if (world != null) { - final Vector3d middle = Vector3d.copyCentered(getPos().add(pos)).scale(0.5f); - ItemStackUtils.spawnAsEntity(world, middle, new ItemStack(Items.NETWORK_CABLE.get())); + if (level != null) { + final Vector3d middle = Vector3d.atCenterOf(getBlockPos().offset(pos)).scale(0.5f); + ItemStackUtils.spawnAsEntity(level, middle, new ItemStack(Items.NETWORK_CABLE.get())); } } @@ -148,7 +147,7 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme onConnectedPositionsChanged(); } - markDirty(); + setChanged(); } } @@ -224,8 +223,8 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme } @Override - public CompoundNBT write(CompoundNBT tag) { - tag = super.write(tag); + public CompoundNBT save(CompoundNBT tag) { + tag = super.save(tag); final ListNBT connections = new ListNBT(); for (final BlockPos position : connectorPositions) { @@ -241,8 +240,8 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme } @Override - public void read(final BlockState state, final CompoundNBT tag) { - super.read(state, tag); + public void load(final BlockState state, final CompoundNBT tag) { + super.load(state, tag); final ListNBT connections = tag.getList(CONNECTIONS_TAG_NAME, NBTTagIds.TAG_COMPOUND); for (int i = 0; i < Math.min(connections.size(), MAX_CONNECTION_COUNT); i++) { @@ -264,16 +263,16 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme } @Override - public void remove() { - super.remove(); + public void setRemoved() { + super.setRemoved(); // When we're being removed we want to break the actual link to any connected // connectors. This will also cause cables to be dropped. final ArrayList list = new ArrayList<>(connectors.values()); connectors.clear(); for (final NetworkConnectorTileEntity connector : list) { - disconnectFrom(connector.getPos()); - connector.disconnectFrom(getPos()); + disconnectFrom(connector.getBlockPos()); + connector.disconnectFrom(getBlockPos()); } } @@ -283,7 +282,7 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme // When unloading, we just want to remove the reference to this tile entity // from connected connectors; we don't want to actually break the link. - final BlockPos pos = getPos(); + final BlockPos pos = getBlockPos(); for (final NetworkConnectorTileEntity connector : connectors.values()) { connector.connectors.remove(pos); if (connector.connectorPositions.contains(pos)) { @@ -294,8 +293,11 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme @Override public AxisAlignedBB getRenderBoundingBox() { - if (Minecraft.isFabulousGraphicsEnabled()) { - return new AxisAlignedBB(pos.add(-MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE), pos.add(1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE)); + if (Minecraft.useShaderTransparency()) { + return new AxisAlignedBB( + getBlockPos().offset(-MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE), + getBlockPos().offset(1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE) + ); } else { return super.getRenderBoundingBox(); } @@ -319,21 +321,20 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme return; } - final World world = getWorld(); - if (world == null || world.isRemote()) { + if (level == null || level.isClientSide) { return; } final Direction facing = NetworkConnectorBlock.getFacing(getBlockState()); - final BlockPos sourcePos = getPos().offset(facing.getOpposite()); + final BlockPos sourcePos = getBlockPos().relative(facing.getOpposite()); final ChunkPos sourceChunk = new ChunkPos(sourcePos); - if (!world.chunkExists(sourceChunk.x, sourceChunk.z)) { - ServerScheduler.schedule(world, this::setLocalInterfaceChanged, RETRY_UNLOADED_CHUNK_INTERVAL); + if (!level.hasChunk(sourceChunk.x, sourceChunk.z)) { + ServerScheduler.schedule(level, this::setLocalInterfaceChanged, RETRY_UNLOADED_CHUNK_INTERVAL); return; } - final TileEntity tileEntity = world.getTileEntity(sourcePos); + final TileEntity tileEntity = level.getBlockEntity(sourcePos); if (tileEntity == null) { return; } @@ -351,18 +352,17 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme return; } - final World world = getWorld(); - if (world == null || world.isRemote()) { + if (level == null || level.isClientSide) { return; } final ChunkPos destinationChunk = new ChunkPos(connectedPosition); - if (!world.chunkExists(destinationChunk.x, destinationChunk.z)) { - ServerScheduler.schedule(world, () -> dirtyConnectors.add(connectedPosition), RETRY_UNLOADED_CHUNK_INTERVAL); + if (!level.hasChunk(destinationChunk.x, destinationChunk.z)) { + ServerScheduler.schedule(level, () -> dirtyConnectors.add(connectedPosition), RETRY_UNLOADED_CHUNK_INTERVAL); return; } - final TileEntity tileEntity = world.getTileEntity(connectedPosition); + final TileEntity tileEntity = level.getBlockEntity(connectedPosition); if (!(tileEntity instanceof NetworkConnectorTileEntity)) { disconnectFrom(connectedPosition); return; @@ -370,15 +370,15 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme final NetworkConnectorTileEntity connector = (NetworkConnectorTileEntity) tileEntity; - if (!connectedPosition.withinDistance(getPos(), MAX_CONNECTION_DISTANCE)) { + if (!connectedPosition.closerThan(getBlockPos(), MAX_CONNECTION_DISTANCE)) { disconnectFrom(connectedPosition); - connector.disconnectFrom(getPos()); + connector.disconnectFrom(getBlockPos()); return; } - if (isObstructed(world, getPos(), connectedPosition)) { + if (isObstructed(level, getBlockPos(), connectedPosition)) { disconnectFrom(connectedPosition); - connector.disconnectFrom(getPos()); + connector.disconnectFrom(getBlockPos()); return; } @@ -386,21 +386,21 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme } private static boolean isObstructed(final World world, final BlockPos a, final BlockPos b) { - final Vector3d va = Vector3d.copyCentered(a); - final Vector3d vb = Vector3d.copyCentered(b); + final Vector3d va = Vector3d.atCenterOf(a); + final Vector3d vb = Vector3d.atCenterOf(b); final Vector3d ab = vb.subtract(va).normalize().scale(0.5); // Because of floating point inaccuracies the raytrace is not necessarily // symmetric. In particular when grazing corners perfectly, e.g. two connectors // attached to the same block at a 90 degree angle. So we check both ways. - final BlockRayTraceResult hitAB = world.rayTraceBlocks(new RayTraceContext( + final BlockRayTraceResult hitAB = world.clip(new RayTraceContext( va.add(ab), vb.subtract(ab), RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, null )); - final BlockRayTraceResult hitBA = world.rayTraceBlocks(new RayTraceContext( + final BlockRayTraceResult hitBA = world.clip(new RayTraceContext( vb.subtract(ab), va.add(ab), RayTraceContext.BlockMode.COLLIDER, @@ -413,10 +413,10 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity impleme } private void onConnectedPositionsChanged() { - final World world = getWorld(); - if (world != null && !world.isRemote()) { + + if (level != null && !level.isClientSide) { final NetworkConnectorConnectionsMessage message = new NetworkConnectorConnectionsMessage(this); - final Chunk chunk = world.getChunkAt(getPos()); + final Chunk chunk = level.getChunkAt(getBlockPos()); Network.sendToClientsTrackingChunk(message, chunk); } } diff --git a/src/main/java/li/cil/oc2/common/tileentity/NetworkHubTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/NetworkHubTileEntity.java index 61fc584e..58d71ca8 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/NetworkHubTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/NetworkHubTileEntity.java @@ -63,20 +63,20 @@ public final class NetworkHubTileEntity extends AbstractTileEntity implements Ne areAdjacentInterfacesDirty = false; - final World world = getWorld(); - if (world == null || world.isRemote()) { + final World world = getLevel(); + if (world == null || world.isClientSide) { return; } - final BlockPos pos = getPos(); + final BlockPos pos = getBlockPos(); for (final Direction side : Constants.DIRECTIONS) { - adjacentInterfaces[side.getIndex()] = null; + adjacentInterfaces[side.get3DDataValue()] = null; - final TileEntity neighborTileEntity = world.getTileEntity(pos.offset(side)); + final TileEntity neighborTileEntity = world.getBlockEntity(pos.relative(side)); if (neighborTileEntity != null) { final LazyOptional capability = neighborTileEntity.getCapability(Capabilities.NETWORK_INTERFACE, side.getOpposite()); capability.ifPresent(adjacentInterface -> { - adjacentInterfaces[side.getIndex()] = adjacentInterface; + adjacentInterfaces[side.get3DDataValue()] = adjacentInterface; capability.addListener(unused -> handleNeighborChanged()); }); } diff --git a/src/main/java/li/cil/oc2/common/tileentity/RedstoneInterfaceTileEntity.java b/src/main/java/li/cil/oc2/common/tileentity/RedstoneInterfaceTileEntity.java index 3c0e30c4..bfa3820b 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/RedstoneInterfaceTileEntity.java +++ b/src/main/java/li/cil/oc2/common/tileentity/RedstoneInterfaceTileEntity.java @@ -41,15 +41,15 @@ public final class RedstoneInterfaceTileEntity extends TileEntity implements Nam /////////////////////////////////////////////////////////////////// @Override - public CompoundNBT write(CompoundNBT compound) { - compound = super.write(compound); + public CompoundNBT save(CompoundNBT compound) { + compound = super.save(compound); compound.putByteArray(OUTPUT_TAG_NAME, output); return compound; } @Override - public void read(final BlockState state, final CompoundNBT compound) { - super.read(state, compound); + public void load(final BlockState state, final CompoundNBT compound) { + super.load(state, compound); final byte[] serializedOutput = compound.getByteArray(OUTPUT_TAG_NAME); System.arraycopy(serializedOutput, 0, output, 0, Math.min(serializedOutput.length, output.length)); } @@ -58,49 +58,49 @@ public final class RedstoneInterfaceTileEntity extends TileEntity implements Nam final Direction localDirection = HorizontalBlockUtils.toLocal(getBlockState(), direction); assert localDirection != null; - return output[localDirection.getIndex()]; + return output[localDirection.get3DDataValue()]; } @Callback(name = GET_REDSTONE_INPUT) - public int getRedstoneInput(@Parameter(SIDE) final Direction side) { - final World world = getWorld(); + public int setRedstoneSignal(@Parameter(SIDE) final Direction side) { + final World world = getLevel(); if (world == null) { return 0; } - final BlockPos pos = getPos(); + final BlockPos pos = getBlockPos(); final Direction direction = HorizontalBlockUtils.toGlobal(getBlockState(), side); assert direction != null; - final BlockPos neighborPos = pos.offset(direction); + final BlockPos neighborPos = pos.relative(direction); final ChunkPos chunkPos = new ChunkPos(neighborPos.getX(), neighborPos.getZ()); - if (!world.chunkExists(chunkPos.x, chunkPos.z)) { + if (!world.hasChunk(chunkPos.x, chunkPos.z)) { return 0; } - return world.getRedstonePower(neighborPos, direction); + return world.getSignal(neighborPos, direction); } @Callback(name = GET_REDSTONE_OUTPUT, synchronize = false) - public int getRedstoneOutput(@Parameter(SIDE) final Direction side) { - return output[side.getIndex()]; + public int getRedstoneSignal(@Parameter(SIDE) final Direction side) { + return output[side.get3DDataValue()]; } @Callback(name = SET_REDSTONE_OUTPUT) - public void setRedstoneOutput(@Parameter(SIDE) final Direction side, @Parameter(VALUE) final int value) { + public void getRedstoneSignal(@Parameter(SIDE) final Direction side, @Parameter(VALUE) final int value) { final byte clampedValue = (byte) MathHelper.clamp(value, 0, 15); - if (clampedValue == output[side.getIndex()]) { + if (clampedValue == output[side.get3DDataValue()]) { return; } - output[side.getIndex()] = clampedValue; + output[side.get3DDataValue()] = clampedValue; final Direction direction = HorizontalBlockUtils.toGlobal(getBlockState(), side); if (direction != null) { notifyNeighbor(direction); } - markDirty(); + setChanged(); } @Override @@ -137,12 +137,12 @@ public final class RedstoneInterfaceTileEntity extends TileEntity implements Nam /////////////////////////////////////////////////////////////////// private void notifyNeighbor(final Direction direction) { - final World world = getWorld(); + final World world = getLevel(); if (world == null) { return; } - world.notifyNeighborsOfStateChange(getPos(), getBlockState().getBlock()); - world.notifyNeighborsOfStateChange(getPos().offset(direction), getBlockState().getBlock()); + world.updateNeighborsAt(getBlockPos(), getBlockState().getBlock()); + world.updateNeighborsAt(getBlockPos().relative(direction), getBlockState().getBlock()); } } diff --git a/src/main/java/li/cil/oc2/common/tileentity/TileEntities.java b/src/main/java/li/cil/oc2/common/tileentity/TileEntities.java index cc7a33ae..990e4cb2 100644 --- a/src/main/java/li/cil/oc2/common/tileentity/TileEntities.java +++ b/src/main/java/li/cil/oc2/common/tileentity/TileEntities.java @@ -36,6 +36,6 @@ public final class TileEntities { @SuppressWarnings("ConstantConditions") // .build(null) is fine private static RegistryObject> register(final RegistryObject block, final Supplier factory) { - return TILES.register(block.getId().getPath(), () -> TileEntityType.Builder.create(factory, block.get()).build(null)); + return TILES.register(block.getId().getPath(), () -> TileEntityType.Builder.of(factory, block.get()).build(null)); } } diff --git a/src/main/java/li/cil/oc2/common/util/FakePlayerUtils.java b/src/main/java/li/cil/oc2/common/util/FakePlayerUtils.java index f4023e6b..70fc362e 100644 --- a/src/main/java/li/cil/oc2/common/util/FakePlayerUtils.java +++ b/src/main/java/li/cil/oc2/common/util/FakePlayerUtils.java @@ -24,11 +24,11 @@ public final class FakePlayerUtils { public static ServerPlayerEntity getFakePlayer(final ServerWorld world, final Entity entity) { final ServerPlayerEntity player = getFakePlayer(world); - player.copyLocationAndAnglesFrom(entity); - player.prevRotationPitch = player.rotationPitch; - player.prevRotationYaw = player.rotationYaw; - player.rotationYawHead = player.rotationYaw; - player.prevRotationYawHead = player.rotationYawHead; + player.copyPosition(entity); + player.xRotO = player.xRot; + player.yRotO = player.yRot; + player.yHeadRot = player.yRot; + player.yHeadRotO = player.yHeadRot; return player; } @@ -52,7 +52,7 @@ public final class FakePlayerUtils { } @Override - public void sendPacket(final IPacket packetIn, @Nullable final GenericFutureListener> futureListeners) { + public void send(final IPacket packetIn, @Nullable final GenericFutureListener> futureListeners) { } } } diff --git a/src/main/java/li/cil/oc2/common/util/HorizontalBlockUtils.java b/src/main/java/li/cil/oc2/common/util/HorizontalBlockUtils.java index 8935addb..59e35a1c 100644 --- a/src/main/java/li/cil/oc2/common/util/HorizontalBlockUtils.java +++ b/src/main/java/li/cil/oc2/common/util/HorizontalBlockUtils.java @@ -17,19 +17,19 @@ public final class HorizontalBlockUtils { return null; } - final int index = direction.getHorizontalIndex(); + final int index = direction.get2DDataValue(); if (index < 0) { return direction; } - if (!blockState.hasProperty(HorizontalBlock.HORIZONTAL_FACING)) { + if (!blockState.hasProperty(HorizontalBlock.FACING)) { return direction; } - final Direction facing = blockState.get(HorizontalBlock.HORIZONTAL_FACING); - final int toLocal = HORIZONTAL_DIRECTION_COUNT - facing.getHorizontalIndex(); + final Direction facing = blockState.getValue(HorizontalBlock.FACING); + final int toLocal = HORIZONTAL_DIRECTION_COUNT - facing.get2DDataValue(); final int rotatedIndex = (index + toLocal) % HORIZONTAL_DIRECTION_COUNT; - return Direction.byHorizontalIndex(rotatedIndex); + return Direction.from2DDataValue(rotatedIndex); } @Nullable @@ -38,18 +38,18 @@ public final class HorizontalBlockUtils { return null; } - final int index = direction.getHorizontalIndex(); + final int index = direction.get2DDataValue(); if (index < 0) { return direction; } - if (!blockState.hasProperty(HorizontalBlock.HORIZONTAL_FACING)) { + if (!blockState.hasProperty(HorizontalBlock.FACING)) { return direction; } - final Direction facing = blockState.get(HorizontalBlock.HORIZONTAL_FACING); - final int toGlobal = facing.getHorizontalIndex(); + final Direction facing = blockState.getValue(HorizontalBlock.FACING); + final int toGlobal = facing.get2DDataValue(); final int rotatedIndex = (index + toGlobal) % HORIZONTAL_DIRECTION_COUNT; - return Direction.byHorizontalIndex(rotatedIndex); + return Direction.from2DDataValue(rotatedIndex); } } diff --git a/src/main/java/li/cil/oc2/common/util/ItemStackUtils.java b/src/main/java/li/cil/oc2/common/util/ItemStackUtils.java index 03cde38a..223ffae8 100644 --- a/src/main/java/li/cil/oc2/common/util/ItemStackUtils.java +++ b/src/main/java/li/cil/oc2/common/util/ItemStackUtils.java @@ -24,32 +24,32 @@ public final class ItemStackUtils { } public static Optional spawnAsEntity(final World world, final BlockPos pos, final ItemStack stack) { - return spawnAsEntity(world, Vector3d.copyCentered(pos), stack); + return spawnAsEntity(world, Vector3d.atCenterOf(pos), stack); } public static Optional spawnAsEntity(final World world, final Vector3d pos, final ItemStack stack) { - if (world.isRemote() || stack.isEmpty()) { + if (world.isClientSide() || stack.isEmpty()) { return Optional.empty(); } - final Random rng = world.rand; + final Random rng = world.random; final float tx = 0.5f * (rng.nextFloat() - 1.0f); final float ty = 0.5f * (rng.nextFloat() - 1.0f); final float tz = 0.5f * (rng.nextFloat() - 1.0f); - final double px = pos.getX() + tx; - final double py = pos.getY() + ty; - final double pz = pos.getZ() + tz; + final double px = pos.x + tx; + final double py = pos.y + ty; + final double pz = pos.z + tz; final ItemEntity entity = new ItemEntity(world, px, py, pz, stack); - entity.setDefaultPickupDelay(); - world.addEntity(entity); + entity.setDefaultPickUpDelay(); + world.addFreshEntity(entity); return Optional.of(entity); } public static Optional spawnAsEntity(final World world, final BlockPos pos, final ItemStack stack, @Nullable final Direction direction) { - return spawnAsEntity(world, Vector3d.copyCentered(pos), stack, direction); + return spawnAsEntity(world, Vector3d.atCenterOf(pos), stack, direction); } public static Optional spawnAsEntity(final World world, final Vector3d pos, final ItemStack stack, @Nullable final Direction direction) { @@ -57,32 +57,32 @@ public final class ItemStackUtils { return spawnAsEntity(world, pos, stack); } - if (world.isRemote() || stack.isEmpty()) { + if (world.isClientSide || stack.isEmpty()) { return Optional.empty(); } - final Random rng = world.rand; + final Random rng = world.random; - final float ox = direction.getXOffset(); - final float oy = direction.getYOffset(); - final float oz = direction.getZOffset(); + final float ox = direction.getStepX(); + final float oy = direction.getStepY(); + final float oz = direction.getStepZ(); final float tx = 0.1f * (rng.nextFloat() - 0.5f) + ox * 0.65f; final float ty = 0.1f * (rng.nextFloat() - 0.5f) + oy * 0.75f + (ox + oz) * 0.25f; final float tz = 0.1f * (rng.nextFloat() - 0.5f) + oz * 0.65f; - final double px = pos.getX() + tx; - final double py = pos.getY() + ty; - final double pz = pos.getZ() + tz; + final double px = pos.x + tx; + final double py = pos.y + ty; + final double pz = pos.z + tz; final ItemEntity entity = new ItemEntity(world, px, py, pz, stack); - entity.setMotion( + entity.moveTo( 0.0125 * (rng.nextDouble() - 0.5) + ox * 0.03, 0.0125 * (rng.nextDouble() - 0.5) + oy * 0.08 + (ox + oz) * 0.03, 0.0125 * (rng.nextDouble() - 0.5) + oz * 0.03 ); - entity.setDefaultPickupDelay(); - world.addEntity(entity); + entity.setDefaultPickUpDelay(); + world.addFreshEntity(entity); return Optional.of(entity); } diff --git a/src/main/java/li/cil/oc2/common/util/Location.java b/src/main/java/li/cil/oc2/common/util/Location.java index 6d7cf42d..33f41d1b 100644 --- a/src/main/java/li/cil/oc2/common/util/Location.java +++ b/src/main/java/li/cil/oc2/common/util/Location.java @@ -5,6 +5,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorld; +import java.util.Objects; import java.util.Optional; public final class Location { @@ -18,7 +19,7 @@ public final class Location { public static Optional of(final Entity entity) { if (entity.isAlive()) { - return Optional.of(new Location(entity.getEntityWorld(), entity.getPosition())); + return Optional.of(new Location(entity.level, entity.blockPosition())); } else { return Optional.empty(); } @@ -26,7 +27,7 @@ public final class Location { public static Optional of(final TileEntity tileEntity) { if (!tileEntity.isRemoved()) { - return Optional.of(new Location(tileEntity.getWorld(), tileEntity.getPos())); + return Optional.of(new Location(Objects.requireNonNull(tileEntity.getLevel()), tileEntity.getBlockPos())); } else { return Optional.empty(); } diff --git a/src/main/java/li/cil/oc2/common/util/LocationSupplierUtils.java b/src/main/java/li/cil/oc2/common/util/LocationSupplierUtils.java index e73d9bbe..320189e4 100644 --- a/src/main/java/li/cil/oc2/common/util/LocationSupplierUtils.java +++ b/src/main/java/li/cil/oc2/common/util/LocationSupplierUtils.java @@ -18,7 +18,7 @@ public final class LocationSupplierUtils { } public static Supplier> of(final BlockDeviceQuery query) { - final Optional location = Optional.of(new Location(query.getWorld(), query.getQueryPosition())); + final Optional location = Optional.of(new Location(query.getLevel(), query.getQueryPosition())); return () -> location; } diff --git a/src/main/java/li/cil/oc2/common/util/NBTUtils.java b/src/main/java/li/cil/oc2/common/util/NBTUtils.java index 5e773087..175e8f22 100644 --- a/src/main/java/li/cil/oc2/common/util/NBTUtils.java +++ b/src/main/java/li/cil/oc2/common/util/NBTUtils.java @@ -56,6 +56,6 @@ public final class NBTUtils { } public static CompoundNBT makeInventoryTag(final ItemStack... items) { - return new ItemStackHandler(NonNullList.from(ItemStack.EMPTY, items)).serializeNBT(); + return new ItemStackHandler(NonNullList.of(ItemStack.EMPTY, items)).serializeNBT(); } } diff --git a/src/main/java/li/cil/oc2/common/util/ResourceUtils.java b/src/main/java/li/cil/oc2/common/util/ResourceUtils.java index c306b7bc..09e6f734 100644 --- a/src/main/java/li/cil/oc2/common/util/ResourceUtils.java +++ b/src/main/java/li/cil/oc2/common/util/ResourceUtils.java @@ -24,18 +24,18 @@ public final class ResourceUtils { try (final IResource metadataResource = manager.getResource(metadataLocation)) { final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(metadataResource.getInputStream(), StandardCharsets.UTF_8)); - final JsonObject metadataJson = JSONUtils.fromJson(bufferedReader); + final JsonObject metadataJson = JSONUtils.parse(bufferedReader); if (metadataJson == null) { return null; } - final String sectionName = serializer.getSectionName(); + final String sectionName = serializer.getMetadataSectionName(); if (!metadataJson.has(sectionName)) { return null; } - final JsonObject section = JSONUtils.getJsonObject(metadataJson, sectionName); - return serializer.deserialize(section); + final JsonObject section = JSONUtils.convertToJsonObject(metadataJson, sectionName); + return serializer.fromJson(section); } } } diff --git a/src/main/java/li/cil/oc2/common/util/ServerScheduler.java b/src/main/java/li/cil/oc2/common/util/ServerScheduler.java index f4d27c6d..f5d2e357 100644 --- a/src/main/java/li/cil/oc2/common/util/ServerScheduler.java +++ b/src/main/java/li/cil/oc2/common/util/ServerScheduler.java @@ -131,7 +131,7 @@ public final class ServerScheduler { @SubscribeEvent public static void handleChunkLoad(final ChunkEvent.Load event) { - final HashMap chunkMap = chunkLoadSchedulers.get(event.getWorld()); + final HashMap chunkMap = chunkLoadSchedulers.get(event.getChunk()); if (chunkMap == null) { return; } @@ -144,7 +144,7 @@ public final class ServerScheduler { @SubscribeEvent public static void handleChunkUnload(final ChunkEvent.Unload event) { - final HashMap chunkMap = chunkUnloadSchedulers.get(event.getWorld()); + final HashMap chunkMap = chunkUnloadSchedulers.get(event.getChunk()); if (chunkMap == null) { return; } diff --git a/src/main/java/li/cil/oc2/common/util/TooltipUtils.java b/src/main/java/li/cil/oc2/common/util/TooltipUtils.java index a32093bf..e08b00e8 100644 --- a/src/main/java/li/cil/oc2/common/util/TooltipUtils.java +++ b/src/main/java/li/cil/oc2/common/util/TooltipUtils.java @@ -26,7 +26,7 @@ import static li.cil.oc2.common.Constants.*; public final class TooltipUtils { private static final IFormattableTextComponent DEVICE_NEEDS_REBOOT = new TranslationTextComponent(Constants.TOOLTIP_DEVICE_NEEDS_REBOOT) - .modifyStyle(s -> s.setColor(Color.fromTextFormatting(TextFormatting.YELLOW))); + .withStyle(s -> s.withColor(Color.fromLegacyFormat(TextFormatting.YELLOW))); private static final ThreadLocal> ITEM_STACKS = ThreadLocal.withInitial(ArrayList::new); private static final ThreadLocal ITEM_STACKS_SIZES = ThreadLocal.withInitial(IntArrayList::new); @@ -38,9 +38,9 @@ public final class TooltipUtils { return; } - final String translationKey = stack.getTranslationKey() + Constants.TOOLTIP_DESCRIPTION_SUFFIX; + final String translationKey = stack.getDescriptionId() + Constants.TOOLTIP_DESCRIPTION_SUFFIX; final LanguageMap languagemap = LanguageMap.getInstance(); - if (languagemap.func_230506_b_(translationKey)) { + if (languagemap.has(translationKey)) { final TranslationTextComponent description = new TranslationTextComponent(translationKey); tooltip.add(withColor(description, TextFormatting.GRAY)); } @@ -48,7 +48,7 @@ public final class TooltipUtils { // Tooltips get queried very early in Minecraft initialization, meaning tags may not // have been initialized. Trying to directly use our tag would lead to an exception // in that case, so we do the detour through the collection instead. - final ITag tag = net.minecraft.tags.ItemTags.getCollection().get(ItemTags.DEVICE_NEEDS_REBOOT.getName()); + final ITag tag = net.minecraft.tags.ItemTags.getAllTags().getTag(ItemTags.DEVICE_NEEDS_REBOOT.getName()); if (tag != null && tag.contains(stack.getItem())) { tooltip.add(DEVICE_NEEDS_REBOOT); } @@ -91,10 +91,10 @@ public final class TooltipUtils { final ItemStack itemStack = itemStacks.get(i); tooltip.add(new StringTextComponent("- ") .append(itemStack.getDisplayName()) - .modifyStyle(style -> style.setColor(Color.fromTextFormatting(TextFormatting.GRAY))) + .withStyle(style -> style.withColor(Color.fromLegacyFormat(TextFormatting.GRAY))) .append(new StringTextComponent(" x") - .appendString(String.valueOf(itemStackSizes.getInt(i))) - .modifyStyle(style -> style.setColor(Color.fromTextFormatting(TextFormatting.DARK_GRAY)))) + .append(String.valueOf(itemStackSizes.getInt(i))) + .withStyle(style -> style.withColor(Color.fromLegacyFormat(TextFormatting.DARK_GRAY)))) ); } } @@ -121,7 +121,7 @@ public final class TooltipUtils { } public static IFormattableTextComponent withColor(final IFormattableTextComponent text, final TextFormatting formatting) { - return text.modifyStyle(s -> s.setColor(Color.fromTextFormatting(formatting))); + return text.withStyle(s -> s.withColor(Color.fromLegacyFormat(formatting))); } /////////////////////////////////////////////////////////////////// @@ -140,13 +140,13 @@ public final class TooltipUtils { final ListNBT itemsTag = tag.getList("Items", NBTTagIds.TAG_COMPOUND); for (int i = 0; i < itemsTag.size(); i++) { final CompoundNBT itemTag = itemsTag.getCompound(i); - final ItemStack itemStack = ItemStack.read(itemTag); + final ItemStack itemStack = ItemStack.of(itemTag); boolean didMerge = false; for (int j = 0; j < stacks.size(); j++) { final ItemStack existingStack = stacks.get(j); - if (ItemStack.areItemsEqual(existingStack, itemStack) && - ItemStack.areItemStackTagsEqual(existingStack, itemStack)) { + if (ItemStack.matches(existingStack, itemStack) && + ItemStack.matches(existingStack, itemStack)) { final int existingCount = stackSizes.getInt(j); stackSizes.set(j, existingCount + itemStack.getCount()); didMerge = true; diff --git a/src/main/java/li/cil/oc2/common/util/VoxelShapeUtils.java b/src/main/java/li/cil/oc2/common/util/VoxelShapeUtils.java index 843648c1..6be2aa9a 100644 --- a/src/main/java/li/cil/oc2/common/util/VoxelShapeUtils.java +++ b/src/main/java/li/cil/oc2/common/util/VoxelShapeUtils.java @@ -8,9 +8,9 @@ public final class VoxelShapeUtils { public static VoxelShape rotateHorizontalClockwise(final VoxelShape shape) { TEMP_SHAPE.set(VoxelShapes.empty()); - shape.forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> { + shape.forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> { TEMP_SHAPE.set(VoxelShapes.or(TEMP_SHAPE.get(), - VoxelShapes.create(minZ, minY, 1.0 - minX, maxZ, maxY, 1.0 - maxX) + VoxelShapes.box(minZ, minY, 1.0 - minX, maxZ, maxY, 1.0 - maxX) )); }); return TEMP_SHAPE.get(); diff --git a/src/main/java/li/cil/oc2/common/util/WorldUtils.java b/src/main/java/li/cil/oc2/common/util/WorldUtils.java index 3cb4f125..7c54f83c 100644 --- a/src/main/java/li/cil/oc2/common/util/WorldUtils.java +++ b/src/main/java/li/cil/oc2/common/util/WorldUtils.java @@ -15,23 +15,23 @@ import java.util.function.Function; public final class WorldUtils { @Nullable - public static TileEntity getTileEntityIfChunkExists(final IWorld world, final BlockPos pos) { + public static TileEntity getBlockEntityIfChunkExists(final IWorld world, final BlockPos pos) { final ChunkPos chunkPos = new ChunkPos(pos); - if (!world.chunkExists(chunkPos.x, chunkPos.z)) { + if (!world.hasChunk(chunkPos.x, chunkPos.z)) { return null; } - return world.getTileEntity(pos); + return world.getBlockEntity(pos); } @Nullable public static String getBlockName(final IWorld world, final BlockPos pos) { final ChunkPos chunkPos = new ChunkPos(pos); - if (!world.chunkExists(chunkPos.x, chunkPos.z)) { + if (!world.hasChunk(chunkPos.x, chunkPos.z)) { return null; } - final TileEntity tileEntity = world.getTileEntity(pos); + final TileEntity tileEntity = world.getBlockEntity(pos); if (tileEntity != null) { final ResourceLocation registryName = tileEntity.getType().getRegistryName(); if (registryName != null) { diff --git a/src/main/java/li/cil/oc2/common/vm/Terminal.java b/src/main/java/li/cil/oc2/common/vm/Terminal.java index d3fb2f43..1f52ff78 100644 --- a/src/main/java/li/cil/oc2/common/vm/Terminal.java +++ b/src/main/java/li/cil/oc2/common/vm/Terminal.java @@ -115,7 +115,7 @@ public final class Terminal { if (hasPendingBell) { hasPendingBell = false; final Minecraft client = Minecraft.getInstance(); - client.execute(() -> client.getSoundHandler().play(SimpleSound.master(NoteBlockInstrument.PLING.getSound(), 1))); + client.execute(() -> client.getSoundManager().play(SimpleSound.forUI(NoteBlockInstrument.PLING.getSoundEvent(), 1))); } if (renderer == null) { @@ -552,23 +552,23 @@ public final class Terminal { /////////////////////////////////////////////////////////////// private void renderBuffer() { - GlStateManager.depthMask(false); - Minecraft.getInstance().getTextureManager().bindTexture(LOCATION_FONT_TEXTURE); + GlStateManager._depthMask(false); + Minecraft.getInstance().getTextureManager().bind(LOCATION_FONT_TEXTURE); - final BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + final BufferBuilder buffer = Tessellator.getInstance().getBuilder(); for (final Object line : lines) { buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX); - buffer.setVertexState((BufferBuilder.State) line); - buffer.finishDrawing(); - WorldVertexBufferUploader.draw(buffer); + buffer.restoreState((BufferBuilder.State) line); + buffer.end(); + WorldVertexBufferUploader.end(buffer); } - GlStateManager.depthMask(true); + GlStateManager._depthMask(true); } private void validateLineCache(final AtomicInteger dirty, final MatrixStack stack) { - if (!Objects.equals(lastMatrix, stack.getLast().getMatrix())) { - lastMatrix = stack.getLast().getMatrix(); + if (!Objects.equals(lastMatrix, stack.last().pose())) { + lastMatrix = stack.last().pose(); dirty.set(-1); } @@ -576,7 +576,7 @@ public final class Terminal { return; } - final BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + final BufferBuilder buffer = Tessellator.getInstance().getBuilder(); final int mask = dirty.getAndSet(0); for (int row = 0; row < lines.length; row++) { @@ -584,20 +584,20 @@ public final class Terminal { continue; } - stack.push(); + stack.pushPose(); stack.translate(0, row * CHAR_HEIGHT, 0); - final Matrix4f matrix = stack.getLast().getMatrix(); + final Matrix4f matrix = stack.last().pose(); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX); renderBackground(matrix, buffer, row); renderForeground(matrix, buffer, row); - lines[row] = buffer.getVertexState(); - buffer.finishDrawing(); + lines[row] = buffer.getState(); + buffer.end(); buffer.discard(); - stack.pop(); + stack.popPose(); } } @@ -651,10 +651,10 @@ public final class Terminal { final float ulu = (TEXTURE_RESOLUTION - 1) / (float) TEXTURE_RESOLUTION; final float ulv = 1 / (float) TEXTURE_RESOLUTION; - buffer.pos(matrix, x0, CHAR_HEIGHT, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); - buffer.pos(matrix, x1, CHAR_HEIGHT, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); - buffer.pos(matrix, x1, 0, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); - buffer.pos(matrix, x0, 0, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); + buffer.vertex(matrix, x0, CHAR_HEIGHT, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); + buffer.vertex(matrix, x1, CHAR_HEIGHT, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); + buffer.vertex(matrix, x1, 0, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); + buffer.vertex(matrix, x0, 0, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); } private void renderForeground(final Matrix4f matrix, final BufferBuilder buffer, final int row) { @@ -692,20 +692,20 @@ public final class Terminal { final float v0 = y * (CHAR_HEIGHT * ONE_OVER_TEXTURE_RESOLUTION); final float v1 = (y + 1) * (CHAR_HEIGHT * ONE_OVER_TEXTURE_RESOLUTION); - buffer.pos(matrix, offset, CHAR_HEIGHT, 0).color(r, g, b, 1).tex(u0, v1).endVertex(); - buffer.pos(matrix, offset + CHAR_WIDTH, CHAR_HEIGHT, 0).color(r, g, b, 1).tex(u1, v1).endVertex(); - buffer.pos(matrix, offset + CHAR_WIDTH, 0, 0).color(r, g, b, 1).tex(u1, v0).endVertex(); - buffer.pos(matrix, offset, 0, 0).color(r, g, b, 1).tex(u0, v0).endVertex(); + buffer.vertex(matrix, offset, CHAR_HEIGHT, 0).color(r, g, b, 1).uv(u0, v1).endVertex(); + buffer.vertex(matrix, offset + CHAR_WIDTH, CHAR_HEIGHT, 0).color(r, g, b, 1).uv(u1, v1).endVertex(); + buffer.vertex(matrix, offset + CHAR_WIDTH, 0, 0).color(r, g, b, 1).uv(u1, v0).endVertex(); + buffer.vertex(matrix, offset, 0, 0).color(r, g, b, 1).uv(u0, v0).endVertex(); } if ((style & STYLE_UNDERLINE_MASK) != 0) { final float ulu = (TEXTURE_RESOLUTION - 1) / (float) TEXTURE_RESOLUTION; final float ulv = 1 / (float) TEXTURE_RESOLUTION; - buffer.pos(matrix, offset, CHAR_HEIGHT - 3, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); - buffer.pos(matrix, offset + CHAR_WIDTH, CHAR_HEIGHT - 3, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); - buffer.pos(matrix, offset + CHAR_WIDTH, CHAR_HEIGHT - 2, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); - buffer.pos(matrix, offset, CHAR_HEIGHT - 2, 0).color(r, g, b, 1).tex(ulu, ulv).endVertex(); + buffer.vertex(matrix, offset, CHAR_HEIGHT - 3, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); + buffer.vertex(matrix, offset + CHAR_WIDTH, CHAR_HEIGHT - 3, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); + buffer.vertex(matrix, offset + CHAR_WIDTH, CHAR_HEIGHT - 2, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); + buffer.vertex(matrix, offset, CHAR_HEIGHT - 2, 0).color(r, g, b, 1).uv(ulu, ulv).endVertex(); } } @@ -714,14 +714,14 @@ public final class Terminal { return; } - GlStateManager.depthMask(false); + GlStateManager._depthMask(false); RenderSystem.disableTexture(); - stack.push(); + stack.pushPose(); stack.translate(terminal.x * CHAR_WIDTH, terminal.y * CHAR_HEIGHT, 0); - final Matrix4f matrix = stack.getLast().getMatrix(); - final BufferBuilder buffer = Tessellator.getInstance().getBuffer(); + final Matrix4f matrix = stack.last().pose(); + final BufferBuilder buffer = Tessellator.getInstance().getBuilder(); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR); final int foreground = COLORS[COLOR_WHITE]; @@ -729,18 +729,18 @@ public final class Terminal { final float g = ((foreground >> 8) & 0xFF) / 255f; final float b = ((foreground) & 0xFF) / 255f; - buffer.pos(matrix, 0, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex(); - buffer.pos(matrix, CHAR_WIDTH, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex(); - buffer.pos(matrix, CHAR_WIDTH, 0, 0).color(r, g, b, 1).endVertex(); - buffer.pos(matrix, 0, 0, 0).color(r, g, b, 1).endVertex(); + buffer.vertex(matrix, 0, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex(); + buffer.vertex(matrix, CHAR_WIDTH, CHAR_HEIGHT, 0).color(r, g, b, 1).endVertex(); + buffer.vertex(matrix, CHAR_WIDTH, 0, 0).color(r, g, b, 1).endVertex(); + buffer.vertex(matrix, 0, 0, 0).color(r, g, b, 1).endVertex(); - buffer.finishDrawing(); - WorldVertexBufferUploader.draw(buffer); + buffer.end(); + WorldVertexBufferUploader.end(buffer); - stack.pop(); + stack.popPose(); RenderSystem.enableTexture(); - GlStateManager.depthMask(true); + GlStateManager._depthMask(true); } private static boolean isPrintableCharacter(final char ch) { diff --git a/src/main/java/li/cil/oc2/data/ModBlockStateProvider.java b/src/main/java/li/cil/oc2/data/ModBlockStateProvider.java index 55a7fe3b..340964a9 100644 --- a/src/main/java/li/cil/oc2/data/ModBlockStateProvider.java +++ b/src/main/java/li/cil/oc2/data/ModBlockStateProvider.java @@ -62,7 +62,7 @@ public class ModBlockStateProvider extends BlockStateProvider { .end(); BusCableBlock.FACING_TO_CONNECTION_MAP.forEach((direction, connectionType) -> { - final int rotationY = (int) direction.getHorizontalAngle(); + final int rotationY = (int) direction.toYRot(); final int rotationX; if (direction == Direction.UP) { rotationX = 90; diff --git a/src/main/java/li/cil/oc2/data/ModBlockTagsProvider.java b/src/main/java/li/cil/oc2/data/ModBlockTagsProvider.java index 1f36ddf7..543a738d 100644 --- a/src/main/java/li/cil/oc2/data/ModBlockTagsProvider.java +++ b/src/main/java/li/cil/oc2/data/ModBlockTagsProvider.java @@ -16,16 +16,16 @@ public final class ModBlockTagsProvider extends BlockTagsProvider { } @Override - protected void registerTags() { - getOrCreateBuilder(DEVICES).add( + protected void addTags() { + tag(DEVICES).add( COMPUTER.get(), REDSTONE_INTERFACE.get(), DISK_DRIVE.get() ); - getOrCreateBuilder(CABLES).add( + tag(CABLES).add( BUS_CABLE.get() ); - getOrCreateBuilder(WRENCH_BREAKABLE).add( + tag(WRENCH_BREAKABLE).add( COMPUTER.get(), BUS_CABLE.get(), NETWORK_CONNECTOR.get(), diff --git a/src/main/java/li/cil/oc2/data/ModItemTagsProvider.java b/src/main/java/li/cil/oc2/data/ModItemTagsProvider.java index 4b1fbebc..bcea64c4 100644 --- a/src/main/java/li/cil/oc2/data/ModItemTagsProvider.java +++ b/src/main/java/li/cil/oc2/data/ModItemTagsProvider.java @@ -21,11 +21,11 @@ public final class ModItemTagsProvider extends ItemTagsProvider { @SuppressWarnings("unchecked") @Override - protected void registerTags() { + protected void addTags() { copy(BlockTags.CABLES, CABLES); copy(BlockTags.DEVICES, DEVICES); - getOrCreateBuilder(DEVICES).addTags( + tag(DEVICES).addTags( DEVICES_MEMORY, DEVICES_HARD_DRIVE, DEVICES_FLASH_MEMORY, @@ -33,35 +33,35 @@ public final class ModItemTagsProvider extends ItemTagsProvider { DEVICES_ROBOT_MODULE, DEVICES_FLOPPY ); - getOrCreateBuilder(DEVICES_MEMORY).add( + tag(DEVICES_MEMORY).add( Items.MEMORY_SMALL.get(), Items.MEMORY_MEDIUM.get(), Items.MEMORY_LARGE.get() ); - getOrCreateBuilder(DEVICES_HARD_DRIVE).add( + tag(DEVICES_HARD_DRIVE).add( Items.HARD_DRIVE_SMALL.get(), Items.HARD_DRIVE_MEDIUM.get(), Items.HARD_DRIVE_LARGE.get(), Items.HARD_DRIVE_CUSTOM.get() ); - getOrCreateBuilder(DEVICES_FLASH_MEMORY).add( + tag(DEVICES_FLASH_MEMORY).add( Items.FLASH_MEMORY.get(), Items.FLASH_MEMORY_CUSTOM.get() ); - getOrCreateBuilder(DEVICES_FLOPPY).add( + tag(DEVICES_FLOPPY).add( Items.FLOPPY.get() ); - getOrCreateBuilder(DEVICES_CARD).add( + tag(DEVICES_CARD).add( Items.REDSTONE_INTERFACE_CARD.get(), Items.NETWORK_INTERFACE_CARD.get(), Items.FILE_IMPORT_EXPORT_CARD.get() ); - getOrCreateBuilder(DEVICES_ROBOT_MODULE).add( + tag(DEVICES_ROBOT_MODULE).add( Items.INVENTORY_OPERATIONS_MODULE.get(), Items.BLOCK_OPERATIONS_MODULE.get() ); - getOrCreateBuilder(TOOL_MATERIALS).addTags( + tag(TOOL_MATERIALS).addTags( TOOL_MATERIAL_WOOD, TOOL_MATERIAL_STONE, TOOL_MATERIAL_IRON, @@ -69,28 +69,28 @@ public final class ModItemTagsProvider extends ItemTagsProvider { TOOL_MATERIAL_DIAMOND, TOOL_MATERIAL_NETHERITE ); - getOrCreateBuilder(TOOL_MATERIAL_WOOD).addTags( + tag(TOOL_MATERIAL_WOOD).addTags( ItemTags.PLANKS ); - getOrCreateBuilder(TOOL_MATERIAL_STONE).addTags( + tag(TOOL_MATERIAL_STONE).addTags( ItemTags.STONE_TOOL_MATERIALS ); - getOrCreateBuilder(TOOL_MATERIAL_IRON).addTags( + tag(TOOL_MATERIAL_IRON).addTags( Tags.Items.INGOTS_IRON ); - getOrCreateBuilder(TOOL_MATERIAL_GOLD).addTags( + tag(TOOL_MATERIAL_GOLD).addTags( Tags.Items.INGOTS_GOLD ); - getOrCreateBuilder(TOOL_MATERIAL_DIAMOND).addTags( + tag(TOOL_MATERIAL_DIAMOND).addTags( Tags.Items.GEMS_DIAMOND ); - getOrCreateBuilder(TOOL_MATERIAL_NETHERITE).addTags( + tag(TOOL_MATERIAL_NETHERITE).addTags( Tags.Items.INGOTS_NETHERITE ); - getOrCreateBuilder(WRENCHES).add(Items.WRENCH.get()); + tag(WRENCHES).add(Items.WRENCH.get()); - getOrCreateBuilder(DEVICE_NEEDS_REBOOT).add( + tag(DEVICE_NEEDS_REBOOT).add( Items.MEMORY_SMALL.get(), Items.MEMORY_MEDIUM.get(), Items.MEMORY_LARGE.get(), diff --git a/src/main/java/li/cil/oc2/data/ModLootTableProvider.java b/src/main/java/li/cil/oc2/data/ModLootTableProvider.java index f653a765..f5f67842 100644 --- a/src/main/java/li/cil/oc2/data/ModLootTableProvider.java +++ b/src/main/java/li/cil/oc2/data/ModLootTableProvider.java @@ -30,7 +30,7 @@ public final class ModLootTableProvider extends LootTableProvider { @Override protected void validate(final Map map, final ValidationTracker validationtracker) { - map.forEach((location, table) -> LootTableManager.validateLootTable(validationtracker, location, table)); + map.forEach((location, table) -> LootTableManager.validate(validationtracker, location, table)); } @Override @@ -41,13 +41,13 @@ public final class ModLootTableProvider extends LootTableProvider { public static final class ModBlockLootTables extends BlockLootTables { @Override protected void addTables() { - registerDropSelfLootTable(Blocks.REDSTONE_INTERFACE.get()); - registerDropSelfLootTable(Blocks.NETWORK_CONNECTOR.get()); - registerDropSelfLootTable(Blocks.NETWORK_HUB.get()); - registerDropSelfLootTable(Blocks.DISK_DRIVE.get()); - registerDropSelfLootTable(Blocks.CHARGER.get()); + dropSelf(Blocks.REDSTONE_INTERFACE.get()); + dropSelf(Blocks.NETWORK_CONNECTOR.get()); + dropSelf(Blocks.NETWORK_HUB.get()); + dropSelf(Blocks.DISK_DRIVE.get()); + dropSelf(Blocks.CHARGER.get()); - registerLootTable(Blocks.COMPUTER.get(), ModBlockLootTables::droppingWithInventory); + add(Blocks.COMPUTER.get(), ModBlockLootTables::droppingWithInventory); } @Override @@ -59,15 +59,15 @@ public final class ModLootTableProvider extends LootTableProvider { } private static LootTable.Builder droppingWithInventory(final Block block) { - return LootTable.builder() - .addLootPool(withSurvivesExplosion(block, LootPool.builder() - .rolls(ConstantRange.of(1)) - .addEntry(ItemLootEntry.builder(block) - .acceptFunction(CopyNbt.builder(CopyNbt.Source.BLOCK_ENTITY) - .addOperation(ITEMS_TAG_NAME, + return LootTable.lootTable() + .withPool(applyExplosionCondition(block, LootPool.lootPool() + .setRolls(ConstantRange.exactly(1)) + .add(ItemLootEntry.lootTableItem(block) + .apply(CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY) + .copy(ITEMS_TAG_NAME, concat(BLOCK_ENTITY_TAG_NAME_IN_ITEM, ITEMS_TAG_NAME), CopyNbt.Action.REPLACE) - .addOperation(ENERGY_TAG_NAME, + .copy(ENERGY_TAG_NAME, concat(BLOCK_ENTITY_TAG_NAME_IN_ITEM, ENERGY_TAG_NAME), CopyNbt.Action.REPLACE) ) diff --git a/src/main/java/li/cil/oc2/data/ModRecipesProvider.java b/src/main/java/li/cil/oc2/data/ModRecipesProvider.java index fcdd9aa2..071e5567 100644 --- a/src/main/java/li/cil/oc2/data/ModRecipesProvider.java +++ b/src/main/java/li/cil/oc2/data/ModRecipesProvider.java @@ -15,319 +15,319 @@ public final class ModRecipesProvider extends RecipeProvider { } @Override - protected void registerRecipes(final Consumer consumer) { + protected void buildShapelessRecipes(final Consumer consumer) { ShapedRecipeBuilder - .shapedRecipe(Items.COMPUTER.get()) - .patternLine("ICI") - .patternLine("XTX") - .patternLine("IBI") - .key('I', Tags.Items.INGOTS_IRON) - .key('C', Tags.Items.CHESTS_WOODEN) - .key('X', Items.BUS_INTERFACE.get()) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_transistor", inventoryChange(Items.TRANSISTOR.get())) - .addCriterion("has_circuit_board", inventoryChange(Items.CIRCUIT_BOARD.get())) - .build(consumer); + .shaped(Items.COMPUTER.get()) + .pattern("ICI") + .pattern("XTX") + .pattern("IBI") + .define('I', Tags.Items.INGOTS_IRON) + .define('C', Tags.Items.CHESTS_WOODEN) + .define('X', Items.BUS_INTERFACE.get()) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_transistor", inventoryChange(Items.TRANSISTOR.get())) + .unlockedBy("has_circuit_board", inventoryChange(Items.CIRCUIT_BOARD.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.BUS_CABLE.get(), 16) - .patternLine("III") - .patternLine("GTG") - .patternLine("III") - .key('I', Tags.Items.INGOTS_IRON) - .key('G', Tags.Items.INGOTS_GOLD) - .key('T', Items.TRANSISTOR.get()) - .addCriterion("has_transistor", inventoryChange(Items.TRANSISTOR.get())) - .build(consumer); + .shaped(Items.BUS_CABLE.get(), 16) + .pattern("III") + .pattern("GTG") + .pattern("III") + .define('I', Tags.Items.INGOTS_IRON) + .define('G', Tags.Items.INGOTS_GOLD) + .define('T', Items.TRANSISTOR.get()) + .unlockedBy("has_transistor", inventoryChange(Items.TRANSISTOR.get())) + .save(consumer); ShapelessRecipeBuilder - .shapelessRecipe(Items.BUS_INTERFACE.get()) - .addIngredient(Items.TRANSISTOR.get()) - .addIngredient(Items.BUS_CABLE.get()) - .addCriterion("has_bus_cable", inventoryChange(Items.BUS_CABLE.get())) - .build(consumer); + .shapeless(Items.BUS_INTERFACE.get()) + .requires(Items.TRANSISTOR.get()) + .requires(Items.BUS_CABLE.get()) + .unlockedBy("has_bus_cable", inventoryChange(Items.BUS_CABLE.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.NETWORK_CONNECTOR.get(), 4) - .patternLine("IGI") - .patternLine("ITI") - .key('I', Tags.Items.INGOTS_IRON) - .key('G', Tags.Items.GLASS) - .key('T', Items.TRANSISTOR.get()) - .addCriterion("has_transistor", inventoryChange(Items.TRANSISTOR.get())) - .build(consumer); + .shaped(Items.NETWORK_CONNECTOR.get(), 4) + .pattern("IGI") + .pattern("ITI") + .define('I', Tags.Items.INGOTS_IRON) + .define('G', Tags.Items.GLASS) + .define('T', Items.TRANSISTOR.get()) + .unlockedBy("has_transistor", inventoryChange(Items.TRANSISTOR.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.NETWORK_HUB.get()) - .patternLine("ICI") - .patternLine("XTX") - .patternLine("ICI") - .key('I', Tags.Items.INGOTS_IRON) - .key('C', Items.NETWORK_CONNECTOR.get()) - .key('X', Items.BUS_INTERFACE.get()) - .key('T', Items.TRANSISTOR.get()) - .addCriterion("has_network_connector", inventoryChange(Items.NETWORK_CONNECTOR.get())) - .build(consumer); + .shaped(Items.NETWORK_HUB.get()) + .pattern("ICI") + .pattern("XTX") + .pattern("ICI") + .define('I', Tags.Items.INGOTS_IRON) + .define('C', Items.NETWORK_CONNECTOR.get()) + .define('X', Items.BUS_INTERFACE.get()) + .define('T', Items.TRANSISTOR.get()) + .unlockedBy("has_network_connector", inventoryChange(Items.NETWORK_CONNECTOR.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.REDSTONE_INTERFACE.get()) - .patternLine("IRI") - .patternLine("XTX") - .patternLine("IRI") - .key('I', Tags.Items.INGOTS_IRON) - .key('R', Tags.Items.DUSTS_REDSTONE) - .key('T', Items.TRANSISTOR.get()) - .key('X', Items.BUS_INTERFACE.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .build(consumer); + .shaped(Items.REDSTONE_INTERFACE.get()) + .pattern("IRI") + .pattern("XTX") + .pattern("IRI") + .define('I', Tags.Items.INGOTS_IRON) + .define('R', Tags.Items.DUSTS_REDSTONE) + .define('T', Items.TRANSISTOR.get()) + .define('X', Items.BUS_INTERFACE.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.DISK_DRIVE.get()) - .patternLine("IBI") - .patternLine("XTX") - .patternLine("IDI") - .key('I', Tags.Items.INGOTS_IRON) - .key('B', ItemTags.BUTTONS) - .key('T', Items.TRANSISTOR.get()) - .key('X', Items.BUS_INTERFACE.get()) - .key('D', net.minecraft.item.Items.DISPENSER) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .build(consumer); + .shaped(Items.DISK_DRIVE.get()) + .pattern("IBI") + .pattern("XTX") + .pattern("IDI") + .define('I', Tags.Items.INGOTS_IRON) + .define('B', ItemTags.BUTTONS) + .define('T', Items.TRANSISTOR.get()) + .define('X', Items.BUS_INTERFACE.get()) + .define('D', net.minecraft.item.Items.DISPENSER) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.CHARGER.get()) - .patternLine("IPI") - .patternLine("XTX") - .patternLine("IRI") - .key('I', Tags.Items.INGOTS_IRON) - .key('P', net.minecraft.item.Items.LIGHT_WEIGHTED_PRESSURE_PLATE) - .key('T', Items.TRANSISTOR.get()) - .key('X', Items.BUS_INTERFACE.get()) - .key('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) - .addCriterion("has_transistor", inventoryChange(Items.TRANSISTOR.get())) - .build(consumer); + .shaped(Items.CHARGER.get()) + .pattern("IPI") + .pattern("XTX") + .pattern("IRI") + .define('I', Tags.Items.INGOTS_IRON) + .define('P', net.minecraft.item.Items.LIGHT_WEIGHTED_PRESSURE_PLATE) + .define('T', Items.TRANSISTOR.get()) + .define('X', Items.BUS_INTERFACE.get()) + .define('R', Tags.Items.STORAGE_BLOCKS_REDSTONE) + .unlockedBy("has_transistor", inventoryChange(Items.TRANSISTOR.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.WRENCH.get()) - .patternLine("I I") - .patternLine(" T ") - .patternLine(" I ") - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .addCriterion("has_transistor", inventoryChange(Items.TRANSISTOR.get())) - .build(consumer); + .shaped(Items.WRENCH.get()) + .pattern("I I") + .pattern(" T ") + .pattern(" I ") + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .unlockedBy("has_transistor", inventoryChange(Items.TRANSISTOR.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.NETWORK_CABLE.get(), 8) - .patternLine("SSS") - .patternLine("GTG") - .patternLine("SSS") - .key('S', Tags.Items.STRING) - .key('G', Tags.Items.GLASS) - .key('T', Items.TRANSISTOR.get()) - .addCriterion("has_network_connector", inventoryChange(Items.NETWORK_CONNECTOR.get())) - .build(consumer); + .shaped(Items.NETWORK_CABLE.get(), 8) + .pattern("SSS") + .pattern("GTG") + .pattern("SSS") + .define('S', Tags.Items.STRING) + .define('G', Tags.Items.GLASS) + .define('T', Items.TRANSISTOR.get()) + .unlockedBy("has_network_connector", inventoryChange(Items.NETWORK_CONNECTOR.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.ROBOT.get()) - .patternLine("ICI") - .patternLine("PTP") - .patternLine("IBI") - .key('I', Tags.Items.INGOTS_IRON) - .key('C', Tags.Items.CHESTS_WOODEN) - .key('P', net.minecraft.item.Items.PISTON) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_transistor", inventoryChange(Items.TRANSISTOR.get())) - .addCriterion("has_circuit_board", inventoryChange(Items.CIRCUIT_BOARD.get())) - .build(consumer); + .shaped(Items.ROBOT.get()) + .pattern("ICI") + .pattern("PTP") + .pattern("IBI") + .define('I', Tags.Items.INGOTS_IRON) + .define('C', Tags.Items.CHESTS_WOODEN) + .define('P', net.minecraft.item.Items.PISTON) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_transistor", inventoryChange(Items.TRANSISTOR.get())) + .unlockedBy("has_circuit_board", inventoryChange(Items.CIRCUIT_BOARD.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.MEMORY_SMALL.get(), 2) - .patternLine("ITI") - .patternLine(" B ") - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.MEMORY_SMALL.get(), 2) + .pattern("ITI") + .pattern(" B ") + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.MEMORY_MEDIUM.get(), 2) - .patternLine("GTG") - .patternLine(" B ") - .key('G', Tags.Items.INGOTS_GOLD) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.MEMORY_MEDIUM.get(), 2) + .pattern("GTG") + .pattern(" B ") + .define('G', Tags.Items.INGOTS_GOLD) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.MEMORY_LARGE.get(), 2) - .patternLine("DTD") - .patternLine(" B ") - .key('D', Tags.Items.GEMS_DIAMOND) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.MEMORY_LARGE.get(), 2) + .pattern("DTD") + .pattern(" B ") + .define('D', Tags.Items.GEMS_DIAMOND) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.HARD_DRIVE_SMALL.get()) - .patternLine("ITI") - .patternLine("EBE") - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .key('E', Tags.Items.GEMS_EMERALD) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.HARD_DRIVE_SMALL.get()) + .pattern("ITI") + .pattern("EBE") + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .define('E', Tags.Items.GEMS_EMERALD) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.HARD_DRIVE_MEDIUM.get()) - .patternLine("GTG") - .patternLine("EBE") - .key('G', Tags.Items.INGOTS_GOLD) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .key('E', Tags.Items.GEMS_EMERALD) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.HARD_DRIVE_MEDIUM.get()) + .pattern("GTG") + .pattern("EBE") + .define('G', Tags.Items.INGOTS_GOLD) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .define('E', Tags.Items.GEMS_EMERALD) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.HARD_DRIVE_LARGE.get()) - .patternLine("DTD") - .patternLine("EBE") - .key('D', Tags.Items.GEMS_DIAMOND) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .key('E', Tags.Items.GEMS_EMERALD) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.HARD_DRIVE_LARGE.get()) + .pattern("DTD") + .pattern("EBE") + .define('D', Tags.Items.GEMS_DIAMOND) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .define('E', Tags.Items.GEMS_EMERALD) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); WrenchRecipeBuilder .wrenchRecipe(Items.HARD_DRIVE_CUSTOM.get()) - .addIngredient(Items.HARD_DRIVE_LARGE.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .requires(Items.HARD_DRIVE_LARGE.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.FLASH_MEMORY.get()) - .patternLine("ITI") - .patternLine("RBR") - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .key('R', Tags.Items.DUSTS_REDSTONE) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.FLASH_MEMORY.get()) + .pattern("ITI") + .pattern("RBR") + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .define('R', Tags.Items.DUSTS_REDSTONE) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); WrenchRecipeBuilder .wrenchRecipe(Items.FLASH_MEMORY_CUSTOM.get()) - .addIngredient(Items.FLASH_MEMORY.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .requires(Items.FLASH_MEMORY.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.REDSTONE_INTERFACE_CARD.get()) - .patternLine("IRT") - .patternLine(" B ") - .key('R', net.minecraft.item.Items.REDSTONE_TORCH) - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .build(consumer); + .shaped(Items.REDSTONE_INTERFACE_CARD.get()) + .pattern("IRT") + .pattern(" B ") + .define('R', net.minecraft.item.Items.REDSTONE_TORCH) + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.NETWORK_INTERFACE_CARD.get()) - .patternLine("IGT") - .patternLine(" B ") - .key('G', Tags.Items.GLASS) - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .build(consumer); + .shaped(Items.NETWORK_INTERFACE_CARD.get()) + .pattern("IGT") + .pattern(" B ") + .define('G', Tags.Items.GLASS) + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.FILE_IMPORT_EXPORT_CARD.get()) - .patternLine("IET") - .patternLine(" B ") - .key('E', net.minecraft.item.Items.PAPER) - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_computer", inventoryChange(Items.COMPUTER.get())) - .build(consumer); + .shaped(Items.FILE_IMPORT_EXPORT_CARD.get()) + .pattern("IET") + .pattern(" B ") + .define('E', net.minecraft.item.Items.PAPER) + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_computer", inventoryChange(Items.COMPUTER.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.FLOPPY.get()) - .patternLine("ITI") - .patternLine("QBQ") - .key('I', Tags.Items.INGOTS_IRON) - .key('T', Items.TRANSISTOR.get()) - .key('Q', Tags.Items.GEMS_QUARTZ) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_disk_drive", inventoryChange(Items.DISK_DRIVE.get())) - .build(consumer); + .shaped(Items.FLOPPY.get()) + .pattern("ITI") + .pattern("QBQ") + .define('I', Tags.Items.INGOTS_IRON) + .define('T', Items.TRANSISTOR.get()) + .define('Q', Tags.Items.GEMS_QUARTZ) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_disk_drive", inventoryChange(Items.DISK_DRIVE.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.INVENTORY_OPERATIONS_MODULE.get()) - .patternLine("TCG") - .patternLine(" B ") - .key('T', Items.TRANSISTOR.get()) - .key('C', Tags.Items.CHESTS_WOODEN) - .key('G', Tags.Items.INGOTS_GOLD) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.INVENTORY_OPERATIONS_MODULE.get()) + .pattern("TCG") + .pattern(" B ") + .define('T', Items.TRANSISTOR.get()) + .define('C', Tags.Items.CHESTS_WOODEN) + .define('G', Tags.Items.INGOTS_GOLD) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.BLOCK_OPERATIONS_MODULE.get()) - .patternLine("TPG") - .patternLine(" B ") - .key('T', Items.TRANSISTOR.get()) - .key('P', net.minecraft.item.Items.DIAMOND_PICKAXE) - .key('G', Tags.Items.INGOTS_GOLD) - .key('B', Items.CIRCUIT_BOARD.get()) - .addCriterion("has_robot", inventoryChange(Items.ROBOT.get())) - .build(consumer); + .shaped(Items.BLOCK_OPERATIONS_MODULE.get()) + .pattern("TPG") + .pattern(" B ") + .define('T', Items.TRANSISTOR.get()) + .define('P', net.minecraft.item.Items.DIAMOND_PICKAXE) + .define('G', Tags.Items.INGOTS_GOLD) + .define('B', Items.CIRCUIT_BOARD.get()) + .unlockedBy("has_robot", inventoryChange(Items.ROBOT.get())) + .save(consumer); ShapedRecipeBuilder - .shapedRecipe(Items.TRANSISTOR.get(), 8) - .patternLine("RCR") - .patternLine("III") - .key('I', Tags.Items.INGOTS_IRON) - .key('R', Tags.Items.DUSTS_REDSTONE) - .key('C', net.minecraft.item.Items.COMPARATOR) - .addCriterion("has_gold", inventoryChange(net.minecraft.item.Items.GOLD_INGOT)) - .build(consumer); + .shaped(Items.TRANSISTOR.get(), 8) + .pattern("RCR") + .pattern("III") + .define('I', Tags.Items.INGOTS_IRON) + .define('R', Tags.Items.DUSTS_REDSTONE) + .define('C', net.minecraft.item.Items.COMPARATOR) + .unlockedBy("has_gold", inventoryChange(net.minecraft.item.Items.GOLD_INGOT)) + .save(consumer); ShapelessRecipeBuilder - .shapelessRecipe(Items.CIRCUIT_BOARD.get(), 4) - .addIngredient(Tags.Items.INGOTS_GOLD) - .addIngredient(net.minecraft.item.Items.CLAY_BALL) - .addIngredient(Items.TRANSISTOR.get()) - .addCriterion("has_transistor", inventoryChange(Items.TRANSISTOR.get())) - .build(consumer); + .shapeless(Items.CIRCUIT_BOARD.get(), 4) + .requires(Tags.Items.INGOTS_GOLD) + .requires(net.minecraft.item.Items.CLAY_BALL) + .requires(Items.TRANSISTOR.get()) + .unlockedBy("has_transistor", inventoryChange(Items.TRANSISTOR.get())) + .save(consumer); } private static InventoryChangeTrigger.Instance inventoryChange(final IItemProvider item) { - return InventoryChangeTrigger.Instance.forItems(item); + return InventoryChangeTrigger.Instance.hasItems(item); } } diff --git a/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java b/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java index 3f9b7ce0..dd3fc9e5 100644 --- a/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java +++ b/src/main/java/li/cil/oc2/data/WrenchRecipeBuilder.java @@ -27,14 +27,14 @@ public final class WrenchRecipeBuilder { private final Item result; private final int count; private final List ingredients = Lists.newArrayList(); - private final Advancement.Builder advancementBuilder = Advancement.Builder.builder(); + private final Advancement.Builder advancementBuilder = Advancement.Builder.advancement(); private String group; public WrenchRecipeBuilder(final IItemProvider result, final int count) { this.result = result.asItem(); this.count = count; - addIngredient(Items.WRENCH.get()); + requires(Items.WRENCH.get()); } public static WrenchRecipeBuilder wrenchRecipe(final IItemProvider resultIn) { @@ -45,23 +45,23 @@ public final class WrenchRecipeBuilder { return new WrenchRecipeBuilder(resultIn, countIn); } - public WrenchRecipeBuilder addIngredient(final ITag tagIn) { - return this.addIngredient(Ingredient.fromTag(tagIn)); + public WrenchRecipeBuilder requires(final ITag tagIn) { + return this.requires(Ingredient.of(tagIn)); } - public WrenchRecipeBuilder addIngredient(final IItemProvider itemIn) { - return this.addIngredient(itemIn, 1); + public WrenchRecipeBuilder requires(final IItemProvider itemIn) { + return this.requires(itemIn, 1); } - public WrenchRecipeBuilder addIngredient(final IItemProvider itemIn, final int quantity) { + public WrenchRecipeBuilder requires(final IItemProvider itemIn, final int quantity) { for (int i = 0; i < quantity; ++i) { - this.addIngredient(Ingredient.fromItems(itemIn)); + this.requires(Ingredient.of(itemIn)); } return this; } - public WrenchRecipeBuilder addIngredient(final Ingredient ingredientIn) { + public WrenchRecipeBuilder requires(final Ingredient ingredientIn) { return this.addIngredient(ingredientIn, 1); } @@ -73,8 +73,8 @@ public final class WrenchRecipeBuilder { return this; } - public WrenchRecipeBuilder addCriterion(final String name, final ICriterionInstance criterionIn) { - this.advancementBuilder.withCriterion(name, criterionIn); + public WrenchRecipeBuilder unlockedBy(final String name, final ICriterionInstance criterionIn) { + this.advancementBuilder.addCriterion(name, criterionIn); return this; } @@ -83,23 +83,23 @@ public final class WrenchRecipeBuilder { return this; } - public void build(final Consumer consumerIn) { - this.build(consumerIn, ForgeRegistries.ITEMS.getKey(this.result)); + public void save(final Consumer consumerIn) { + this.save(consumerIn, ForgeRegistries.ITEMS.getKey(this.result)); } - public void build(final Consumer consumerIn, final String save) { + public void save(final Consumer consumerIn, final String save) { final ResourceLocation resourcelocation = ForgeRegistries.ITEMS.getKey(this.result); if ((new ResourceLocation(save)).equals(resourcelocation)) { throw new IllegalStateException("Shapeless Recipe " + save + " should remove its 'save' argument"); } else { - this.build(consumerIn, new ResourceLocation(save)); + this.save(consumerIn, new ResourceLocation(save)); } } - public void build(final Consumer consumerIn, final ResourceLocation id) { + public void save(final Consumer consumerIn, final ResourceLocation id) { this.validate(id); - this.advancementBuilder.withParentId(new ResourceLocation("recipes/root")).withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(id)).withRewards(AdvancementRewards.Builder.recipe(id)).withRequirementsStrategy(IRequirementsStrategy.OR); - consumerIn.accept(new WrenchRecipeBuilder.Result(id, this.result, this.count, this.group == null ? "" : this.group, this.ingredients, this.advancementBuilder, new ResourceLocation(id.getNamespace(), "recipes/" + this.result.getGroup().getPath() + "/" + id.getPath()))); + this.advancementBuilder.parent(new ResourceLocation("recipes/root")).addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(id)).rewards(AdvancementRewards.Builder.recipe(id)).requirements(IRequirementsStrategy.OR); + consumerIn.accept(new WrenchRecipeBuilder.Result(id, this.result, this.count, this.group == null ? "" : this.group, this.ingredients, this.advancementBuilder, new ResourceLocation(id.getNamespace(), "recipes/" + this.result.getItemCategory().getRecipeFolderName() + "/" + id.getPath()))); } private void validate(final ResourceLocation id) { @@ -127,7 +127,7 @@ public final class WrenchRecipeBuilder { this.advancementId = advancementIdIn; } - public void serialize(final JsonObject json) { + public void serializeRecipeData(final JsonObject json) { if (!this.group.isEmpty()) { json.addProperty("group", this.group); } @@ -135,7 +135,7 @@ public final class WrenchRecipeBuilder { final JsonArray jsonarray = new JsonArray(); for (final Ingredient ingredient : this.ingredients) { - jsonarray.add(ingredient.serialize()); + jsonarray.add(ingredient.toJson()); } json.add("ingredients", jsonarray); @@ -148,21 +148,21 @@ public final class WrenchRecipeBuilder { json.add("result", jsonobject); } - public IRecipeSerializer getSerializer() { + public IRecipeSerializer getType() { return RecipeSerializers.WRENCH.get(); } - public ResourceLocation getID() { + public ResourceLocation getId() { return this.id; } @Nullable - public JsonObject getAdvancementJson() { - return this.advancementBuilder.serialize(); + public JsonObject serializeAdvancement() { + return this.advancementBuilder.serializeToJson(); } @Nullable - public ResourceLocation getAdvancementID() { + public ResourceLocation getAdvancementId() { return this.advancementId; } } diff --git a/src/test/java/li/cil/oc2/common/bus/DeviceBusTests.java b/src/test/java/li/cil/oc2/common/bus/DeviceBusTests.java index 7a3f7cf9..71f27c48 100644 --- a/src/test/java/li/cil/oc2/common/bus/DeviceBusTests.java +++ b/src/test/java/li/cil/oc2/common/bus/DeviceBusTests.java @@ -31,7 +31,7 @@ public class DeviceBusTests { public static void setup() { // Gotta go through regular MC bootstrapping first because otherwise class // load order may lead to errors because static fields reference each other. - Bootstrap.register(); + Bootstrap.bootStrap(); } @BeforeEach diff --git a/src/test/java/li/cil/oc2/common/serialization/SerializationTests.java b/src/test/java/li/cil/oc2/common/serialization/SerializationTests.java index 0623169c..6c898964 100644 --- a/src/test/java/li/cil/oc2/common/serialization/SerializationTests.java +++ b/src/test/java/li/cil/oc2/common/serialization/SerializationTests.java @@ -38,7 +38,7 @@ public final class SerializationTests { assertArrayEquals(new int[]{4, 5, 6}, nbt.getIntArray("intArrayValue")); assertArrayEquals(new long[]{7, 8, 9}, nbt.getLongArray("longArrayValue")); assertEquals("test string", nbt.getString("stringValue")); - assertEquals(uuid, nbt.getCompound("uuidValue").getUniqueId("uuidValue")); + assertEquals(uuid, nbt.getCompound("uuidValue").getUUID("uuidValue")); } @Test @@ -56,7 +56,7 @@ public final class SerializationTests { nbt.putString("stringValue", "another test"); final UUID uuid = UUID.randomUUID(); final CompoundNBT uuidNBT = new CompoundNBT(); - uuidNBT.putUniqueId("uuidValue", uuid); + uuidNBT.putUUID("uuidValue", uuid); nbt.put("uuidValue", uuidNBT); final Flat value = assertDoesNotThrow(() -> NBTSerialization.deserialize(nbt, Flat.class, new Flat())); @@ -90,7 +90,7 @@ public final class SerializationTests { nbt.putString("stringValue", "another test"); final UUID uuid = UUID.randomUUID(); final CompoundNBT uuidNBT = new CompoundNBT(); - uuidNBT.putUniqueId("uuidValue", uuid); + uuidNBT.putUUID("uuidValue", uuid); nbt.put("uuidValue", uuidNBT); final Flat value = assertDoesNotThrow(() -> NBTSerialization.deserialize(nbt, Flat.class, null));