Merge pull request #43 from lucsoft/1.16.5

Switch to Mojang Mappings
This commit is contained in:
Sangar
2021-06-05 12:57:24 +02:00
committed by GitHub
138 changed files with 1523 additions and 1522 deletions

5
.gitignore vendored
View File

@@ -1,3 +1,6 @@
#system
.DS_Store
# eclipse
bin
*.launch
@@ -28,4 +31,4 @@ forge*changelog.txt
/src/generated/
#vscode
.vscode
.vscode

View File

@@ -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

Binary file not shown.

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
///////////////////////////////////////////////////////////////////

View File

@@ -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;
}

View File

@@ -22,9 +22,9 @@ public final class ComputerInventoryScreen extends ContainerScreen<ComputerInven
public ComputerInventoryScreen(final ComputerInventoryContainer container, final PlayerInventory inventory, final ITextComponent title) {
super(container, inventory, title);
xSize = 176;
ySize = 197;
playerInventoryTitleY = ySize - 94;
imageWidth = 176;
imageHeight = 197;
inventoryLabelY = imageHeight - 94;
}
@Override
@@ -41,15 +41,15 @@ public final class ComputerInventoryScreen extends ContainerScreen<ComputerInven
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);
requireNonNull(minecraft).getTextureManager().bindTexture(BACKGROUND);
blit(matrixStack, guiLeft, guiTop, 0, 0, xSize, ySize);
requireNonNull(minecraft).getTextureManager().bind(BACKGROUND);
blit(matrixStack, leftPos, topPos, 0, 0, imageWidth, imageHeight);
}
}

View File

@@ -22,28 +22,29 @@ public final class ComputerTerminalScreen extends ContainerScreen<ComputerTermin
public ComputerTerminalScreen(final ComputerTerminalContainer container, final PlayerInventory playerInventory, final ITextComponent title) {
super(container, playerInventory, title);
this.terminalWidget = new ComputerTerminalWidget(container.getComputer().getTerminal());
xSize = AbstractTerminalWidget.WIDTH;
ySize = AbstractTerminalWidget.HEIGHT;
imageWidth = AbstractTerminalWidget.WIDTH;
imageHeight = AbstractTerminalWidget.HEIGHT;
}
///////////////////////////////////////////////////////////////////
@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) {
terminalWidget.renderBackground(matrixStack, mouseX, mouseY);
}
@Override
protected void drawGuiContainerForegroundLayer(final MatrixStack matrixStack, final int mouseX, final int mouseY) {
protected void renderLabels(final MatrixStack matrixStack, final int mouseX, final int mouseY) {
// This is required to prevent the labels from being rendered
}
@Override
public void render(final MatrixStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
terminalWidget.setEnergyInfo(container.getEnergy(), container.getEnergyCapacity(), container.getEnergyConsumption());
terminalWidget.setEnergyInfo(menu.getEnergy(), menu.getEnergyCapacity(), menu.getEnergyConsumption());
renderBackground(matrixStack);
super.render(matrixStack, mouseX, mouseY, partialTicks);
terminalWidget.render(matrixStack, mouseX, mouseY, container.getComputer().getVirtualMachine().getBootError());
terminalWidget.render(matrixStack, mouseX, mouseY, menu.getComputer().getVirtualMachine().getBootError());
}
@Override
@@ -67,8 +68,8 @@ public final class ComputerTerminalScreen extends ContainerScreen<ComputerTermin
// Don't close with inventory binding since we usually want to use that as terminal input
// even without input capture enabled.
final InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
if (this.minecraft.gameSettings.keyBindInventory.isActiveAndMatches(input)) {
final InputMappings.Input input = InputMappings.getKey(keyCode, scanCode);
if (this.minecraft.options.keyInventory.isActiveAndMatches(input)) {
return true;
}
@@ -96,7 +97,7 @@ public final class ComputerTerminalScreen extends ContainerScreen<ComputerTermin
@Override
protected boolean isRunning() {
return container.getComputer().getVirtualMachine().isRunning();
return menu.getComputer().getVirtualMachine().isRunning();
}
@Override
@@ -106,12 +107,12 @@ public final class ComputerTerminalScreen extends ContainerScreen<ComputerTermin
@Override
protected void sendPowerStateToServer(final boolean value) {
Network.INSTANCE.sendToServer(new ComputerPowerMessage(container.getComputer(), value));
Network.INSTANCE.sendToServer(new ComputerPowerMessage(menu.getComputer(), value));
}
@Override
protected void sendTerminalInputToServer(final ByteBuffer input) {
Network.INSTANCE.sendToServer(new ComputerTerminalInputMessage(container.getComputer(), input));
Network.INSTANCE.sendToServer(new ComputerTerminalInputMessage(menu.getComputer(), input));
}
}
}

View File

@@ -71,24 +71,24 @@ public class FileChooserScreen extends Screen {
///////////////////////////////////////////////////////////////////
public static void openFileChooserForSave(final String name, final FileChooserCallback callback) {
final Screen currentScreen = Minecraft.getInstance().currentScreen;
final Screen currentScreen = Minecraft.getInstance().screen;
if (currentScreen instanceof FileChooserScreen) {
currentScreen.closeScreen();
currentScreen.onClose();
}
final FileChooserScreen screen = new FileChooserScreen(callback, false);
Minecraft.getInstance().displayGuiScreen(screen);
screen.fileNameTextField.setText(name);
Minecraft.getInstance().setScreen(screen);
screen.fileNameTextField.setValue(name);
}
public static void openFileChooserForLoad(final FileChooserCallback callback) {
final Screen currentScreen = Minecraft.getInstance().currentScreen;
final Screen currentScreen = Minecraft.getInstance().screen;
if (currentScreen instanceof FileChooserScreen) {
currentScreen.closeScreen();
currentScreen.onClose();
}
final FileChooserScreen screen = new FileChooserScreen(callback, true);
Minecraft.getInstance().displayGuiScreen(screen);
Minecraft.getInstance().setScreen(screen);
}
///////////////////////////////////////////////////////////////////
@@ -99,7 +99,7 @@ public class FileChooserScreen extends Screen {
this.callback = callback;
this.isLoad = isLoad;
this.previousScreen = Minecraft.getInstance().currentScreen;
this.previousScreen = Minecraft.getInstance().screen;
}
///////////////////////////////////////////////////////////////////
@@ -111,7 +111,7 @@ public class FileChooserScreen extends Screen {
}
if (previousScreen != null) {
minecraft.enqueue(() -> 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<FileEntry> {
@@ -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;

View File

@@ -24,7 +24,7 @@ public final class RobotContainerScreen extends ContainerScreen<RobotContainer>
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<RobotContainer>
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<RobotContainer>
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);
}
}

View File

@@ -28,29 +28,30 @@ public final class RobotTerminalScreen extends ContainerScreen<RobotTerminalCont
public RobotTerminalScreen(final RobotTerminalContainer container, final PlayerInventory playerInventory, final ITextComponent title) {
super(container, playerInventory, title);
this.terminalWidget = new RobotTerminalWidget(container.getRobot().getTerminal());
xSize = AbstractTerminalWidget.WIDTH;
ySize = AbstractTerminalWidget.HEIGHT;
imageWidth = AbstractTerminalWidget.WIDTH;
imageHeight = AbstractTerminalWidget.HEIGHT;
}
@Override
protected void drawGuiContainerBackgroundLayer(final MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
INVENTORY_BACKGROUND.draw(matrixStack, guiLeft + SLOTS_X, guiTop + SLOTS_Y);
protected void renderBg(final MatrixStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
INVENTORY_BACKGROUND.draw(matrixStack, leftPos + SLOTS_X, topPos + SLOTS_Y);
terminalWidget.renderBackground(matrixStack, mouseX, mouseY);
}
@Override
protected void drawGuiContainerForegroundLayer(final MatrixStack matrixStack, final int mouseX, final int mouseY) {
protected void renderLabels(final MatrixStack matrixStack, final int mouseX, final int mouseY) {
}
@Override
public void render(final MatrixStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
terminalWidget.setEnergyInfo(container.getEnergy(), container.getEnergyCapacity(), container.getEnergyConsumption());
terminalWidget.setEnergyInfo(menu.getEnergy(), menu.getEnergyCapacity(), menu.getEnergyConsumption());
renderBackground(matrixStack);
super.render(matrixStack, mouseX, mouseY, partialTicks);
terminalWidget.render(matrixStack, mouseX, mouseY, container.getRobot().getVirtualMachine().getBootError());
RobotContainerScreen.renderSelection(matrixStack, container.getRobot().getSelectedSlot(), guiLeft + SLOTS_X + 4, guiTop + SLOTS_Y + 4, 12);
renderHoveredTooltip(matrixStack, mouseX, mouseY);
terminalWidget.render(matrixStack, mouseX, mouseY, menu.getRobot().getVirtualMachine().getBootError());
RobotContainerScreen.renderSelection(matrixStack, menu.getRobot().getSelectedSlot(), leftPos + SLOTS_X + 4, topPos + SLOTS_Y + 4, 12);
renderTooltip(matrixStack, mouseX, mouseY);
}
@Override
@@ -74,8 +75,8 @@ public final class RobotTerminalScreen extends ContainerScreen<RobotTerminalCont
// Don't close with inventory binding since we usually want to use that as terminal input
// even without input capture enabled.
final InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
if (this.minecraft.gameSettings.keyBindInventory.isActiveAndMatches(input)) {
final InputMappings.Input input = InputMappings.getKey(keyCode, scanCode);
if (this.minecraft.options.keyInventory.isActiveAndMatches(input)) {
return true;
}
@@ -103,7 +104,7 @@ public final class RobotTerminalScreen extends ContainerScreen<RobotTerminalCont
@Override
protected boolean isRunning() {
return container.getRobot().getVirtualMachine().isRunning();
return menu.getRobot().getVirtualMachine().isRunning();
}
@Override
@@ -113,12 +114,12 @@ public final class RobotTerminalScreen extends ContainerScreen<RobotTerminalCont
@Override
protected void sendPowerStateToServer(final boolean value) {
Network.INSTANCE.sendToServer(new RobotPowerMessage(container.getRobot(), value));
Network.INSTANCE.sendToServer(new RobotPowerMessage(menu.getRobot(), value));
}
@Override
protected void sendTerminalInputToServer(final ByteBuffer input) {
Network.INSTANCE.sendToServer(new RobotTerminalInputMessage(container.getRobot(), input));
Network.INSTANCE.sendToServer(new RobotTerminalInputMessage(menu.getRobot(), input));
}
}
}

View File

@@ -22,11 +22,11 @@ public final class GuiUtils {
private static final int RELATIVE_ICON_POSITION = (SLOT_SIZE - DEVICE_INFO_ICON_SIZE) / 2;
public static <TContainer extends Container> void renderMissingDeviceInfoIcon(final MatrixStack matrixStack, final ContainerScreen<TContainer> 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 <TContainer extends Container> void renderMissingDeviceInfoTooltip(final MatrixStack matrixStack, final ContainerScreen<TContainer> 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<TypedSlotItemHandler> 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;

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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));
}
}

View File

@@ -35,7 +35,7 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
@Override
public List<BakedQuad> 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<BusCableBlock.ConnectionType> 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<BusCableBlock.ConnectionType> 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;
}
}

View File

@@ -50,8 +50,8 @@ public final class BusCableModel implements IModelGeometry<BusCableModel> {
@Override
public Collection<RenderMaterial> getTextures(final IModelConfiguration owner, final Function<ResourceLocation, IUnbakedModel> modelGetter, final Set<Pair<String, String>> missingTextureErrors) {
final ArrayList<RenderMaterial> 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;
}
}

View File

@@ -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();
}
}

View File

@@ -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,

View File

@@ -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<NetworkConnectorTileEntity> 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<NetworkConnectorTileEntity> 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<Connection> connections, final Predicate<AxisAlignedBB> 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<Connection> 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

View File

@@ -24,30 +24,30 @@ public final class RobotEntityRenderer extends EntityRenderer<RobotEntity> {
///////////////////////////////////////////////////////////////////
@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()) {

View File

@@ -25,20 +25,20 @@ public final class RobotModel extends EntityModel<RobotEntity> {
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<RobotEntity> {
}
@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();
}
}

View File

@@ -17,7 +17,7 @@ import net.minecraft.util.math.vector.Matrix4f;
public final class ChargerTileEntityRenderer extends TileEntityRenderer<ChargerTileEntity> {
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<ChargerT
public void render(final ChargerTileEntity tileEntity, final float partialTicks, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int light, final int overlay) {
offset = (offset + EFFECT_SPEED * partialTicks / 20f) % (float) (Math.PI * 2);
matrixStack.push();
matrixStack.pushPose();
matrixStack.translate(0.5, 1.1, 0.5);
final IVertexBuilder builder = TEXTURE_EFFECT.getBuffer(buffer, CustomRenderType::getUnlitBlock);
final IVertexBuilder builder = TEXTURE_EFFECT.buffer(buffer, CustomRenderType::getUnlitBlock);
for (int i = 0; i < EFFECT_LAYERS; i++) {
final float relativeY = (1 + MathHelper.sin(offset + ((float) Math.PI * 2f * i / EFFECT_LAYERS))) * 0.5f;
final float y = relativeY * EFFECT_HEIGHT;
final float scale = EFFECT_SCALE_START + relativeY * (EFFECT_SCALE_END - EFFECT_SCALE_START);
matrixStack.push();
matrixStack.pushPose();
matrixStack.translate(0, y, 0);
renderScaledQuad(matrixStack, builder, scale);
matrixStack.pop();
matrixStack.popPose();
}
matrixStack.pop();
matrixStack.popPose();
}
private static void renderScaledQuad(final MatrixStack matrixStack, final IVertexBuilder builder, final float scale) {
matrixStack.push();
matrixStack.pushPose();
matrixStack.scale(scale, scale, scale);
renderQuad(matrixStack.getLast().getMatrix(), builder);
matrixStack.pop();
renderQuad(matrixStack.last().pose(), builder);
matrixStack.popPose();
}
private static void renderQuad(final Matrix4f matrix, final IVertexBuilder builder) {
@@ -72,20 +72,20 @@ public final class ChargerTileEntityRenderer extends TileEntityRenderer<ChargerT
// because methods may return the underlying vertex builder, so e.g. calling
// buffer.pos(...).tex(...) will not actually call SpriteAwareVertexBuilder.tex(...)
// but SpriteAwareVertexBuilder.vertexBuilder.tex(...), skipping the UV remapping.
builder.pos(matrix, -0.5f, 0, -0.5f);
builder.tex(0, 0);
builder.vertex(matrix, -0.5f, 0, -0.5f);
builder.uv(0, 0);
builder.endVertex();
builder.pos(matrix, -0.5f, 0, 0.5f);
builder.tex(0, 1);
builder.vertex(matrix, -0.5f, 0, 0.5f);
builder.uv(0, 1);
builder.endVertex();
builder.pos(matrix, 0.5f, 0, 0.5f);
builder.tex(1, 1);
builder.vertex(matrix, 0.5f, 0, 0.5f);
builder.uv(1, 1);
builder.endVertex();
builder.pos(matrix, 0.5f, 0, -0.5f);
builder.tex(1, 0);
builder.vertex(matrix, 0.5f, 0, -0.5f);
builder.uv(1, 0);
builder.endVertex();
}
}

View File

@@ -31,9 +31,9 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
public static final ResourceLocation OVERLAY_STATUS_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_status");
public static final ResourceLocation OVERLAY_TERMINAL_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_terminal");
private static final RenderMaterial TEXTURE_POWER = new RenderMaterial(PlayerContainer.LOCATION_BLOCKS_TEXTURE, OVERLAY_POWER_LOCATION);
private static final RenderMaterial TEXTURE_STATUS = new RenderMaterial(PlayerContainer.LOCATION_BLOCKS_TEXTURE, OVERLAY_STATUS_LOCATION);
private static final RenderMaterial TEXTURE_TERMINAL = new RenderMaterial(PlayerContainer.LOCATION_BLOCKS_TEXTURE, OVERLAY_TERMINAL_LOCATION);
private static final RenderMaterial TEXTURE_POWER = new RenderMaterial(PlayerContainer.BLOCK_ATLAS, OVERLAY_POWER_LOCATION);
private static final RenderMaterial TEXTURE_STATUS = new RenderMaterial(PlayerContainer.BLOCK_ATLAS, OVERLAY_STATUS_LOCATION);
private static final RenderMaterial TEXTURE_TERMINAL = new RenderMaterial(PlayerContainer.BLOCK_ATLAS, OVERLAY_TERMINAL_LOCATION);
///////////////////////////////////////////////////////////////////
@@ -45,23 +45,23 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
@Override
public void render(final ComputerTileEntity tileEntity, final float partialTicks, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int light, final int overlay) {
final Direction blockFacing = tileEntity.getBlockState().get(ComputerBlock.HORIZONTAL_FACING);
final Vector3d cameraPosition = renderDispatcher.renderInfo.getRenderViewEntity().getEyePosition(partialTicks);
final Direction blockFacing = tileEntity.getBlockState().getValue(ComputerBlock.FACING);
final Vector3d cameraPosition = renderer.camera.getEntity().getEyePosition(partialTicks);
// If viewer is not in front of the block we can skip all of the rest, it cannot be visible.
// We check against the center of the block instead of the actual relevant face for simplicity.
final Vector3d relativeCameraPosition = cameraPosition.subtract(Vector3d.copyCentered(tileEntity.getPos()));
final double projectedCameraPosition = relativeCameraPosition.dotProduct(Vector3d.copy(blockFacing.getDirectionVec()));
final Vector3d relativeCameraPosition = cameraPosition.subtract(Vector3d.atCenterOf(tileEntity.getBlockPos()));
final double projectedCameraPosition = relativeCameraPosition.dot(Vector3d.atLowerCornerOf(blockFacing.getNormal()));
if (projectedCameraPosition <= 0) {
return;
}
matrixStack.push();
matrixStack.pushPose();
// Align with front face of block.
final Quaternion rotation = new Quaternion(Vector3f.YN, blockFacing.getHorizontalAngle() + 180, true);
final Quaternion rotation = new Quaternion(Vector3f.YN, blockFacing.toYRot() + 180, true);
matrixStack.translate(0.5f, 0, 0.5f);
matrixStack.rotate(rotation);
matrixStack.mulPose(rotation);
matrixStack.translate(-0.5f, 0, -0.5f);
// Flip and align with top left corner.
@@ -79,7 +79,7 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
}
matrixStack.translate(0, 0, -0.1f);
final Matrix4f matrix = matrixStack.getLast().getMatrix();
final Matrix4f matrix = matrixStack.last().pose();
switch (tileEntity.getVirtualMachine().getBusState()) {
case SCAN_PENDING:
@@ -106,15 +106,15 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
break;
}
matrixStack.pop();
matrixStack.popPose();
}
///////////////////////////////////////////////////////////////////
private void renderTerminal(final ComputerTileEntity tileEntity, final MatrixStack stack, final IRenderTypeBuffer buffer, final Vector3d cameraPosition) {
// Render terminal content if close enough.
if (Vector3d.copyCentered(tileEntity.getPos()).isWithinDistanceOf(cameraPosition, 6f)) {
stack.push();
if (Vector3d.atCenterOf(tileEntity.getBlockPos()).closerThan(cameraPosition, 6f)) {
stack.pushPose();
stack.translate(2, 2, -0.9f);
// Scale to make terminal fit fully.
@@ -134,25 +134,25 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
stack.scale(scale, scale, 1f);
// TODO Make terminal renderer use buffer+rendertype.
GlStateManager.enableBlend();
GlStateManager.enableDepthTest();
GlStateManager.depthMask(false);
GlStateManager._enableBlend();
GlStateManager._enableDepthTest();
GlStateManager._depthMask(false);
terminal.render(stack);
stack.pop();
stack.popPose();
} else {
stack.push();
stack.pushPose();
stack.translate(0, 0, -0.9f);
final Matrix4f matrix = stack.getLast().getMatrix();
renderQuad(matrix, TEXTURE_TERMINAL.getBuffer(buffer, CustomRenderType::getUnlitBlock));
final Matrix4f matrix = stack.last().pose();
renderQuad(matrix, TEXTURE_TERMINAL.buffer(buffer, CustomRenderType::getUnlitBlock));
stack.pop();
stack.popPose();
}
}
private void renderStatusText(final ComputerTileEntity tileEntity, final MatrixStack stack, final Vector3d cameraPosition) {
if (!Vector3d.copyCentered(tileEntity.getPos()).isWithinDistanceOf(cameraPosition, 12f)) {
if (!Vector3d.atCenterOf(tileEntity.getBlockPos()).closerThan(cameraPosition, 12f)) {
return;
}
@@ -161,32 +161,32 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
return;
}
stack.push();
stack.pushPose();
stack.translate(3, 3, -0.9f);
drawText(stack, bootError);
stack.pop();
stack.popPose();
}
private void drawText(final MatrixStack stack, final ITextComponent text) {
final int maxWidth = 100;
stack.push();
stack.pushPose();
stack.scale(10f / maxWidth, 10f / maxWidth, 10f / maxWidth);
final FontRenderer fontRenderer = renderDispatcher.getFontRenderer();
final List<ITextProperties> wrappedText = renderDispatcher.getFontRenderer().getCharacterManager().func_238362_b_(text, maxWidth, Style.EMPTY);
final FontRenderer fontRenderer = renderer.font;
final List<ITextProperties> 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<Compute
private void renderStatus(final Matrix4f matrix, final IRenderTypeBuffer buffer, final int frequency) {
if (frequency <= 0 || (((System.currentTimeMillis() + hashCode()) / frequency) % 2) == 1) {
renderQuad(matrix, TEXTURE_STATUS.getBuffer(buffer, CustomRenderType::getUnlitBlock));
renderQuad(matrix, TEXTURE_STATUS.buffer(buffer, CustomRenderType::getUnlitBlock));
}
}
private void renderPower(final Matrix4f matrix, final IRenderTypeBuffer buffer) {
renderQuad(matrix, TEXTURE_POWER.getBuffer(buffer, CustomRenderType::getUnlitBlock));
renderQuad(matrix, TEXTURE_POWER.buffer(buffer, CustomRenderType::getUnlitBlock));
}
private static void renderQuad(final Matrix4f matrix, final IVertexBuilder builder) {
@@ -208,20 +208,20 @@ public final class ComputerTileEntityRenderer extends TileEntityRenderer<Compute
// because methods may return the underlying vertex builder, so e.g. calling
// buffer.pos(...).tex(...) will not actually call SpriteAwareVertexBuilder.tex(...)
// but SpriteAwareVertexBuilder.vertexBuilder.tex(...), skipping the UV remapping.
builder.pos(matrix, 0, 0, 0);
builder.tex(0, 0);
builder.vertex(matrix, 0, 0, 0);
builder.uv(0, 0);
builder.endVertex();
builder.pos(matrix, 0, 16, 0);
builder.tex(0, 1);
builder.vertex(matrix, 0, 16, 0);
builder.uv(0, 1);
builder.endVertex();
builder.pos(matrix, 16, 16, 0);
builder.tex(1, 1);
builder.vertex(matrix, 16, 16, 0);
builder.uv(1, 1);
builder.endVertex();
builder.pos(matrix, 16, 0, 0);
builder.tex(1, 0);
builder.vertex(matrix, 16, 0, 0);
builder.uv(1, 0);
builder.endVertex();
}
}

View File

@@ -24,21 +24,21 @@ public final class DiskDriveTileEntityRenderer extends TileEntityRenderer<DiskDr
@Override
public void render(final DiskDriveTileEntity tileEntity, final float partialTicks, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int light, final int overlay) {
final ItemStack stack = tileEntity.getFloppy();
final Direction blockFacing = tileEntity.getBlockState().get(DiskDriveBlock.HORIZONTAL_FACING);
final int neighborLight = WorldRenderer.getCombinedLight(renderDispatcher.world, tileEntity.getPos().offset(blockFacing));
final Direction blockFacing = tileEntity.getBlockState().getValue(DiskDriveBlock.FACING);
final int neighborLight = WorldRenderer.getLightColor(renderer.level, tileEntity.getBlockPos().relative(blockFacing));
final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
matrixStack.push();
matrixStack.pushPose();
matrixStack.translate(0.5f, 0.5f, 0.5f);
matrixStack.rotate(Vector3f.YN.rotationDegrees(blockFacing.getHorizontalAngle()));
matrixStack.mulPose(Vector3f.YN.rotationDegrees(blockFacing.toYRot()));
matrixStack.translate(0.0f, 0.0f, 0.5f);
matrixStack.rotate(Vector3f.XN.rotationDegrees(90));
matrixStack.mulPose(Vector3f.XN.rotationDegrees(90));
matrixStack.translate(0.0f, 0.2375f, 2.5f / 16f);
matrixStack.scale(0.55f, 0.55f, 0.55f);
itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.FIXED, neighborLight, overlay, matrixStack, buffer);
itemRenderer.renderStatic(stack, ItemCameraTransforms.TransformType.FIXED, neighborLight, overlay, matrixStack, buffer);
matrixStack.pop();
matrixStack.popPose();
}
}

View File

@@ -21,17 +21,17 @@ public final class NetworkConnectorTileEntityRenderer extends TileEntityRenderer
// We do cable rendering as a fall-back in the TESR when Fabulous rendering is enabled.
// We need to do this because there's no hook to render before the Fabulous full-screen
// effects are rendered, which, sadly, completely ruin the depth buffer for us.
if (!Minecraft.isFabulousGraphicsEnabled()) {
if (!Minecraft.useShaderTransparency()) {
return;
}
final BlockPos from = connector.getPos();
final BlockPos from = connector.getBlockPos();
matrixStack.push();
matrixStack.pushPose();
matrixStack.translate(-from.getX(), -from.getY(), -from.getZ());
NetworkCableRenderer.renderCablesFor(renderDispatcher.world, matrixStack, renderDispatcher.renderInfo.getProjectedView(), connector);
NetworkCableRenderer.renderCablesFor(renderer.level, matrixStack, renderer.camera.getPosition(), connector);
matrixStack.pop();
matrixStack.popPose();
}
}

View File

@@ -15,14 +15,14 @@ public final class RobotItemStackRenderer extends ItemStackTileEntityRenderer {
///////////////////////////////////////////////////////////////////
@Override
public void func_239207_a_(final ItemStack stack, final ItemCameraTransforms.TransformType transformType, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int combinedLight, final int combinedOverlay) {
matrixStack.push();
public void renderByItem(final ItemStack stack, final ItemCameraTransforms.TransformType transformType, final MatrixStack matrixStack, final IRenderTypeBuffer buffer, final int combinedLight, final int combinedOverlay) {
matrixStack.pushPose();
matrixStack.translate(0.5, 0, 0.5);
final IVertexBuilder builder = buffer.getBuffer(model.getRenderType(RobotModel.ROBOT_ENTITY_TEXTURE));
model.render(matrixStack, builder, combinedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
final IVertexBuilder builder = buffer.getBuffer(model.renderType(RobotModel.ROBOT_ENTITY_TEXTURE));
model.renderToBuffer(matrixStack, builder, combinedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
matrixStack.pop();
matrixStack.popPose();
}
}

View File

@@ -52,7 +52,7 @@ public final class BusCableBlock extends Block {
INTERFACE;
@Override
public String getString() {
public String getSerializedName() {
switch (this) {
case NONE:
return "none";
@@ -87,7 +87,7 @@ public final class BusCableBlock extends Block {
public static ConnectionType getConnectionType(final BlockState state, @Nullable final Direction direction) {
if (direction != null) {
return state.get(BusCableBlock.FACING_TO_CONNECTION_MAP.get(direction));
return state.getValue(BusCableBlock.FACING_TO_CONNECTION_MAP.get(direction));
} else {
return ConnectionType.NONE;
}
@@ -96,7 +96,7 @@ public final class BusCableBlock extends Block {
public static int getInterfaceCount(final BlockState state) {
int partCount = 0;
for (final EnumProperty<ConnectionType> 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<ConnectionType> 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<BusCableBlock.ConnectionType> 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<ItemStack> getDrops(final BlockState state, final LootContext.Builder builder) {
final List<ItemStack> 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<Direction, EnumProperty<ConnectionType>> 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<Block, BlockState> builder) {
super.fillStateContainer(builder);
protected void createBlockStateDefinition(final StateContainer.Builder<Block, BlockState> 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<ConnectionType> 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;
}

View File

@@ -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<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(HorizontalBlock.HORIZONTAL_FACING);
protected void createBlockStateDefinition(final StateContainer.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(HorizontalBlock.FACING);
}
}

View File

@@ -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<ItemStack> items) {
super.fillItemGroup(group, items);
public void fillItemCategory(final ItemGroup group, final NonNullList<ItemStack> items) {
super.fillItemCategory(group, items);
items.add(getPreconfiguredComputer());
}
@OnlyIn(Dist.CLIENT)
@Override
public void addInformation(final ItemStack stack, @Nullable final IBlockReader world, final List<ITextComponent> tooltip, final ITooltipFlag advanced) {
super.addInformation(stack, world, tooltip, advanced);
public void appendHoverText(final ItemStack stack, @Nullable final IBlockReader world, final List<ITextComponent> 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<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(HORIZONTAL_FACING);
protected void createBlockStateDefinition(final StateContainer.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
///////////////////////////////////////////////////////////////////

View File

@@ -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());
}

View File

@@ -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<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(HORIZONTAL_FACING);
protected void createBlockStateDefinition(final StateContainer.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
}

View File

@@ -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<Block, BlockState> builder) {
builder.add(FACE, HORIZONTAL_FACING);
protected void createBlockStateDefinition(final StateContainer.Builder<Block, BlockState> builder) {
builder.add(FACE, FACING);
}
}

View File

@@ -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<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(HORIZONTAL_FACING);
protected void createBlockStateDefinition(final StateContainer.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
}

View File

@@ -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<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(HORIZONTAL_FACING);
protected void createBlockStateDefinition(final StateContainer.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
}

View File

@@ -54,7 +54,7 @@ public abstract class AbstractGroupingDeviceBusElement<TProvider extends IForgeR
final CompoundNBT sideTag = new CompoundNBT();
sideTag.putUniqueId(GROUP_ID_TAG_NAME, groupIds[i]);
sideTag.putUUID(GROUP_ID_TAG_NAME, groupIds[i]);
sideTag.put(GROUP_DATA_TAG_NAME, groupData[i]);
listTag.add(sideTag);
@@ -68,8 +68,8 @@ public abstract class AbstractGroupingDeviceBusElement<TProvider extends IForgeR
for (int i = 0; i < count; i++) {
final CompoundNBT sideTag = nbt.getCompound(i);
if (sideTag.hasUniqueId(GROUP_ID_TAG_NAME)) {
groupIds[i] = sideTag.getUniqueId(GROUP_ID_TAG_NAME);
if (sideTag.hasUUID(GROUP_ID_TAG_NAME)) {
groupIds[i] = sideTag.getUUID(GROUP_ID_TAG_NAME);
}
if (sideTag.contains(GROUP_DATA_TAG_NAME, NBTTagIds.TAG_COMPOUND)) {
groupData[i] = sideTag.getCompound(GROUP_DATA_TAG_NAME);

View File

@@ -43,7 +43,7 @@ public class TileEntityDeviceBusController extends CommonDeviceBusController {
protected void onAfterBusScan() {
super.onAfterBusScan();
final World world = tileEntity.getWorld();
final World world = tileEntity.getLevel();
if (world == null) {
return;
}
@@ -52,19 +52,19 @@ public class TileEntityDeviceBusController extends CommonDeviceBusController {
for (final DeviceBusElement element : getElements()) {
if (element instanceof BlockDeviceBusElement) {
final BlockDeviceBusElement blockElement = (BlockDeviceBusElement) element;
final IWorld elementWorld = blockElement.getWorld();
final IWorld elementWorld = blockElement.getLevel();
final BlockPos elementPosition = blockElement.getPosition();
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.offset(Direction.NORTH)));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.offset(Direction.EAST)));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.offset(Direction.SOUTH)));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.offset(Direction.WEST)));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.NORTH)));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.EAST)));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.SOUTH)));
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.WEST)));
}
}
// Do not track the chunk the controller itself is in -- this is unneeded because
// we expect the controller to be disposed if its chunk is unloaded.
newTrackedChunks.remove(new TrackedChunk(world, tileEntity.getPos()));
newTrackedChunks.remove(new TrackedChunk(world, tileEntity.getBlockPos()));
final HashSet<TrackedChunk> removedChunks = new HashSet<>(trackedChunks);
removedChunks.removeAll(newTrackedChunks);

View File

@@ -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<Collection<LazyOptional<DeviceBusElement>>> 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<BlockDeviceInfo> 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;
}

View File

@@ -54,7 +54,7 @@ public final class FileSystems {
LOGGER.info("Searching for datapack filesystems...");
final Collection<ResourceLocation> fileSystemDescriptorLocations = resourceManager
.getAllResourceLocations("file_systems", s -> s.endsWith(".json"));
.listResources("file_systems", s -> s.endsWith(".json"));
final ArrayList<ZipStreamFileSystem> fileSystems = new ArrayList<>();
final Object2IntArrayMap<ZipStreamFileSystem> fileSystemOrder = new Object2IntArrayMap<>();
@@ -117,7 +117,7 @@ public final class FileSystems {
public CompletableFuture<Void> 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);
}
}
}

View File

@@ -111,14 +111,14 @@ public abstract class AbstractBlockDeviceVMDevice<TBlock extends BlockDevice, TI
getSerializationStream(data).ifPresent(stream -> 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<TBlock extends BlockDevice, TI
}
if (blobHandle != null) {
tag.putUniqueId(BLOB_HANDLE_TAG_NAME, blobHandle);
tag.putUUID(BLOB_HANDLE_TAG_NAME, blobHandle);
}
return tag;
@@ -149,8 +149,8 @@ public abstract class AbstractBlockDeviceVMDevice<TBlock extends BlockDevice, TI
@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(DEVICE_TAG_NAME, NBTTagIds.TAG_COMPOUND)) {

View File

@@ -76,7 +76,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy<ItemStack>
@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<ItemStack>
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<ItemStack>
final List<ItemEntity> 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<ItemStack>
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<ItemStack>
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<ItemStack>
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<ItemStack>
@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<ItemStack>
beginCooldown();
if (identity.getDamage() == 0) {
if (identity.getDamageValue() == 0) {
return false;
}
@@ -196,7 +196,7 @@ public final class BlockOperationsModuleDevice extends IdentityProxy<ItemStack>
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<ItemStack>
return false;
}
identity.setDamage(identity.getDamage() - repairValue);
identity.setDamageValue(identity.getDamageValue() - repairValue);
return true;
}
@@ -214,11 +214,11 @@ public final class BlockOperationsModuleDevice extends IdentityProxy<ItemStack>
///////////////////////////////////////////////////////////////////
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<ItemStack>
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<ItemEntity> 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<ItemStack>
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<ItemStack>
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<ItemStack>
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;
}

View File

@@ -78,7 +78,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy<ItemSta
// And if putting it back fails, just drop it. Avoid destroying items.
if (!remaining.isEmpty()) {
entity.entityDropItem(remaining);
entity.spawnAtLocation(remaining);
}
}
@@ -112,7 +112,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy<ItemSta
if (!stack.isEmpty()) {
dropped += stack.getCount();
entity.entityDropItem(stack);
entity.spawnAtLocation(stack);
}
return dropped;
@@ -146,7 +146,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy<ItemSta
if (!stack.isEmpty()) {
dropped += stack.getCount();
entity.entityDropItem(stack);
entity.spawnAtLocation(stack);
}
return dropped;
@@ -187,9 +187,9 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy<ItemSta
}
if (direction.getAxis().isHorizontal()) {
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();
}
}
@@ -209,8 +209,8 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy<ItemSta
}
private Stream<IItemHandler> 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<IItemHandler> getItemStackHandlersAt(final Vector3d position, final Direction side) {
@@ -218,8 +218,8 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy<ItemSta
}
private Stream<IItemHandler> 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<ItemSta
private Stream<IItemHandler> 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<ItemSta
}
private List<ItemEntity> 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<ItemSta
// And if putting it back fails, just drop it. Avoid destroying items.
if (!overflow.isEmpty()) {
remaining -= overflow.getCount();
entity.entityDropItem(overflow);
entity.spawnAtLocation(overflow);
}
}
@@ -331,7 +331,7 @@ public final class InventoryOperationsModuleDevice extends IdentityProxy<ItemSta
// And if putting it back fails, just drop it. Avoid destroying items.
if (!overflow.isEmpty()) {
// NB: not counting this towards taken count since it did not end up in our inventory.
entity.entityDropItem(overflow);
entity.spawnAtLocation(overflow);
}
return taken;

View File

@@ -83,7 +83,7 @@ public final class MemoryDevice extends IdentityProxy<ItemStack> 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<ItemStack> 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));

View File

@@ -64,7 +64,7 @@ public final class RedstoneInterfaceCardItemDevice extends IdentityProxy<ItemSta
@Override
public <T> LazyOptional<T> getCapability(@Nonnull final Capability<T> 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<ItemSta
@Callback(name = GET_REDSTONE_INPUT)
public int getRedstoneInput(@Parameter(SIDE) final Direction side) {
final World world = tileEntity.getWorld();
final World world = tileEntity.getLevel();
if (world == null) {
return 0;
}
final BlockPos pos = tileEntity.getPos();
final BlockPos pos = tileEntity.getBlockPos();
final Direction direction = HorizontalBlockUtils.toGlobal(tileEntity.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()];
return output[side.get3DDataValue()];
}
@Callback(name = SET_REDSTONE_OUTPUT)
public void setRedstoneOutput(@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(tileEntity.getBlockState(), side);
if (direction != null) {
@@ -162,12 +162,12 @@ public final class RedstoneInterfaceCardItemDevice extends IdentityProxy<ItemSta
///////////////////////////////////////////////////////////////////
private void notifyNeighbor(final Direction direction) {
final World world = tileEntity.getWorld();
final World world = tileEntity.getLevel();
if (world == null) {
return;
}
world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockState().getBlock());
world.notifyNeighborsOfStateChange(tileEntity.getPos().offset(direction), tileEntity.getBlockState().getBlock());
world.updateNeighborsAt(tileEntity.getBlockPos(), tileEntity.getBlockState().getBlock());
world.updateNeighborsAt(tileEntity.getBlockPos().relative(direction), tileEntity.getBlockState().getBlock());
}
}

View File

@@ -14,7 +14,7 @@ import net.minecraftforge.common.util.LazyOptional;
public final class BlockStateDeviceProvider extends AbstractBlockDeviceProvider {
@Override
public LazyOptional<Device> 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);

View File

@@ -17,7 +17,7 @@ public final class DiskDriveDeviceProvider extends AbstractTileEntityDeviceProvi
protected LazyOptional<Device> 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();
}

View File

@@ -25,7 +25,7 @@ public abstract class AbstractTileEntityDeviceProvider<T extends TileEntity> ext
@SuppressWarnings("unchecked")
@Override
public final LazyOptional<Device> 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();
}

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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());
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -23,11 +23,11 @@ public final class TypedSlotItemHandler extends SlotItemHandler {
@Nullable
@Override
public Pair<ResourceLocation, ResourceLocation> getBackground() {
if (getHasStack()) {
return super.getBackground();
public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
if (hasItem()) {
return super.getNoItemIcon();
} else {
return Pair.of(PlayerContainer.LOCATION_BLOCKS_TEXTURE, deviceType.getBackgroundIcon());
return Pair.of(PlayerContainer.BLOCK_ATLAS, deviceType.getBackgroundIcon());
}
}
}

View File

@@ -16,7 +16,7 @@ public final class Entities {
///////////////////////////////////////////////////////////////////
public static final RegistryObject<EntityType<RobotEntity>> ROBOT = register("robot", RobotEntity::new, EntityClassification.MISC, b -> b.size(14f / 16f, 14f / 16f).immuneToFire().disableSummoning());
public static final RegistryObject<EntityType<RobotEntity>> 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 <T extends Entity> RegistryObject<EntityType<T>> register(final String name, final EntityType.IFactory<T> factory, final EntityClassification classification, final Function<EntityType.Builder<T>, EntityType.Builder<T>> 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));
}
}

View File

@@ -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<BlockPos> TARGET_POSITION = EntityDataManager.createKey(RobotEntity.class, DataSerializers.BLOCK_POS);
public static final DataParameter<Direction> TARGET_DIRECTION = EntityDataManager.createKey(RobotEntity.class, DataSerializers.DIRECTION);
public static final DataParameter<Byte> SELECTED_SLOT = EntityDataManager.createKey(RobotEntity.class, DataSerializers.BYTE);
public static final DataParameter<BlockPos> TARGET_POSITION = EntityDataManager.defineId(RobotEntity.class, DataSerializers.BLOCK_POS);
public static final DataParameter<Direction> TARGET_DIRECTION = EntityDataManager.defineId(RobotEntity.class, DataSerializers.DIRECTION);
public static final DataParameter<Byte> 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<ItemStack> 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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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);
}
}
}

View File

@@ -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(")");
}
}

View File

@@ -6,6 +6,6 @@ public final class BlockOperationsModule extends ModItem {
///////////////////////////////////////////////////////////////////
public BlockOperationsModule() {
super(createProperties().maxDamage(DURABILITY));
super(createProperties().durability(DURABILITY));
}
}

View File

@@ -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<ITextComponent> tooltip, final ITooltipFlag flag) {
super.addInformation(stack, world, tooltip, flag);
public void appendHoverText(final ItemStack stack, final @Nullable World world, final List<ITextComponent> 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;

View File

@@ -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<ITextComponent> tooltip, final ITooltipFlag flag) {
super.addInformation(stack, world, tooltip, flag);
public void appendHoverText(final ItemStack stack, final @Nullable World world, final List<ITextComponent> 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<ItemStack> items) {
if (isInGroup(group)) {
public void fillItemCategory(final ItemGroup group, final NonNullList<ItemStack> items) {
if (allowdedIn(group)) {
items.add(new ItemStack(this));
}
}
@Override
public void addToBlockToItemMap(final Map<Block, Item> map, final Item item) {
public void registerBlocks(final Map<Block, Item> 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<ConnectionType> 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;

View File

@@ -14,9 +14,9 @@ public final class ChargerItem extends ModBlockItem {
///////////////////////////////////////////////////////////////////
@Override
public void fillItemGroup(final ItemGroup group, final NonNullList<ItemStack> items) {
public void fillItemCategory(final ItemGroup group, final NonNullList<ItemStack> items) {
if (Config.chargerUseEnergy()) {
super.fillItemGroup(group, items);
super.fillItemCategory(group, items);
}
}
}

View File

@@ -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";
}
}

View File

@@ -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";
}
}

View File

@@ -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";
}
}

View File

@@ -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";
}
}

View File

@@ -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());
}
};

View File

@@ -8,7 +8,8 @@ public final class MemoryItem extends AbstractStorageItem {
///////////////////////////////////////////////////////////////////
@Override
protected String getDefaultTranslationKey() {
protected String getOrCreateDescriptionId() {
return "item.oc2.memory";
}
}

View File

@@ -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<ITextComponent> tooltip, final ITooltipFlag flag) {
public void appendHoverText(final ItemStack stack, @Nullable final World world, final List<ITextComponent> tooltip, final ITooltipFlag flag) {
TooltipUtils.tryAddDescription(stack, tooltip);
super.addInformation(stack, world, tooltip, flag);
super.appendHoverText(stack, world, tooltip, flag);
}
///////////////////////////////////////////////////////////////////

View File

@@ -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<ITextComponent> tooltip, final ITooltipFlag flag) {
super.addInformation(stack, world, tooltip, flag);
public void appendHoverText(final ItemStack stack, @Nullable final World world, final List<ITextComponent> tooltip, final ITooltipFlag flag) {
super.appendHoverText(stack, world, tooltip, flag);
TooltipUtils.tryAddDescription(stack, tooltip);
}

View File

@@ -24,51 +24,51 @@ public final class NetworkCableItem extends ModItem {
///////////////////////////////////////////////////////////////////
@Override
public ActionResult<ItemStack> onItemRightClick(final World world, final PlayerEntity player, final Hand hand) {
if (player.isSneaking()) {
public ActionResult<ItemStack> 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;
}
}

View File

@@ -37,8 +37,8 @@ public final class RobotItem extends ModItem {
///////////////////////////////////////////////////////////////////
@Override
public void addInformation(final ItemStack stack, @Nullable final World world, final List<ITextComponent> tooltip, final ITooltipFlag flag) {
super.addInformation(stack, world, tooltip, flag);
public void appendHoverText(final ItemStack stack, @Nullable final World world, final List<ITextComponent> 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;
}

View File

@@ -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

View File

@@ -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<ItemStack> getRemainingItems(final CraftingInventory inventory) {
final NonNullList<ItemStack> result = NonNullList.withSize(inventory.getSizeInventory(), ItemStack.EMPTY);
final NonNullList<ItemStack> 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<IRecipeSerializer<?>> implements IRecipeSerializer<WrenchRecipe> {
@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);
}
}
}

View File

@@ -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 <T extends TileEntity> void withClientTileEntityAt(final BlockPos pos, final Class<T> type, final Consumer<T> 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 <T extends Entity> void withClientEntity(final int id, final Class<T> type, final Consumer<T> 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);
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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<NetworkEvent.Context> 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);
}
///////////////////////////////////////////////////////////////////

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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 {

View File

@@ -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);
}
}

View File

@@ -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<NetworkEvent.Context> 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);
}
}

View File

@@ -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();
}
}

View File

@@ -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());
}

View File

@@ -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));
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

Some files were not shown because too many files have changed in this diff Show More