1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-28 16:22:18 +00:00

Attempting to update to 1.17.

Todo: refactor rendering to avoid using direct GL calls, instead I've
read that you could use a `BufferBuilder` but need to do more looking
into that.
Also need to update some block entity things, since some calls are also
gone.
This commit is contained in:
coolsa 2021-09-23 23:22:54 -06:00
parent 0028ad8f54
commit 0dc34a7dbe
93 changed files with 648 additions and 597 deletions

View File

@ -12,10 +12,10 @@ jobs:
- name: Checkout submodules - name: Checkout submodules
run: git submodule update --init --recursive run: git submodule update --init --recursive
- name: Set up Java 8 - name: Set up Java 16
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 8 java-version: 16
- name: Cache gradle dependencies - name: Cache gradle dependencies
uses: actions/cache@v2 uses: actions/cache@v2

View File

@ -1,7 +1,7 @@
<img src="logo.png" alt="CC: Restitched" width="100%"/> <img src="logo.png" alt="CC: Restitched" width="100%"/>
[![Current build status](https://github.com/Merith-TK/cc-restitched/workflows/Build/badge.svg)](https://github.com/Merith-TK/cc-restitched/actions "Current build status") [![Current build status](https://github.com/Merith-TK/cc-restitched/workflows/Build/badge.svg)](https://github.com/Merith-TK/cc-restitched/actions "Current build status")
[![Download CC: Restitched on CurseForge](http://cf.way2muchnoise.eu/title/cc-restitched.svg)](https://www.curseforge.com/minecraft/mc-mods/cc-restitched-updated "Download CC: Restitched on CurseForge") [![Download CC: Restitched on CurseForge](https://camo.githubusercontent.com/07622e6662ef5ead080c4840ef6514a34e079d63015f7e51c977a55b1881dfb9/687474703a2f2f63662e776179326d7563686e6f6973652e65752f7469746c652f63632d726573746974636865642e737667)](https://www.curseforge.com/minecraft/mc-mods/cc-restitched "Download CC: Restitched on CurseForge")
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-908a85?logo=gitpod)](https://gitpod.io/#https://github.com/Merith-TK/cc-restitched) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-908a85?logo=gitpod)](https://gitpod.io/#https://github.com/Merith-TK/cc-restitched)
# CC: R Version VS CC: T Version # CC: R Version VS CC: T Version

View File

@ -7,7 +7,7 @@ plugins {
java { java {
toolchain { toolchain {
languageVersion = JavaLanguageVersion.of(8) languageVersion = JavaLanguageVersion.of(16)
vendor = JvmVendorSpec.ADOPTOPENJDK vendor = JvmVendorSpec.ADOPTOPENJDK
} }
} }
@ -55,8 +55,8 @@ dependencies {
include 'com.electronwill.night-config:toml:3.6.3' include 'com.electronwill.night-config:toml:3.6.3'
include "me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}" include "me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}"
modRuntime "me.shedaniel:RoughlyEnoughItems-api:5.12.248" modRuntime "me.shedaniel:RoughlyEnoughItems-api:6.0.254-alpha"
modRuntime "me.shedaniel:RoughlyEnoughItems:5.12.248" modRuntime "me.shedaniel:RoughlyEnoughItems:6.0.254-alpha"
} }
processResources { processResources {

View File

@ -5,13 +5,13 @@ org.gradle.jvmargs=-Xmx1G
mod_version=1.96.1-rc1 mod_version=1.96.1-rc1
# Minecraft properties # Minecraft properties
mc_version=1.16.5 mc_version=1.17
mappings_version=9 mappings_version=9
# Dependencies # Dependencies
cloth_config_version=4.11.26 cloth_config_version=5.0.34
fabric_loader_version=0.11.3 fabric_loader_version=0.11.6
fabric_api_version=0.32.0+1.16 fabric_api_version=0.36.0+1.16
jankson_version=1.2.0 jankson_version=1.2.0
modmenu_version=1.16.9 modmenu_version=2.0.2
cloth_api_version=1.4.5 cloth_api_version=2.0.54

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

178
gradlew.bat vendored
View File

@ -1,89 +1,89 @@
@rem @rem
@rem Copyright 2015 the original author or authors. @rem Copyright 2015 the original author or authors.
@rem @rem
@rem Licensed under the Apache License, Version 2.0 (the "License"); @rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License. @rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at @rem You may obtain a copy of the License at
@rem @rem
@rem https://www.apache.org/licenses/LICENSE-2.0 @rem https://www.apache.org/licenses/LICENSE-2.0
@rem @rem
@rem Unless required by applicable law or agreed to in writing, software @rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS, @rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter. @rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if "%ERRORLEVEL%" == "0" goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo. echo.
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation. echo location of your Java installation.
goto fail goto fail
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1 exit /b 1
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal
:omega :omega

View File

@ -8,7 +8,7 @@ package dan200.computercraft.api;
import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.ITurtleUpgrade;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -76,8 +76,8 @@ public interface IUpgradeBase
// A more expanded form of ItemStack.areShareTagsEqual, but allowing an empty tag to be equal to a // A more expanded form of ItemStack.areShareTagsEqual, but allowing an empty tag to be equal to a
// null one. // null one.
CompoundTag shareTag = stack.getTag(); NbtCompound shareTag = stack.getTag();
CompoundTag craftingShareTag = crafting.getTag(); NbtCompound craftingShareTag = crafting.getTag();
if( shareTag == craftingShareTag ) return true; if( shareTag == craftingShareTag ) return true;
if( shareTag == null ) return craftingShareTag.isEmpty(); if( shareTag == null ) return craftingShareTag.isEmpty();
if( craftingShareTag == null ) return shareTag.isEmpty(); if( craftingShareTag == null ) return shareTag.isEmpty();

View File

@ -13,7 +13,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager; import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.util.ModelIdentifier; import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.client.util.math.AffineTransformation; import net.minecraft.util.math.AffineTransformation;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;

View File

@ -8,7 +8,7 @@ package dan200.computercraft.api.pocket;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -73,7 +73,7 @@ public interface IPocketAccess
* @see #updateUpgradeNBTData() * @see #updateUpgradeNBTData()
*/ */
@Nonnull @Nonnull
CompoundTag getUpgradeNBTData(); NbtCompound getUpgradeNBTData();
/** /**
* Mark the upgrade-specific NBT as dirty. * Mark the upgrade-specific NBT as dirty.

View File

@ -53,7 +53,7 @@ public class FakePlayer extends ServerPlayerEntity
{ {
public FakePlayer( ServerWorld world, GameProfile gameProfile ) public FakePlayer( ServerWorld world, GameProfile gameProfile )
{ {
super( world.getServer(), world, gameProfile, new ServerPlayerInteractionManager( world ) ); super( world.getServer(), world, gameProfile );
networkHandler = new FakeNetHandler( this ); networkHandler = new FakeNetHandler( this );
} }
@ -128,7 +128,7 @@ public class FakePlayer extends ServerPlayerEntity
} }
@Override @Override
public void openEditBookScreen( ItemStack stack, Hand hand ) public void useBook( ItemStack stack, Hand hand )
{ {
} }
@ -137,30 +137,30 @@ public class FakePlayer extends ServerPlayerEntity
{ {
} }
@Override // @Override
public void onSlotUpdate( ScreenHandler container, int slot, ItemStack stack ) // public void onSlotUpdate( ScreenHandler container, int slot, ItemStack stack )
{ // {
} // }
//
@Override // @Override
public void onHandlerRegistered( ScreenHandler container, DefaultedList<ItemStack> defaultedList ) // public void onHandlerRegistered( ScreenHandler container, DefaultedList<ItemStack> defaultedList )
{ // {
} // }
//
@Override // @Override
public void onPropertyUpdate( ScreenHandler container, int key, int value ) // public void onPropertyUpdate( ScreenHandler container, int key, int value )
{ // {
} // }
@Override @Override
public void closeHandledScreen() public void closeHandledScreen()
{ {
} }
@Override // @Override
public void updateCursorStack() // public void updateCursorStack()
{ // {
} // }
@Override @Override
public int unlockRecipes( Collection<Recipe<?>> recipes ) public int unlockRecipes( Collection<Recipe<?>> recipes )
@ -191,17 +191,17 @@ public class FakePlayer extends ServerPlayerEntity
} }
@Override @Override
public void method_14222( EntityAnchorArgumentType.EntityAnchor self, Entity entity, EntityAnchorArgumentType.EntityAnchor target ) public void lookAtEntity( EntityAnchorArgumentType.EntityAnchor self, Entity entity, EntityAnchorArgumentType.EntityAnchor target )
{ {
} }
@Override @Override
protected void onStatusEffectApplied( StatusEffectInstance statusEffectInstance ) protected void onStatusEffectApplied( StatusEffectInstance statusEffectInstance, @Nullable Entity source )
{ {
} }
@Override @Override
protected void onStatusEffectUpgraded( StatusEffectInstance statusEffectInstance, boolean particles ) protected void onStatusEffectUpgraded( StatusEffectInstance statusEffectInstance, boolean particles, @Nullable Entity source )
{ {
} }
@ -215,10 +215,10 @@ public class FakePlayer extends ServerPlayerEntity
{ {
} }
@Override // @Override
public void setGameMode( GameMode gameMode ) // public void setGameMode( GameMode gameMode )
{ // {
} // }
@Override @Override
public void sendMessage( Text message, MessageType type, UUID senderUuid ) public void sendMessage( Text message, MessageType type, UUID senderUuid )
@ -232,15 +232,15 @@ public class FakePlayer extends ServerPlayerEntity
return "[Fake Player]"; return "[Fake Player]";
} }
@Override // @Override
public void sendResourcePackUrl( String url, String hash ) // public void sendResourcePackUrl( String url, String hash )
{ // {
} // }
@Override // @Override
public void onStoppedTracking( Entity entity ) // public void onStoppedTracking( Entity entity )
{ // {
} // }
@Override @Override
public void setCameraEntity( Entity entity ) public void setCameraEntity( Entity entity )

View File

@ -12,7 +12,7 @@ import dan200.computercraft.api.lua.MethodResult;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.util.ItemStorage; import dan200.computercraft.shared.util.ItemStorage;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -255,7 +255,7 @@ public interface ITurtleAccess
* @see #updateUpgradeNBTData(TurtleSide) * @see #updateUpgradeNBTData(TurtleSide)
*/ */
@Nonnull @Nonnull
CompoundTag getUpgradeNBTData( @Nullable TurtleSide side ); NbtCompound getUpgradeNBTData( @Nullable TurtleSide side );
/** /**
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the client and persisted. * Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the client and persisted.

View File

@ -14,7 +14,7 @@ import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*; import net.minecraft.client.render.*;
import net.minecraft.client.util.math.AffineTransformation; import net.minecraft.util.math.AffineTransformation;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -23,7 +23,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public final class FixedWidthFontRenderer public final class FixedWidthFontRenderer
{ { //FIXME Make this work like a gui, via BufferBuilder's
public static final int FONT_HEIGHT = 9; public static final int FONT_HEIGHT = 9;
public static final int FONT_WIDTH = 6; public static final int FONT_WIDTH = 6;
public static final float WIDTH = 256.0f; public static final float WIDTH = 256.0f;
@ -394,21 +394,21 @@ public final class FixedWidthFontRenderer
private static final VertexFormat FORMAT = VertexFormats.POSITION_COLOR_TEXTURE; private static final VertexFormat FORMAT = VertexFormats.POSITION_COLOR_TEXTURE;
static final RenderLayer MAIN = RenderLayer.of( "terminal_font", FORMAT, GL_MODE, 1024, false, false, // useDelegate, needsSorting static final RenderLayer MAIN = RenderLayer.of( "terminal_font", FORMAT, GL_MODE, 1024, false, false, // useDelegate, needsSorting
RenderLayer.MultiPhaseParameters.builder() RenderLayer.MultiPhaseParameters.Builder()
.texture( new RenderPhase.Texture( FONT, .texture( new RenderPhase.Texture( FONT,
false, false,
false ) ) // blur, minimap false ) ) // blur, minimap
.alpha( ONE_TENTH_ALPHA ) .transparency( TRANSLUCENT_TRANSPARENCY )
.lightmap( DISABLE_LIGHTMAP ) .lightmap( DISABLE_LIGHTMAP )
.writeMaskState( COLOR_MASK ) .writeMaskState( COLOR_MASK )
.build( false ) ); .build( false ) );
static final RenderLayer BLOCKER = RenderLayer.of( "terminal_blocker", FORMAT, GL_MODE, 256, false, false, // useDelegate, needsSorting static final RenderLayer BLOCKER = RenderLayer.of( "terminal_blocker", FORMAT, GL_MODE, 256, false, false, // useDelegate, needsSorting
RenderLayer.MultiPhaseParameters.builder() RenderLayer.MultiPhaseParameters.Builder()
.texture( new RenderPhase.Texture( FONT, .texture( new RenderPhase.Texture( FONT,
false, false,
false ) ) // blur, minimap false ) ) // blur, minimap
.alpha( ONE_TENTH_ALPHA ) .transparency( TRANSLUCENT_TRANSPARENCY )
.writeMaskState( ALL_MASK ) .writeMaskState( ALL_MASK )
.lightmap( DISABLE_LIGHTMAP ) .lightmap( DISABLE_LIGHTMAP )
.build( false ) ); .build( false ) );

View File

@ -28,6 +28,8 @@ import javax.annotation.Nonnull;
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER; import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN; import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN;
import java.util.List;
public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<T> public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<T>
{ {
protected final ComputerFamily family; protected final ComputerFamily family;
@ -78,7 +80,7 @@ public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<
terminal = new WidgetTerminal( client, () -> computer, termWidth, termHeight, MARGIN, MARGIN, MARGIN, MARGIN ); terminal = new WidgetTerminal( client, () -> computer, termWidth, termHeight, MARGIN, MARGIN, MARGIN, MARGIN );
terminalWrapper = new WidgetWrapper( terminal, MARGIN + border + x, MARGIN + border + y, termPxWidth, termPxHeight ); terminalWrapper = new WidgetWrapper( terminal, MARGIN + border + x, MARGIN + border + y, termPxWidth, termPxHeight );
children.add( terminalWrapper ); ((List<WidgetWrapper>)children()).add( terminalWrapper ); //FIXME: This is bad.
setFocused( terminalWrapper ); setFocused( terminalWrapper );
} }
@ -109,7 +111,7 @@ public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() ); terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
// Draw a border around the terminal // Draw a border around the terminal
RenderSystem.color4f( 1, 1, 1, 1 ); RenderSystem.clearColor( 1, 1, 1, 1 );
client.getTextureManager() client.getTextureManager()
.bindTexture( ComputerBorderRenderer.getTexture( family ) ); .bindTexture( ComputerBorderRenderer.getTexture( family ) );
ComputerBorderRenderer.render( terminalWrapper.getX() - MARGIN, terminalWrapper.getY() - MARGIN, ComputerBorderRenderer.render( terminalWrapper.getX() - MARGIN, terminalWrapper.getY() - MARGIN,
@ -144,7 +146,7 @@ public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<
public void removed() public void removed()
{ {
super.removed(); super.removed();
children.remove( terminal ); children().remove( terminal );
terminal = null; terminal = null;
client.keyboard.setRepeatEvents( false ); client.keyboard.setRepeatEvents( false );
} }

View File

@ -36,7 +36,7 @@ public class GuiDiskDrive extends HandledScreen<ContainerDiskDrive>
@Override @Override
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY ) protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
{ {
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); RenderSystem.clearColor( 1.0F, 1.0F, 1.0F, 1.0F );
client.getTextureManager() client.getTextureManager()
.bindTexture( BACKGROUND ); .bindTexture( BACKGROUND );
drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight ); drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight );

View File

@ -44,7 +44,7 @@ public class GuiPrinter extends HandledScreen<ContainerPrinter>
@Override @Override
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY ) protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
{ {
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); RenderSystem.clearColor( 1.0F, 1.0F, 1.0F, 1.0F );
client.getTextureManager() client.getTextureManager()
.bindTexture( BACKGROUND ); .bindTexture( BACKGROUND );
drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight ); drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight );

View File

@ -108,7 +108,7 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY ) protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
{ {
// Draw the printout // Draw the printout
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); RenderSystem.clearColor( 1.0f, 1.0f, 1.0f, 1.0f );
RenderSystem.enableDepthTest(); RenderSystem.enableDepthTest();
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance() VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance()

View File

@ -44,7 +44,7 @@ public class GuiTurtle extends GuiComputer<ContainerTurtle>
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() ); terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
// Draw border/inventory // Draw border/inventory
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); RenderSystem.clearColor( 1.0F, 1.0F, 1.0F, 1.0F );
client.getTextureManager() client.getTextureManager()
.bindTexture( texture ); .bindTexture( texture );
drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight ); drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight );

View File

@ -11,6 +11,7 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
@ -84,11 +85,11 @@ public class ComputerBorderRenderer
{ {
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer(); BufferBuilder buffer = tessellator.getBuffer();
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE ); buffer.begin( VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE );
render( IDENTITY, buffer, x, y, z, width, height ); render( IDENTITY, buffer, x, y, z, width, height );
RenderSystem.enableAlphaTest(); RenderSystem.enableDepthTest(); //TODO: enableAlphaTest(). FIXME
tessellator.draw(); tessellator.draw();
} }

View File

@ -13,12 +13,12 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.HeldItemRenderer; import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Arm; import net.minecraft.util.Arm;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3f;
@Environment( EnvType.CLIENT ) @Environment( EnvType.CLIENT )
public abstract class ItemMapLikeRenderer public abstract class ItemMapLikeRenderer
@ -75,18 +75,18 @@ public abstract class ItemMapLikeRenderer
HeldItemRendererAccess access = (HeldItemRendererAccess) renderer; HeldItemRendererAccess access = (HeldItemRendererAccess) renderer;
float pitchAngle = access.callGetMapAngle( pitch ); float pitchAngle = access.callGetMapAngle( pitch );
transform.translate( 0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f ); transform.translate( 0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( pitchAngle * -85.0f ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( pitchAngle * -85.0f ) );
if( !minecraft.player.isInvisible() ) if( !minecraft.player.isInvisible() )
{ {
transform.push(); transform.push();
transform.multiply( Vector3f.POSITIVE_Y.getDegreesQuaternion( 90.0F ) ); transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( 90.0F ) );
access.callRenderArm( transform, render, combinedLight, Arm.RIGHT ); access.callRenderArm( transform, render, combinedLight, Arm.RIGHT );
access.callRenderArm( transform, render, combinedLight, Arm.LEFT ); access.callRenderArm( transform, render, combinedLight, Arm.LEFT );
transform.pop(); transform.pop();
} }
float rX = MathHelper.sin( swingRt * (float) Math.PI ); float rX = MathHelper.sin( swingRt * (float) Math.PI );
transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( rX * 20.0F ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( rX * 20.0F ) );
transform.scale( 2.0F, 2.0F, 2.0F ); transform.scale( 2.0F, 2.0F, 2.0F );
renderItem( transform, render, stack ); renderItem( transform, render, stack );
@ -114,7 +114,7 @@ public abstract class ItemMapLikeRenderer
if( !minecraft.player.isInvisible() ) if( !minecraft.player.isInvisible() )
{ {
transform.push(); transform.push();
transform.multiply( Vector3f.POSITIVE_Z.getDegreesQuaternion( offset * 10f ) ); transform.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( offset * 10f ) );
((HeldItemRendererAccess) minecraft.getHeldItemRenderer()) ((HeldItemRendererAccess) minecraft.getHeldItemRenderer())
.callRenderArmHoldingItem( transform, render, combinedLight, equipProgress, swingProgress, side ); .callRenderArmHoldingItem( transform, render, combinedLight, equipProgress, swingProgress, side );
transform.pop(); transform.pop();
@ -130,8 +130,8 @@ public abstract class ItemMapLikeRenderer
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) ); float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI ); float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
transform.translate( offset * f3, f4 - 0.3f * f2, f5 ); transform.translate( offset * f3, f4 - 0.3f * f2, f5 );
transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( f2 * -45f ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( f2 * -45f ) );
transform.multiply( Vector3f.POSITIVE_Y.getDegreesQuaternion( offset * f2 * -30f ) ); transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( offset * f2 * -30f ) );
renderItem( transform, render, stack ); renderItem( transform, render, stack );

View File

@ -18,10 +18,11 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -64,8 +65,8 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
// Setup various transformations. Note that these are partially adapted from the corresponding method // Setup various transformations. Note that these are partially adapted from the corresponding method
// in ItemRenderer // in ItemRenderer
transform.push(); transform.push();
transform.multiply( Vector3f.POSITIVE_Y.getDegreesQuaternion( 180f ) ); transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( 180f ) );
transform.multiply( Vector3f.POSITIVE_Z.getDegreesQuaternion( 180f ) ); transform.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( 180f ) );
transform.scale( 0.5f, 0.5f, 0.5f ); transform.scale( 0.5f, 0.5f, 0.5f );
float scale = 0.75f / Math.max( width + BORDER * 2, height + BORDER * 2 + LIGHT_HEIGHT ); float scale = 0.75f / Math.max( width + BORDER * 2, height + BORDER * 2 + LIGHT_HEIGHT );
@ -114,7 +115,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer(); BufferBuilder buffer = tessellator.getBuffer();
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_COLOR_TEXTURE ); buffer.begin( VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE );
ComputerBorderRenderer.render( transform, buffer, 0, 0, 0, width, height, true, r, g, b ); ComputerBorderRenderer.render( transform, buffer, 0, 0, 0, width, height, true, r, g, b );
@ -131,7 +132,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer(); BufferBuilder buffer = tessellator.getBuffer();
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_COLOR ); buffer.begin( VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR );
buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ) buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 )
.color( r, g, b, 1.0f ) .color( r, g, b, 1.0f )
.next(); .next();

View File

@ -9,7 +9,7 @@ package dan200.computercraft.client.render;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.Vec3f;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
@ -33,7 +33,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
@Override @Override
protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack ) protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack )
{ {
transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( 180f ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( 180f ) );
transform.scale( 0.42f, 0.42f, -0.42f ); transform.scale( 0.42f, 0.42f, -0.42f );
transform.translate( -0.5f, -0.48f, 0.0f ); transform.translate( -0.5f, -0.48f, 0.0f );
@ -85,7 +85,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
// Move a little bit forward to ensure we're not clipping with the frame // Move a little bit forward to ensure we're not clipping with the frame
matrixStack.translate( 0.0f, 0.0f, -0.001f ); matrixStack.translate( 0.0f, 0.0f, -0.001f );
matrixStack.multiply( Vector3f.POSITIVE_Z.getDegreesQuaternion( 180f ) ); matrixStack.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( 180f ) );
matrixStack.scale( 0.95f, 0.95f, -0.95f ); matrixStack.scale( 0.95f, 0.95f, -0.95f );
matrixStack.translate( -0.5f, -0.5f, 0.0f ); matrixStack.translate( -0.5f, -0.5f, 0.0f );

View File

@ -12,7 +12,7 @@ import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormatElement; import net.minecraft.client.render.VertexFormatElement;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.util.math.Vector4f; import net.minecraft.util.math.Vector4f;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
import java.util.List; import java.util.List;
@ -66,7 +66,7 @@ public final class ModelTransformer
for( VertexFormatElement element : format.getElements() ) // For each vertex element for( VertexFormatElement element : format.getElements() ) // For each vertex element
{ {
int start = offsetBytes / Integer.BYTES; int start = offsetBytes / Integer.BYTES;
if( element.getType() == VertexFormatElement.Type.POSITION && element.getFormat() == VertexFormatElement.Format.FLOAT ) // When we find a position element if( element.getType() == VertexFormatElement.Type.POSITION && element.getDataType() == VertexFormatElement.DataType.FLOAT ) // When we find a position element
{ {
Vector4f pos = new Vector4f( Float.intBitsToFloat( vertexData[start] ), Vector4f pos = new Vector4f( Float.intBitsToFloat( vertexData[start] ),
Float.intBitsToFloat( vertexData[start + 1] ), Float.intBitsToFloat( vertexData[start + 1] ),
@ -81,7 +81,7 @@ public final class ModelTransformer
vertexData[start + 1] = Float.floatToRawIntBits( pos.getY() ); vertexData[start + 1] = Float.floatToRawIntBits( pos.getY() );
vertexData[start + 2] = Float.floatToRawIntBits( pos.getZ() ); vertexData[start + 2] = Float.floatToRawIntBits( pos.getZ() );
} }
offsetBytes += element.getSize(); offsetBytes += element.getLength();
} }
} }
return copy; return copy;

View File

@ -7,11 +7,11 @@ package dan200.computercraft.client.render;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.texture.TextureUtil;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL13;
@ -19,6 +19,7 @@ import org.lwjgl.opengl.GL20;
import java.io.InputStream; import java.io.InputStream;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.util.List;
class MonitorTextureBufferShader class MonitorTextureBufferShader
{ {
@ -42,7 +43,7 @@ class MonitorTextureBufferShader
static void setupUniform( Matrix4f transform, int width, int height, Palette palette, boolean greyscale ) static void setupUniform( Matrix4f transform, int width, int height, Palette palette, boolean greyscale )
{ {
MATRIX_BUFFER.rewind(); MATRIX_BUFFER.rewind();
transform.writeToBuffer( MATRIX_BUFFER ); transform.write( MATRIX_BUFFER, true ); //FIXME: Row major or Column major? guessing row major, since that is like C.
MATRIX_BUFFER.rewind(); MATRIX_BUFFER.rewind();
RenderSystem.glUniformMatrix4( uniformMv, false, MATRIX_BUFFER ); RenderSystem.glUniformMatrix4( uniformMv, false, MATRIX_BUFFER );
@ -77,7 +78,7 @@ class MonitorTextureBufferShader
{ {
if( ok ) if( ok )
{ {
GlStateManager.useProgram( program ); GlStateManager.glLinkProgram( program );
} }
return ok; return ok;
} }
@ -101,14 +102,15 @@ class MonitorTextureBufferShader
int vertexShader = loadShader( GL20.GL_VERTEX_SHADER, "assets/computercraft/shaders/monitor.vert" ); int vertexShader = loadShader( GL20.GL_VERTEX_SHADER, "assets/computercraft/shaders/monitor.vert" );
int fragmentShader = loadShader( GL20.GL_FRAGMENT_SHADER, "assets/computercraft/shaders/monitor.frag" ); int fragmentShader = loadShader( GL20.GL_FRAGMENT_SHADER, "assets/computercraft/shaders/monitor.frag" );
program = GlStateManager.createProgram(); program = GlStateManager.glCreateProgram();
GlStateManager.attachShader( program, vertexShader ); GlStateManager.glAttachShader( program, vertexShader );
GlStateManager.attachShader( program, fragmentShader ); GlStateManager.glAttachShader( program, fragmentShader );
GL20.glBindAttribLocation( program, 0, "v_pos" ); GL20.glBindAttribLocation( program, 0, "v_pos" );
GlStateManager.linkProgram( program ); GlStateManager.glLinkProgram( program );
boolean ok = GlStateManager.getProgram( program, GL20.GL_LINK_STATUS ) != 0;
String log = GlStateManager.getProgramInfoLog( program, Short.MAX_VALUE ) boolean ok = GlStateManager.glGetProgrami( program, GL20.GL_LINK_STATUS ) != 0;
String log = GlStateManager.glGetProgramInfoLog( program, Short.MAX_VALUE )
.trim(); .trim();
if( !Strings.isNullOrEmpty( log ) ) if( !Strings.isNullOrEmpty( log ) )
{ {
@ -117,8 +119,8 @@ class MonitorTextureBufferShader
GL20.glDetachShader( program, vertexShader ); GL20.glDetachShader( program, vertexShader );
GL20.glDetachShader( program, fragmentShader ); GL20.glDetachShader( program, fragmentShader );
GlStateManager.deleteShader( vertexShader ); GlStateManager.glDeleteShader( vertexShader );
GlStateManager.deleteShader( fragmentShader ); GlStateManager.glDeleteShader( fragmentShader );
if( !ok ) if( !ok )
{ {
@ -150,15 +152,15 @@ class MonitorTextureBufferShader
{ {
throw new IllegalArgumentException( "Cannot find " + path ); throw new IllegalArgumentException( "Cannot find " + path );
} }
String contents = TextureUtil.readAllToString( stream ); List<String> contents = TextureUtil.readResourceAsString(stream).lines().toList();
int shader = GlStateManager.createShader( kind ); int shader = GlStateManager.glCreateShader( kind );
GlStateManager.shaderSource( shader, contents ); GlStateManager.glShaderSource( shader, contents );
GlStateManager.compileShader( shader ); GlStateManager.glCompileShader( shader );
boolean ok = GlStateManager.getShader( shader, GL20.GL_COMPILE_STATUS ) != 0; boolean ok = GlStateManager.glGetShaderi( shader, GL20.GL_COMPILE_STATUS ) != 0;
String log = GlStateManager.getShaderInfoLog( shader, Short.MAX_VALUE ) String log = GlStateManager.glGetShaderInfoLog( shader, Short.MAX_VALUE )
.trim(); .trim();
if( !Strings.isNullOrEmpty( log ) ) if( !Strings.isNullOrEmpty( log ) )
{ {
@ -174,7 +176,7 @@ class MonitorTextureBufferShader
private static int getUniformLocation( int program, String name ) private static int getUniformLocation( int program, String name )
{ {
int uniform = GlStateManager.getUniformLocation( program, name ); int uniform = GlStateManager._glGetUniformLocation( program, name );
if( uniform == -1 ) if( uniform == -1 )
{ {
throw new IllegalStateException( "Cannot find uniform " + name ); throw new IllegalStateException( "Cannot find uniform " + name );

View File

@ -10,6 +10,7 @@ import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.render.*; import net.minecraft.client.render.*;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -18,7 +19,7 @@ import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT
import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE; import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE;
public final class PrintoutRenderer public final class PrintoutRenderer
{ { //FIXME Use BufferBuilders
/** /**
* Width of a page. * Width of a page.
*/ */
@ -186,24 +187,22 @@ public final class PrintoutRenderer
.next(); .next();
} }
private static final class Type extends RenderPhase private static final class Type extends RenderLayer
{ {
static final RenderLayer TYPE = RenderLayer.of( "printout_background", static final RenderLayer TYPE = RenderLayer.of( "printout_background",
VertexFormats.POSITION_TEXTURE, VertexFormats.POSITION_TEXTURE,
GL11.GL_QUADS, VertexFormat.DrawMode.QUADS,
1024, 1024,
false,
false,
// useDelegate, needsSorting // useDelegate, needsSorting
RenderLayer.MultiPhaseParameters.builder() RenderLayer.MultiPhaseParameters.builder()
.texture( new RenderPhase.Texture( BG, false, false ) ) // blur, minimap .texture( new RenderPhase.Texture( BG, false, false ) ) // blur, minimap
.alpha( ONE_TENTH_ALPHA ) .transparency( TRANSLUCENT_TRANSPARENCY )
.lightmap( DISABLE_LIGHTMAP ) .lightmap( DISABLE_LIGHTMAP )
.build( false ) ); .build( false ));
private Type( String name, Runnable setup, Runnable destroy ) private Type( String name, VertexFormat vertexFormat, VertexFormat.DrawMode drawMode, int expectedBufferSize, boolean hasCrumbling, boolean translucent, RenderLayer.MultiPhaseParameters phases, Runnable setup, Runnable destroy )
{ {
super( name, setup, destroy ); super( name, vertexFormat, drawMode, expectedBufferSize, hasCrumbling, hasCrumbling, setup, destroy );
} }
} }
} }

View File

@ -21,9 +21,9 @@ import net.minecraft.client.render.*;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer; import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.util.GlAllocationUtils; import net.minecraft.client.util.GlAllocationUtils;
import net.minecraft.client.util.math.AffineTransformation; import net.minecraft.util.math.AffineTransformation;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Matrix4f;
@ -37,8 +37,8 @@ import java.nio.ByteBuffer;
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*; import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
public class TileEntityMonitorRenderer extends BlockEntityRenderer<TileMonitor> public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonitor>
{ { //FIXME get rid of GL Calls. Buffered things or whatever, more research needed.
/** /**
* {@link TileMonitor#RENDER_MARGIN}, but a tiny bit of additional padding to ensure that there is no space between the monitor frame and contents. * {@link TileMonitor#RENDER_MARGIN}, but a tiny bit of additional padding to ensure that there is no space between the monitor frame and contents.
*/ */
@ -89,8 +89,8 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer<TileMonitor>
originPos.getY() - monitorPos.getY() + 0.5, originPos.getY() - monitorPos.getY() + 0.5,
originPos.getZ() - monitorPos.getZ() + 0.5 ); originPos.getZ() - monitorPos.getZ() + 0.5 );
transform.multiply( Vector3f.NEGATIVE_Y.getDegreesQuaternion( yaw ) ); transform.multiply( Vec3f.NEGATIVE_Y.getDegreesQuaternion( yaw ) );
transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( pitch ) ); transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( pitch ) );
transform.translate( -0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN, transform.translate( -0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0, origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0,
0.50 ); 0.50 );

View File

@ -26,7 +26,7 @@ import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.util.ModelIdentifier; import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.Vec3f;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult; import net.minecraft.util.hit.HitResult;
@ -38,8 +38,8 @@ import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class TileEntityTurtleRenderer extends BlockEntityRenderer<TileTurtle> public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
{ { //FIXME: more rendering puzzles.
private static final ModelIdentifier NORMAL_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_normal", "inventory" ); private static final ModelIdentifier NORMAL_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_normal", "inventory" );
private static final ModelIdentifier ADVANCED_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_advanced", "inventory" ); private static final ModelIdentifier ADVANCED_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_advanced", "inventory" );
private static final ModelIdentifier COLOUR_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_colour", "inventory" ); private static final ModelIdentifier COLOUR_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_colour", "inventory" );
@ -147,7 +147,7 @@ public class TileEntityTurtleRenderer extends BlockEntityRenderer<TileTurtle>
transform.translate( offset.x, offset.y, offset.z ); transform.translate( offset.x, offset.y, offset.z );
transform.translate( 0.5f, 0.5f, 0.5f ); transform.translate( 0.5f, 0.5f, 0.5f );
transform.multiply( Vector3f.POSITIVE_Y.getDegreesQuaternion( 180.0f - yaw ) ); transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( 180.0f - yaw ) );
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) ) if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
{ {
// Flip the model // Flip the model
@ -189,7 +189,7 @@ public class TileEntityTurtleRenderer extends BlockEntityRenderer<TileTurtle>
float toolAngle = turtle.getToolRenderAngle( side, f ); float toolAngle = turtle.getToolRenderAngle( side, f );
transform.translate( 0.0f, 0.5f, 0.5f ); transform.translate( 0.0f, 0.5f, 0.5f );
transform.multiply( Vector3f.NEGATIVE_X.getDegreesQuaternion( toolAngle ) ); transform.multiply( Vec3f.NEGATIVE_X.getDegreesQuaternion( toolAngle ) );
transform.translate( 0.0f, -0.5f, -0.5f ); transform.translate( 0.0f, -0.5f, -0.5f );
TransformedModel model = upgrade.getModel( turtle.getAccess(), side ); TransformedModel model = upgrade.getModel( turtle.getAccess(), side );

View File

@ -15,7 +15,7 @@ import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.json.ModelOverrideList; import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation; import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.math.AffineTransformation; import net.minecraft.util.math.AffineTransformation;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;

View File

@ -10,19 +10,20 @@ import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory.Context;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class TurtlePlayerRenderer extends EntityRenderer<TurtlePlayer> public class TurtlePlayerRenderer extends EntityRenderer<TurtlePlayer>
{ { //FIXME Make sure this isn't an issue. Context was EntityRenderDispatcher.
public TurtlePlayerRenderer( EntityRenderDispatcher renderManager ) public TurtlePlayerRenderer( Context renderManager )
{ {
super( renderManager ); super( renderManager );
} }
public TurtlePlayerRenderer( EntityRenderDispatcher entityRenderDispatcher, EntityRendererRegistry.Context context ) public TurtlePlayerRenderer( Context entityRenderDispatcher, EntityRendererRegistry.Context context )
{ {
super( entityRenderDispatcher ); super( entityRenderDispatcher );
} }

View File

@ -24,7 +24,7 @@ import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation; import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite; import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.ModelIdentifier; import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.client.util.math.AffineTransformation; import net.minecraft.util.math.AffineTransformation;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
@ -70,8 +70,7 @@ public class TurtleSmartItemModel implements BakedModel
{ {
@Nonnull @Nonnull
@Override @Override
public BakedModel apply( @Nonnull BakedModel originalModel, @Nonnull ItemStack stack, @Nullable ClientWorld world, public BakedModel apply( BakedModel originalModel, ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity, int seed)
@Nullable LivingEntity entity )
{ {
ItemTurtle turtle = (ItemTurtle) stack.getItem(); ItemTurtle turtle = (ItemTurtle) stack.getItem();
int colour = turtle.getColour( stack ); int colour = turtle.getColour( stack );

View File

@ -16,7 +16,8 @@ import dan200.computercraft.shared.util.IoUtil;
import net.minecraft.resource.ReloadableResourceManager; import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.resource.Resource; import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloadListener; import net.minecraft.resource.ResourceReloader;
import net.minecraft.resource.ResourceReloader.Synchronizer;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException; import net.minecraft.util.InvalidIdentifierException;
import net.minecraft.util.profiler.Profiler; import net.minecraft.util.profiler.Profiler;
@ -299,7 +300,7 @@ public final class ResourceMount implements IMount
* While people should really be keeping a permanent reference to this, some people construct it every * While people should really be keeping a permanent reference to this, some people construct it every
* method call, so let's make this as small as possible. * method call, so let's make this as small as possible.
*/ */
static class Listener implements ResourceReloadListener static class Listener implements ResourceReloader
{ {
private static final Listener INSTANCE = new Listener(); private static final Listener INSTANCE = new Listener();
@ -324,7 +325,7 @@ public final class ResourceMount implements IMount
synchronized void add( ReloadableResourceManager manager, ResourceMount mount ) synchronized void add( ReloadableResourceManager manager, ResourceMount mount )
{ {
if( managers.add( manager ) ) manager.registerListener( this ); if( managers.add( manager ) ) manager.registerReloader( this );
mounts.add( mount ); mounts.add( mount );
} }
} }

View File

@ -7,7 +7,7 @@ package dan200.computercraft.core.terminal;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -366,7 +366,7 @@ public class Terminal
setChanged(); setChanged();
} }
public synchronized CompoundTag writeToNBT( CompoundTag nbt ) public synchronized NbtCompound writeToNBT( NbtCompound nbt )
{ {
nbt.putInt( "term_cursorX", cursorX ); nbt.putInt( "term_cursorX", cursorX );
nbt.putInt( "term_cursorY", cursorY ); nbt.putInt( "term_cursorY", cursorY );
@ -384,7 +384,7 @@ public class Terminal
return nbt; return nbt;
} }
public synchronized void readFromNBT( CompoundTag nbt ) public synchronized void readFromNBT( NbtCompound nbt )
{ {
cursorX = nbt.getInt( "term_cursorX" ); cursorX = nbt.getInt( "term_cursorX" );
cursorY = nbt.getInt( "term_cursorY" ); cursorY = nbt.getInt( "term_cursorY" );

View File

@ -5,8 +5,8 @@
*/ */
package dan200.computercraft.fabric.mixin; package dan200.computercraft.fabric.mixin;
import net.minecraft.client.util.math.AffineTransformation; import net.minecraft.util.math.AffineTransformation;
import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.Quaternion; import net.minecraft.util.math.Quaternion;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
@ -15,10 +15,10 @@ import org.spongepowered.asm.mixin.gen.Accessor;
public interface AffineTransformationAccess public interface AffineTransformationAccess
{ {
@Accessor @Accessor
Vector3f getTranslation(); Vec3f getTranslation();
@Accessor @Accessor
Vector3f getScale(); Vec3f getScale();
@Accessor @Accessor
Quaternion getRotation1(); Quaternion getRotation1();

View File

@ -32,7 +32,7 @@ public class MixinWorld
@Inject( method = "setBlockEntity", at = @At( "HEAD" ) ) @Inject( method = "setBlockEntity", at = @At( "HEAD" ) )
public void setBlockEntity( BlockPos pos, @Nullable BlockEntity entity, CallbackInfo info ) public void setBlockEntity( BlockPos pos, @Nullable BlockEntity entity, CallbackInfo info )
{ {
if( !World.isOutOfBuildLimitVertically( pos ) && entity != null && !entity.isRemoved() && iteratingTickingBlockEntities ) if( entity != null && !entity.isRemoved() && entity.getWorld().isInBuildLimit(pos) && iteratingTickingBlockEntities )
{ {
setWorld( entity, this ); setWorld( entity, this );
} }
@ -42,7 +42,7 @@ public class MixinWorld
{ {
if( entity.getWorld() != world && entity instanceof TileGeneric ) if( entity.getWorld() != world && entity instanceof TileGeneric )
{ {
entity.setLocation( (World) world, entity.getPos() ); // entity.setLocation( (World) world, entity.getPos() ); //TODO why?
} }
} }

View File

@ -32,7 +32,7 @@ public final class BundledRedstone
public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
{ {
return World.isInBuildLimit( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1; return !world.isInBuildLimit( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1;
} }
public static int getOutput( World world, BlockPos pos, Direction side ) public static int getOutput( World world, BlockPos pos, Direction side )
@ -43,7 +43,7 @@ public final class BundledRedstone
private static int getUnmaskedOutput( World world, BlockPos pos, Direction side ) private static int getUnmaskedOutput( World world, BlockPos pos, Direction side )
{ {
if( !World.isInBuildLimit( pos ) ) if( !world.isInBuildLimit( pos ) )
{ {
return -1; return -1;
} }

View File

@ -43,6 +43,7 @@ import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import dan200.computercraft.shared.turtle.items.ItemTurtle; import dan200.computercraft.shared.turtle.items.ItemTurtle;
import dan200.computercraft.shared.turtle.upgrades.*; import dan200.computercraft.shared.turtle.upgrades.*;
import dan200.computercraft.shared.util.FixedPointTileEntityType; import dan200.computercraft.shared.util.FixedPointTileEntityType;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.minecraft.block.AbstractBlock; import net.minecraft.block.AbstractBlock;
@ -151,19 +152,19 @@ public final class ComputerCraftRegistry
public static final BlockEntityType<TileMonitor> MONITOR_NORMAL = ofBlock( () -> ModBlocks.MONITOR_NORMAL, public static final BlockEntityType<TileMonitor> MONITOR_NORMAL = ofBlock( () -> ModBlocks.MONITOR_NORMAL,
"monitor_normal", "monitor_normal",
f -> new TileMonitor( f, false ) ); f -> new TileMonitor( f, false, null, null ) );
public static final BlockEntityType<TileMonitor> MONITOR_ADVANCED = ofBlock( () -> ModBlocks.MONITOR_ADVANCED, public static final BlockEntityType<TileMonitor> MONITOR_ADVANCED = ofBlock( () -> ModBlocks.MONITOR_ADVANCED,
"monitor_advanced", "monitor_advanced",
f -> new TileMonitor( f, true ) ); f -> new TileMonitor( f, true, null, null ) );
public static final BlockEntityType<TileComputer> COMPUTER_NORMAL = ofBlock( () -> ModBlocks.COMPUTER_NORMAL, public static final BlockEntityType<TileComputer> COMPUTER_NORMAL = ofBlock( () -> ModBlocks.COMPUTER_NORMAL,
"computer_normal", "computer_normal",
f -> new TileComputer( ComputerFamily.NORMAL, f ) ); f -> new TileComputer( ComputerFamily.NORMAL, f, null, null ) );
public static final BlockEntityType<TileComputer> COMPUTER_ADVANCED = ofBlock( () -> ModBlocks.COMPUTER_ADVANCED, public static final BlockEntityType<TileComputer> COMPUTER_ADVANCED = ofBlock( () -> ModBlocks.COMPUTER_ADVANCED,
"computer_advanced", "computer_advanced",
f -> new TileComputer( ComputerFamily.ADVANCED, f ) ); f -> new TileComputer( ComputerFamily.ADVANCED, f, null, null ) );
public static final BlockEntityType<TileCommandComputer> COMPUTER_COMMAND = ofBlock( () -> ModBlocks.COMPUTER_COMMAND, public static final BlockEntityType<TileCommandComputer> COMPUTER_COMMAND = ofBlock( () -> ModBlocks.COMPUTER_COMMAND,
"computer_command", "computer_command",
f -> new TileCommandComputer( ComputerFamily.COMMAND, f ) ); f -> new TileCommandComputer( ComputerFamily.COMMAND, f, null, null ) );
public static final BlockEntityType<TileTurtle> TURTLE_NORMAL = ofBlock( () -> ModBlocks.TURTLE_NORMAL, public static final BlockEntityType<TileTurtle> TURTLE_NORMAL = ofBlock( () -> ModBlocks.TURTLE_NORMAL,
"turtle_normal", "turtle_normal",
f -> new TileTurtle( f, ComputerFamily.NORMAL ) ); f -> new TileTurtle( f, ComputerFamily.NORMAL ) );
@ -179,16 +180,17 @@ public final class ComputerCraftRegistry
public static final BlockEntityType<TileCable> CABLE = ofBlock( () -> ModBlocks.CABLE, "cable", TileCable::new ); public static final BlockEntityType<TileCable> CABLE = ofBlock( () -> ModBlocks.CABLE, "cable", TileCable::new );
public static final BlockEntityType<TileWirelessModem> WIRELESS_MODEM_NORMAL = ofBlock( () -> ModBlocks.WIRELESS_MODEM_NORMAL, public static final BlockEntityType<TileWirelessModem> WIRELESS_MODEM_NORMAL = ofBlock( () -> ModBlocks.WIRELESS_MODEM_NORMAL,
"wireless_modem_normal", "wireless_modem_normal",
f -> new TileWirelessModem( f, false ) ); f -> new TileWirelessModem( f, false, null, null ) );
public static final BlockEntityType<TileWirelessModem> WIRELESS_MODEM_ADVANCED = ofBlock( () -> ModBlocks.WIRELESS_MODEM_ADVANCED, public static final BlockEntityType<TileWirelessModem> WIRELESS_MODEM_ADVANCED = ofBlock( () -> ModBlocks.WIRELESS_MODEM_ADVANCED,
"wireless_modem_advanced", "wireless_modem_advanced",
f -> new TileWirelessModem( f, true ) ); f -> new TileWirelessModem( f, true ) );
private static <T extends BlockEntity> BlockEntityType<T> ofBlock( Supplier<Block> block, String id, Function<BlockEntityType<T>, T> factory ) private static <T extends BlockEntity> BlockEntityType<T> ofBlock( Supplier<Block> block, String id, Function<BlockEntityType<T>, T> factory )
{ {
FabricBlockEntityTypeBuilder.create(factory, block);
return Registry.register( BLOCK_ENTITY_TYPE, return Registry.register( BLOCK_ENTITY_TYPE,
new Identifier( MOD_ID, id ), new Identifier( MOD_ID, id ),
FixedPointTileEntityType.create( Objects.requireNonNull( block ), factory ) ); FabricBlockEntityTypeBuilder.create);
} }
} }

View File

@ -35,7 +35,7 @@ public final class Peripherals
@Nullable @Nullable
public static IPeripheral getPeripheral( World world, BlockPos pos, Direction side ) public static IPeripheral getPeripheral( World world, BlockPos pos, Direction side )
{ {
return World.isInBuildLimit( pos ) && !world.isClient ? getPeripheralAt( world, pos, side ) : null; return world.isInBuildLimit( pos ) && !world.isClient ? getPeripheralAt( world, pos, side ) : null;
} }
@Nullable @Nullable

View File

@ -182,7 +182,7 @@ public final class CommandComputerCraft
ServerPlayerEntity player = (ServerPlayerEntity) entity; ServerPlayerEntity player = (ServerPlayerEntity) entity;
if( player.getEntityWorld() == world ) if( player.getEntityWorld() == world )
{ {
player.networkHandler.teleportRequest( player.networkHandler.requestTeleport(
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0,
EnumSet.noneOf( PlayerPositionLookS2CPacket.Flag.class ) EnumSet.noneOf( PlayerPositionLookS2CPacket.Flag.class )
); );

View File

@ -94,8 +94,8 @@ public abstract class BlockGeneric extends BlockWithEntity
@Nullable @Nullable
@Override @Override
public BlockEntity createBlockEntity( @Nonnull BlockView world ) public BlockEntity createBlockEntity(BlockPos pos, BlockState state)
{ {
return type.instantiate(); return type.instantiate(pos, state);
} }
} }

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState; import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
public class ClientTerminal implements ITerminal public class ClientTerminal implements ITerminal
{ {
@ -80,12 +80,12 @@ public class ClientTerminal implements ITerminal
} }
} }
public void readDescription( CompoundTag nbt ) public void readDescription( NbtCompound nbt )
{ {
colour = nbt.getBoolean( "colour" ); colour = nbt.getBoolean( "colour" );
if( nbt.contains( "terminal" ) ) if( nbt.contains( "terminal" ) )
{ {
CompoundTag terminal = nbt.getCompound( "terminal" ); NbtCompound terminal = nbt.getCompound( "terminal" );
resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) ); resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
this.terminal.readFromNBT( terminal ); this.terminal.readFromNBT( terminal );
} }

View File

@ -7,7 +7,7 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
public interface IColouredItem public interface IColouredItem
{ {
@ -20,7 +20,7 @@ public interface IColouredItem
static int getColourBasic( ItemStack stack ) static int getColourBasic( ItemStack stack )
{ {
CompoundTag tag = stack.getTag(); NbtCompound tag = stack.getTag();
return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1; return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1;
} }
@ -35,7 +35,7 @@ public interface IColouredItem
{ {
if( colour == -1 ) if( colour == -1 )
{ {
CompoundTag tag = stack.getTag(); NbtCompound tag = stack.getTag();
if( tag != null ) if( tag != null )
{ {
tag.remove( NBT_COLOUR ); tag.remove( NBT_COLOUR );

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState; import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -85,12 +85,12 @@ public class ServerTerminal implements ITerminal
return new TerminalState( colour, terminal ); return new TerminalState( colour, terminal );
} }
public void writeDescription( CompoundTag nbt ) public void writeDescription( NbtCompound nbt )
{ {
nbt.putBoolean( "colour", colour ); nbt.putBoolean( "colour", colour );
if( terminal != null ) if( terminal != null )
{ {
CompoundTag terminal = new CompoundTag(); NbtCompound terminal = new NbtCompound();
terminal.putInt( "term_width", this.terminal.getWidth() ); terminal.putInt( "term_width", this.terminal.getWidth() );
terminal.putInt( "term_height", this.terminal.getHeight() ); terminal.putInt( "term_height", this.terminal.getHeight() );
this.terminal.writeToNBT( terminal ); this.terminal.writeToNBT( terminal );

View File

@ -11,7 +11,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
@ -21,9 +21,9 @@ import javax.annotation.Nonnull;
public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable
{ {
public TileGeneric( BlockEntityType<? extends TileGeneric> type ) public TileGeneric( BlockEntityType<? extends TileGeneric> type, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
} }
public void destroy() public void destroy()
@ -82,23 +82,23 @@ public abstract class TileGeneric extends BlockEntity implements BlockEntityClie
} }
@Override @Override
public void fromClientTag( CompoundTag compoundTag ) public void fromClientTag( NbtCompound compoundTag )
{ {
readDescription( compoundTag ); readDescription( compoundTag );
} }
protected void readDescription( @Nonnull CompoundTag nbt ) protected void readDescription( @Nonnull NbtCompound nbt )
{ {
} }
@Override @Override
public CompoundTag toClientTag( CompoundTag compoundTag ) public NbtCompound toClientTag( NbtCompound compoundTag )
{ {
writeDescription( compoundTag ); writeDescription( compoundTag );
return compoundTag; return compoundTag;
} }
protected void writeDescription( @Nonnull CompoundTag nbt ) protected void writeDescription( @Nonnull NbtCompound nbt )
{ {
} }
} }

View File

@ -16,7 +16,7 @@ import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
@ -204,7 +204,7 @@ public class CommandAPI implements ILuaAPI
World world = computer.getWorld(); World world = computer.getWorld();
BlockPos min = new BlockPos( Math.min( minX, maxX ), Math.min( minY, maxY ), Math.min( minZ, maxZ ) ); BlockPos min = new BlockPos( Math.min( minX, maxX ), Math.min( minY, maxY ), Math.min( minZ, maxZ ) );
BlockPos max = new BlockPos( Math.max( minX, maxX ), Math.max( minY, maxY ), Math.max( minZ, maxZ ) ); BlockPos max = new BlockPos( Math.max( minX, maxX ), Math.max( minY, maxY ), Math.max( minZ, maxZ ) );
if( !World.isInBuildLimit( min ) || !World.isInBuildLimit( max ) ) if( !world.isInBuildLimit( min ) || !world.isInBuildLimit( max ) )
{ {
throw new LuaException( "Co-ordinates out of range" ); throw new LuaException( "Co-ordinates out of range" );
} }
@ -252,7 +252,7 @@ public class CommandAPI implements ILuaAPI
BlockEntity tile = world.getBlockEntity( pos ); BlockEntity tile = world.getBlockEntity( pos );
if( tile != null ) if( tile != null )
{ {
table.put( "nbt", NBTUtil.toLua( tile.toTag( new CompoundTag() ) ) ); table.put( "nbt", NBTUtil.toLua( tile.writeNbt( new NbtCompound() ) ) );
} }
return table; return table;
@ -289,7 +289,7 @@ public class CommandAPI implements ILuaAPI
// Get the details of the block // Get the details of the block
World world = computer.getWorld(); World world = computer.getWorld();
BlockPos position = new BlockPos( x, y, z ); BlockPos position = new BlockPos( x, y, z );
if( World.isInBuildLimit( position ) ) if( world.isInBuildLimit( position ) )
{ {
return getBlockInfo( world, position ); return getBlockInfo( world, position );
} }

View File

@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.apis.CommandAPI; import dan200.computercraft.shared.computer.apis.CommandAPI;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@ -19,6 +20,7 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec2f; import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameRules; import net.minecraft.world.GameRules;
@ -32,9 +34,9 @@ public class TileCommandComputer extends TileComputer
{ {
private final CommandReceiver receiver; private final CommandReceiver receiver;
public TileCommandComputer( ComputerFamily family, BlockEntityType<? extends TileCommandComputer> type ) public TileCommandComputer( ComputerFamily family, BlockEntityType<? extends TileCommandComputer> type, BlockPos pos, BlockState state )
{ {
super( family, type ); super( family, type, pos, state );
receiver = new CommandReceiver(); receiver = new CommandReceiver();
} }

View File

@ -17,6 +17,7 @@ import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -26,9 +27,9 @@ public class TileComputer extends TileComputerBase
{ {
private ComputerProxy proxy; private ComputerProxy proxy;
public TileComputer( ComputerFamily family, BlockEntityType<? extends TileComputer> type ) public TileComputer( ComputerFamily family, BlockEntityType<? extends TileComputer> type, BlockPos pos, BlockState state )
{ {
super( type, family ); super( type, family, pos, state );
} }
public boolean isUsableByPlayer( PlayerEntity player ) public boolean isUsableByPlayer( PlayerEntity player )

View File

@ -17,6 +17,7 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.network.container.ComputerContainerData; import dan200.computercraft.shared.network.container.ComputerContainerData;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.RedstoneUtil; import dan200.computercraft.shared.util.RedstoneUtil;
import joptsimple.internal.Strings; import joptsimple.internal.Strings;
@ -28,7 +29,7 @@ import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
@ -37,7 +38,6 @@ import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Nameable; import net.minecraft.util.Nameable;
import net.minecraft.util.Tickable;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -47,7 +47,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Objects; import java.util.Objects;
public abstract class TileComputerBase extends TileGeneric implements IComputerTile, Tickable, IPeripheralTile, Nameable, public abstract class TileComputerBase extends TileGeneric implements IComputerTile, IPeripheralTile, Nameable,
ExtendedScreenHandlerFactory ExtendedScreenHandlerFactory
{ {
private static final String NBT_ID = "ComputerId"; private static final String NBT_ID = "ComputerId";
@ -61,9 +61,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
private boolean on = false; private boolean on = false;
private boolean fresh = false; private boolean fresh = false;
public TileComputerBase( BlockEntityType<? extends TileGeneric> type, ComputerFamily family ) public TileComputerBase( BlockEntityType<? extends TileGeneric> type, ComputerFamily family, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
this.family = family; this.family = family;
} }
@ -250,7 +250,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
@Override @Override
protected void readDescription( @Nonnull CompoundTag nbt ) protected void readDescription( @Nonnull NbtCompound nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null; label = nbt.contains( NBT_LABEL ) ? nbt.getString( NBT_LABEL ) : null;
@ -258,7 +258,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
@Override @Override
protected void writeDescription( @Nonnull CompoundTag nbt ) protected void writeDescription( @Nonnull NbtCompound nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
if( label != null ) if( label != null )
@ -271,43 +271,42 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
} }
@Override public static void tick( World world, BlockPos pos, BlockState state, TileComputerBase tileComputerBase )
public void tick()
{ {
if( !getWorld().isClient ) if( !world.isClient )
{ {
ServerComputer computer = createServerComputer(); ServerComputer computer = tileComputerBase.createServerComputer();
if( computer == null ) if( computer == null )
{ {
return; return;
} }
// If the computer isn't on and should be, then turn it on // If the computer isn't on and should be, then turn it on
if( startOn || (fresh && on) ) if( tileComputerBase.startOn || (tileComputerBase.fresh && tileComputerBase.on) )
{ {
computer.turnOn(); computer.turnOn();
startOn = false; tileComputerBase.startOn = false;
} }
computer.keepAlive(); computer.keepAlive();
fresh = false; tileComputerBase.fresh = false;
computerID = computer.getID(); tileComputerBase.computerID = computer.getID();
label = computer.getLabel(); tileComputerBase.label = computer.getLabel();
on = computer.isOn(); tileComputerBase.on = computer.isOn();
if( computer.hasOutputChanged() ) if( computer.hasOutputChanged() )
{ {
updateOutput(); tileComputerBase.updateOutput();
} }
// Update the block state if needed. We don't fire a block update intentionally, // Update the block state if needed. We don't fire a block update intentionally,
// as this only really is needed on the client side. // as this only really is needed on the client side.
updateBlockState( computer.getState() ); tileComputerBase.updateBlockState( computer.getState() );
if( computer.hasOutputChanged() ) if( computer.hasOutputChanged() )
{ {
updateOutput(); tileComputerBase.updateOutput();
} }
} }
} }
@ -325,9 +324,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
protected abstract void updateBlockState( ComputerState newState ); protected abstract void updateBlockState( ComputerState newState );
@Override @Override
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void readNbt( @Nonnull NbtCompound nbt )
{ {
super.fromTag( state, nbt ); super.readNbt( nbt );
// Load ID, label and power state // Load ID, label and power state
computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
@ -337,8 +336,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( @Nonnull CompoundTag nbt ) public NbtCompound writeNbt( @Nonnull NbtCompound nbt )
{ {
super.writeNbt( nbt );
// Save ID, label and power state // Save ID, label and power state
if( computerID >= 0 ) if( computerID >= 0 )
{ {
@ -349,8 +349,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
nbt.putString( NBT_LABEL, label ); nbt.putString( NBT_LABEL, label );
} }
nbt.putBoolean( NBT_ON, on ); nbt.putBoolean( NBT_ON, on );
return nbt;
return super.toTag( nbt );
} }
@Override @Override
@ -362,7 +361,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
private void updateInput( BlockPos neighbour ) private void updateInput( BlockPos neighbour )
{ {
if( getWorld() == null || getWorld().isClient ) if( getWorld() == null || this.world.isClient )
{ {
return; return;
} }
@ -384,12 +383,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
// If the position is not any adjacent one, update all inputs. // If the position is not any adjacent one, update all inputs.
updateInput(); this.updateInput();
} }
private void updateInput( Direction dir ) private void updateInput( Direction dir )
{ {
if( getWorld() == null || getWorld().isClient ) if( getWorld() == null || this.world.isClient )
{ {
return; return;
} }
@ -412,7 +411,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override @Override
public final void setComputerID( int id ) public final void setComputerID( int id )
{ {
if( getWorld().isClient || computerID == id ) if( this.world.isClient || computerID == id )
{ {
return; return;
} }
@ -437,7 +436,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override @Override
public final void setLabel( String label ) public final void setLabel( String label )
{ {
if( getWorld().isClient || Objects.equals( this.label, label ) ) if( this.world.isClient || Objects.equals( this.label, label ) )
{ {
return; return;
} }

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared.computer.core;
import dan200.computercraft.shared.common.ClientTerminal; import dan200.computercraft.shared.common.ClientTerminal;
import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.network.server.*; import dan200.computercraft.shared.network.server.*;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
public class ClientComputer extends ClientTerminal implements IComputer public class ClientComputer extends ClientTerminal implements IComputer
{ {
@ -17,7 +17,7 @@ public class ClientComputer extends ClientTerminal implements IComputer
private boolean on = false; private boolean on = false;
private boolean blinking = false; private boolean blinking = false;
private CompoundTag userData = null; private NbtCompound userData = null;
public ClientComputer( int instanceID ) public ClientComputer( int instanceID )
@ -26,7 +26,7 @@ public class ClientComputer extends ClientTerminal implements IComputer
this.instanceID = instanceID; this.instanceID = instanceID;
} }
public CompoundTag getUserData() public NbtCompound getUserData()
{ {
return userData; return userData;
} }
@ -123,7 +123,7 @@ public class ClientComputer extends ClientTerminal implements IComputer
NetworkHandler.sendToServer( new MouseEventServerMessage( instanceID, MouseEventServerMessage.TYPE_SCROLL, direction, x, y ) ); NetworkHandler.sendToServer( new MouseEventServerMessage( instanceID, MouseEventServerMessage.TYPE_SCROLL, direction, x, y ) );
} }
public void setState( ComputerState state, CompoundTag userData ) public void setState( ComputerState state, NbtCompound userData )
{ {
on = state != ComputerState.OFF; on = state != ComputerState.OFF;
blinking = state == ComputerState.BLINKING; blinking = state == ComputerState.BLINKING;

View File

@ -25,7 +25,7 @@ import dan200.computercraft.shared.network.client.ComputerDeletedClientMessage;
import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage; import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage;
import me.shedaniel.cloth.api.utils.v1.GameInstanceUtils; import me.shedaniel.cloth.api.utils.v1.GameInstanceUtils;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -42,7 +42,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
private final Computer computer; private final Computer computer;
private World world; private World world;
private BlockPos position; private BlockPos position;
private CompoundTag userData; private NbtCompound userData;
private boolean changed; private boolean changed;
private boolean changedLastFrame; private boolean changedLastFrame;
@ -128,11 +128,11 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
computer.unload(); computer.unload();
} }
public CompoundTag getUserData() public NbtCompound getUserData()
{ {
if( userData == null ) if( userData == null )
{ {
userData = new CompoundTag(); userData = new NbtCompound();
} }
return userData; return userData;
} }

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.computer.items;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -18,7 +18,7 @@ public interface IComputerItem
default int getComputerID( @Nonnull ItemStack stack ) default int getComputerID( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
} }

View File

@ -45,7 +45,7 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe
ComputerFamily family = RecipeUtil.getFamily( json, "family" ); ComputerFamily family = RecipeUtil.getFamily( json, "family" );
RecipeUtil.ShapedTemplate template = RecipeUtil.getTemplate( json ); RecipeUtil.ShapedTemplate template = RecipeUtil.getTemplate( json );
ItemStack result = getItemStack( JsonHelper.getObject( json, "result" ) ); ItemStack result = outputFromJson( JsonHelper.getObject( json, "result" ) );
return create( identifier, group, template.width, template.height, template.ingredients, result, family ); return create( identifier, group, template.width, template.height, template.ingredients, result, family );
} }
@ -78,7 +78,7 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe
buf.writeVarInt( recipe.getWidth() ); buf.writeVarInt( recipe.getWidth() );
buf.writeVarInt( recipe.getHeight() ); buf.writeVarInt( recipe.getHeight() );
buf.writeString( recipe.getGroup() ); buf.writeString( recipe.getGroup() );
for( Ingredient ingredient : recipe.getPreviewInputs() ) for( Ingredient ingredient : recipe.getIngredients() )
{ {
ingredient.write( buf ); ingredient.write( buf );
} }

View File

@ -35,7 +35,7 @@ public final class PlayerCreativeLootCondition implements LootCondition
public boolean test( LootContext lootContext ) public boolean test( LootContext lootContext )
{ {
Entity entity = lootContext.get( LootContextParameters.THIS_ENTITY ); Entity entity = lootContext.get( LootContextParameters.THIS_ENTITY );
return entity instanceof PlayerEntity && ((PlayerEntity) entity).abilities.creativeMode; return entity instanceof PlayerEntity && ((PlayerEntity) entity).getAbilities().creativeMode;
} }
@Nonnull @Nonnull

View File

@ -17,7 +17,7 @@ import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
@ -85,7 +85,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem
public static int getDiskID( @Nonnull ItemStack stack ) public static int getDiskID( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
} }

View File

@ -13,7 +13,7 @@ import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -60,7 +60,7 @@ public class ItemPrintout extends Item
} }
if( text != null ) if( text != null )
{ {
CompoundTag tag = stack.getOrCreateTag(); NbtCompound tag = stack.getOrCreateTag();
tag.putInt( NBT_PAGES, text.length / LINES_PER_PAGE ); tag.putInt( NBT_PAGES, text.length / LINES_PER_PAGE );
for( int i = 0; i < text.length; i++ ) for( int i = 0; i < text.length; i++ )
{ {
@ -72,7 +72,7 @@ public class ItemPrintout extends Item
} }
if( colours != null ) if( colours != null )
{ {
CompoundTag tag = stack.getOrCreateTag(); NbtCompound tag = stack.getOrCreateTag();
for( int i = 0; i < colours.length; i++ ) for( int i = 0; i < colours.length; i++ )
{ {
if( colours[i] != null ) if( colours[i] != null )
@ -105,7 +105,7 @@ public class ItemPrintout extends Item
private static String[] getLines( @Nonnull ItemStack stack, String prefix ) private static String[] getLines( @Nonnull ItemStack stack, String prefix )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
int numLines = getPageCount( stack ) * LINES_PER_PAGE; int numLines = getPageCount( stack ) * LINES_PER_PAGE;
String[] lines = new String[numLines]; String[] lines = new String[numLines];
for( int i = 0; i < lines.length; i++ ) for( int i = 0; i < lines.length; i++ )
@ -117,7 +117,7 @@ public class ItemPrintout extends Item
public static int getPageCount( @Nonnull ItemStack stack ) public static int getPageCount( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_PAGES ) ? nbt.getInt( NBT_PAGES ) : 1; return nbt != null && nbt.contains( NBT_PAGES ) ? nbt.getInt( NBT_PAGES ) : 1;
} }
@ -152,7 +152,7 @@ public class ItemPrintout extends Item
public static String getTitle( @Nonnull ItemStack stack ) public static String getTitle( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : null; return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : null;
} }

View File

@ -16,7 +16,7 @@ import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
@ -41,7 +41,7 @@ public class ItemTreasureDisk extends Item implements IMedia
public static ItemStack create( String subPath, int colourIndex ) public static ItemStack create( String subPath, int colourIndex )
{ {
ItemStack result = new ItemStack( ComputerCraftRegistry.ModItems.TREASURE_DISK ); ItemStack result = new ItemStack( ComputerCraftRegistry.ModItems.TREASURE_DISK );
CompoundTag nbt = result.getOrCreateTag(); NbtCompound nbt = result.getOrCreateTag();
nbt.putString( NBT_SUB_PATH, subPath ); nbt.putString( NBT_SUB_PATH, subPath );
int slash = subPath.indexOf( '/' ); int slash = subPath.indexOf( '/' );
@ -62,7 +62,7 @@ public class ItemTreasureDisk extends Item implements IMedia
public static int getColour( @Nonnull ItemStack stack ) public static int getColour( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : Colour.BLUE.getHex(); return nbt != null && nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : Colour.BLUE.getHex();
} }
@ -84,7 +84,7 @@ public class ItemTreasureDisk extends Item implements IMedia
@Nonnull @Nonnull
private static String getTitle( @Nonnull ItemStack stack ) private static String getTitle( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : "'alongtimeago' by dan200"; return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : "'alongtimeago' by dan200";
} }
@ -128,7 +128,7 @@ public class ItemTreasureDisk extends Item implements IMedia
@Nonnull @Nonnull
private static String getSubPath( @Nonnull ItemStack stack ) private static String getSubPath( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_SUB_PATH ) ? nbt.getString( NBT_SUB_PATH ) : "dan200/alongtimeago"; return nbt != null && nbt.contains( NBT_SUB_PATH ) ? nbt.getString( NBT_SUB_PATH ) : "dan200/alongtimeago";
} }
} }

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared.network.client;
import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import net.fabricmc.fabric.api.network.PacketContext; import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -20,7 +20,7 @@ import javax.annotation.Nonnull;
public class ComputerDataClientMessage extends ComputerClientMessage public class ComputerDataClientMessage extends ComputerClientMessage
{ {
private ComputerState state; private ComputerState state;
private CompoundTag userData; private NbtCompound userData;
public ComputerDataClientMessage( ServerComputer computer ) public ComputerDataClientMessage( ServerComputer computer )
{ {
@ -38,7 +38,7 @@ public class ComputerDataClientMessage extends ComputerClientMessage
{ {
super.toBytes( buf ); super.toBytes( buf );
buf.writeEnumConstant( state ); buf.writeEnumConstant( state );
buf.writeCompoundTag( userData ); buf.writeNbt( userData );
} }
@Override @Override
@ -46,7 +46,7 @@ public class ComputerDataClientMessage extends ComputerClientMessage
{ {
super.fromBytes( buf ); super.fromBytes( buf );
state = buf.readEnumConstant( ComputerState.class ); state = buf.readEnumConstant( ComputerState.class );
userData = buf.readCompoundTag(); userData = buf.readNbt();
} }
@Override @Override

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared.network.server;
import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.core.IContainerComputer;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.util.NBTUtil; import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -42,7 +42,7 @@ public class QueueEventServerMessage extends ComputerServerMessage
{ {
super.toBytes( buf ); super.toBytes( buf );
buf.writeString( event ); buf.writeString( event );
buf.writeCompoundTag( args == null ? null : NBTUtil.encodeObjects( args ) ); buf.writeNbt( args == null ? null : NBTUtil.encodeObjects( args ) );
} }
@Override @Override
@ -51,7 +51,7 @@ public class QueueEventServerMessage extends ComputerServerMessage
super.fromBytes( buf ); super.fromBytes( buf );
event = buf.readString( Short.MAX_VALUE ); event = buf.readString( Short.MAX_VALUE );
CompoundTag args = buf.readCompoundTag(); NbtCompound args = buf.readNbt();
this.args = args == null ? null : NBTUtil.decodeObjects( args ); this.args = args == null ? null : NBTUtil.decodeObjects( args );
} }

View File

@ -8,9 +8,13 @@ package dan200.computercraft.shared.peripheral.diskdrive;
import dan200.computercraft.shared.ComputerCraftRegistry; import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.peripheral.speaker.BlockSpeaker;
import dan200.computercraft.shared.peripheral.speaker.TileSpeaker;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
@ -49,7 +53,13 @@ public class BlockDiskDrive extends BlockGeneric
placement.getPlayerFacing() placement.getPlayerFacing()
.getOpposite() ); .getOpposite() );
} }
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
return world.isClient ? null : BlockDiskDrive.checkType( type, ComputerCraftRegistry.ModTiles.DISK_DRIVE, TileDiskDrive::tick );
}
@Override @Override
public void afterBreak( public void afterBreak(
@Nonnull World world, @Nonnull PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity te, @Nonnull ItemStack stack @Nonnull World world, @Nonnull PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable BlockEntity te, @Nonnull ItemStack stack

View File

@ -23,7 +23,7 @@ import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
@ -32,10 +32,10 @@ import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Nameable; import net.minecraft.util.Nameable;
import net.minecraft.util.Tickable;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -43,7 +43,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public final class TileDiskDrive extends TileGeneric implements DefaultInventory, Tickable, IPeripheralTile, Nameable, NamedScreenHandlerFactory public final class TileDiskDrive extends TileGeneric implements DefaultInventory, IPeripheralTile, Nameable, NamedScreenHandlerFactory
{ {
private static final String NBT_NAME = "CustomName"; private static final String NBT_NAME = "CustomName";
private static final String NBT_ITEM = "Item"; private static final String NBT_ITEM = "Item";
@ -57,9 +57,9 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private boolean restartRecord = false; private boolean restartRecord = false;
private boolean ejectQueued; private boolean ejectQueued;
public TileDiskDrive( BlockEntityType<TileDiskDrive> type ) public TileDiskDrive( BlockEntityType<TileDiskDrive> type, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
} }
@Override @Override
@ -108,22 +108,23 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
} }
@Override @Override
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void readNbt( @Nonnull NbtCompound nbt )
{ {
super.fromTag( state, nbt ); super.readNbt( nbt );
customName = nbt.contains( NBT_NAME ) ? Text.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; customName = nbt.contains( NBT_NAME ) ? Text.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null;
if( nbt.contains( NBT_ITEM ) ) if( nbt.contains( NBT_ITEM ) )
{ {
CompoundTag item = nbt.getCompound( NBT_ITEM ); NbtCompound item = nbt.getCompound( NBT_ITEM );
diskStack = ItemStack.fromTag( item ); diskStack = ItemStack.fromNbt( item );
diskMount = null; diskMount = null;
} }
} }
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( @Nonnull CompoundTag nbt ) public NbtCompound writeNbt( @Nonnull NbtCompound nbt )
{ {
super.writeNbt( nbt );
if( customName != null ) if( customName != null )
{ {
nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) ); nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) );
@ -131,11 +132,11 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
if( !diskStack.isEmpty() ) if( !diskStack.isEmpty() )
{ {
CompoundTag item = new CompoundTag(); NbtCompound item = new NbtCompound();
diskStack.toTag( item ); diskStack.writeNbt( item );
nbt.put( NBT_ITEM, item ); nbt.put( NBT_ITEM, item );
} }
return super.toTag( nbt ); return nbt;
} }
@Override @Override
@ -148,40 +149,39 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
super.markDirty(); super.markDirty();
} }
@Override public static void tick( World world, BlockPos pos, BlockState state, TileDiskDrive tileDiskDrive)
public void tick()
{ {
// Ejection // Ejection
if( ejectQueued ) if( tileDiskDrive.ejectQueued )
{ {
ejectContents( false ); tileDiskDrive.ejectContents( false );
ejectQueued = false; tileDiskDrive.ejectQueued = false;
} }
// Music // Music
synchronized( this ) synchronized( tileDiskDrive )
{ {
if( !world.isClient && recordPlaying != recordQueued || restartRecord ) if( !world.isClient && tileDiskDrive.recordPlaying != tileDiskDrive.recordQueued || tileDiskDrive.restartRecord )
{ {
restartRecord = false; tileDiskDrive.restartRecord = false;
if( recordQueued ) if( tileDiskDrive.recordQueued )
{ {
IMedia contents = getDiskMedia(); IMedia contents = tileDiskDrive.getDiskMedia();
SoundEvent record = contents != null ? contents.getAudio( diskStack ) : null; SoundEvent record = contents != null ? contents.getAudio( tileDiskDrive.diskStack ) : null;
if( record != null ) if( record != null )
{ {
recordPlaying = true; tileDiskDrive.recordPlaying = true;
playRecord(); tileDiskDrive.playRecord();
} }
else else
{ {
recordQueued = false; tileDiskDrive.recordQueued = false;
} }
} }
else else
{ {
stopRecord(); tileDiskDrive.stopRecord();
recordPlaying = false; tileDiskDrive.recordPlaying = false;
} }
} }
} }
@ -479,7 +479,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private synchronized void ejectContents( boolean destroyed ) private synchronized void ejectContents( boolean destroyed )
{ {
if( getWorld().isClient || diskStack.isEmpty() ) if( this.world.isClient || diskStack.isEmpty() )
{ {
return; return;
} }

View File

@ -12,12 +12,13 @@ import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.EnchantedBookItem; import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.NbtElement;
import net.minecraft.tag.ServerTagManagerHolder; import net.minecraft.tag.ServerTagManagerHolder;
import net.minecraft.tag.TagGroup; import net.minecraft.tag.TagGroup;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.registry.Registry;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -71,19 +72,19 @@ public class ItemData
// requireNonNull is safe because we got the Identifiers out of the TagGroup to start with. Would be nicer // requireNonNull is safe because we got the Identifiers out of the TagGroup to start with. Would be nicer
// to stream the tags directly but TagGroup isn't a collection :( // to stream the tags directly but TagGroup isn't a collection :(
TagGroup<Item> itemTags = ServerTagManagerHolder.getTagManager().getItems(); TagGroup<Item> itemTags = ServerTagManagerHolder.getTagManager().getOrCreateTagGroup(Registry.ITEM_KEY);
data.put( "tags", DataHelpers.getTags( itemTags.getTagIds().stream() data.put( "tags", DataHelpers.getTags( itemTags.getTagIds().stream()
.filter( id -> Objects.requireNonNull( itemTags.getTag( id ) ).contains( stack.getItem() ) ) .filter( id -> Objects.requireNonNull( itemTags.getTag( id ) ).contains( stack.getItem() ) )
.collect( Collectors.toList() ) .collect( Collectors.toList() )
) ); // chaos x2 ) ); // chaos x2
CompoundTag tag = stack.getTag(); NbtCompound tag = stack.getTag();
if( tag != null && tag.contains( "display", NBTUtil.TAG_COMPOUND ) ) if( tag != null && tag.contains( "display", NBTUtil.TAG_COMPOUND ) )
{ {
CompoundTag displayTag = tag.getCompound( "display" ); NbtCompound displayTag = tag.getCompound( "display" );
if( displayTag.contains( "Lore", NBTUtil.TAG_LIST ) ) if( displayTag.contains( "Lore", NBTUtil.TAG_LIST ) )
{ {
ListTag loreTag = displayTag.getList( "Lore", NBTUtil.TAG_STRING ); NbtList loreTag = displayTag.getList( "Lore", NBTUtil.TAG_STRING );
data.put( "lore", loreTag.stream() data.put( "lore", loreTag.stream()
.map( ItemData::parseTextComponent ) .map( ItemData::parseTextComponent )
.filter( Objects::nonNull ) .filter( Objects::nonNull )
@ -112,7 +113,7 @@ public class ItemData
@Nullable @Nullable
private static Text parseTextComponent( @Nonnull Tag x ) private static Text parseTextComponent( @Nonnull NbtElement x )
{ {
try try
{ {
@ -138,7 +139,7 @@ public class ItemData
if( stack.getItem() instanceof EnchantedBookItem && (hideFlags & 32) == 0 ) if( stack.getItem() instanceof EnchantedBookItem && (hideFlags & 32) == 0 )
{ {
addEnchantments( EnchantedBookItem.getEnchantmentTag( stack ), enchants ); addEnchantments( EnchantedBookItem.getEnchantmentNbt( stack ), enchants );
} }
if( stack.hasEnchantments() && (hideFlags & 1) == 0 ) if( stack.hasEnchantments() && (hideFlags & 1) == 0 )
@ -161,14 +162,14 @@ public class ItemData
* @param enchants The enchantment map to add it to. * @param enchants The enchantment map to add it to.
* @see EnchantmentHelper * @see EnchantmentHelper
*/ */
private static void addEnchantments( @Nonnull ListTag rawEnchants, @Nonnull ArrayList<Map<String, Object>> enchants ) private static void addEnchantments( @Nonnull NbtList rawEnchants, @Nonnull ArrayList<Map<String, Object>> enchants )
{ {
if( rawEnchants.isEmpty() ) return; if( rawEnchants.isEmpty() ) return;
enchants.ensureCapacity( enchants.size() + rawEnchants.size() ); enchants.ensureCapacity( enchants.size() + rawEnchants.size() );
for( Map.Entry<Enchantment, Integer> entry : EnchantmentHelper.fromTag( rawEnchants ).entrySet() ) for( Map.Entry<Enchantment, Integer> entry : EnchantmentHelper.fromNbt( rawEnchants ).entrySet() )
{ {
Enchantment enchantment = entry.getKey(); Enchantment enchantment = entry.getKey();
Integer level = entry.getValue(); Integer level = entry.getValue();

View File

@ -23,7 +23,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@ -74,9 +74,9 @@ public class TileCable extends TileGeneric implements IPeripheralTile
private boolean hasModemDirection = false; private boolean hasModemDirection = false;
private boolean connectionsFormed = false; private boolean connectionsFormed = false;
public TileCable( BlockEntityType<? extends TileCable> type ) public TileCable( BlockEntityType<? extends TileCable> type, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
} }
@Override @Override
@ -119,7 +119,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
return ActionResult.FAIL; return ActionResult.FAIL;
} }
if( getWorld().isClient ) if( this.world.isClient )
{ {
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }
@ -377,20 +377,21 @@ public class TileCable extends TileGeneric implements IPeripheralTile
} }
@Override @Override
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void readNbt( @Nonnull NbtCompound nbt )
{ {
super.fromTag( state, nbt ); super.readNbt( nbt );
peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
peripheral.read( nbt, "" ); peripheral.read( nbt, "" );
} }
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( CompoundTag nbt ) public NbtCompound writeNbt( NbtCompound nbt )
{ {
super.writeNbt( nbt );
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed ); nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed );
peripheral.write( nbt, "" ); peripheral.write( nbt, "" );
return super.toTag( nbt ); return nbt;
} }
@Override @Override
@ -408,9 +409,10 @@ public class TileCable extends TileGeneric implements IPeripheralTile
} }
@Override @Override
public void resetBlock() public void setCachedState(BlockState state)
{ {
super.resetBlock(); super.setCachedState(state);
if(state != null) return;
hasModemDirection = false; hasModemDirection = false;
if( !world.isClient ) if( !world.isClient )
{ {

View File

@ -20,7 +20,7 @@ import dan200.computercraft.shared.util.TickScheduler;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -49,9 +49,9 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
private boolean destroyed = false; private boolean destroyed = false;
private boolean connectionsFormed = false; private boolean connectionsFormed = false;
public TileWiredModemFull( BlockEntityType<TileWiredModemFull> type ) public TileWiredModemFull( BlockEntityType<TileWiredModemFull> type, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
for( int i = 0; i < peripherals.length; i++ ) for( int i = 0; i < peripherals.length; i++ )
{ {
Direction facing = Direction.byId( i ); Direction facing = Direction.byId( i );
@ -315,9 +315,9 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
} }
@Override @Override
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void readNbt( @Nonnull NbtCompound nbt )
{ {
super.fromTag( state, nbt ); super.readNbt( nbt );
peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
for( int i = 0; i < peripherals.length; i++ ) for( int i = 0; i < peripherals.length; i++ )
{ {
@ -327,14 +327,15 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( CompoundTag nbt ) public NbtCompound writeNbt( NbtCompound nbt )
{ {
super.writeNbt( nbt );
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed ); nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed );
for( int i = 0; i < peripherals.length; i++ ) for( int i = 0; i < peripherals.length; i++ )
{ {
peripherals[i].write( nbt, Integer.toString( i ) ); peripherals[i].write( nbt, Integer.toString( i ) );
} }
return super.toTag( nbt ); return nbt;
} }
@Override @Override

View File

@ -12,7 +12,7 @@ import dan200.computercraft.shared.Peripherals;
import dan200.computercraft.shared.util.IDAssigner; import dan200.computercraft.shared.util.IDAssigner;
import dan200.computercraft.shared.util.NBTUtil; import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -135,7 +135,7 @@ public final class WiredModemLocalPeripheral
return peripheral == null ? Collections.emptyMap() : Collections.singletonMap( type + "_" + id, peripheral ); return peripheral == null ? Collections.emptyMap() : Collections.singletonMap( type + "_" + id, peripheral );
} }
public void write( @Nonnull CompoundTag tag, @Nonnull String suffix ) public void write( @Nonnull NbtCompound tag, @Nonnull String suffix )
{ {
if( id >= 0 ) if( id >= 0 )
{ {
@ -147,7 +147,7 @@ public final class WiredModemLocalPeripheral
} }
} }
public void read( @Nonnull CompoundTag tag, @Nonnull String suffix ) public void read( @Nonnull NbtCompound tag, @Nonnull String suffix )
{ {
id = tag.contains( NBT_PERIPHERAL_ID + suffix, NBTUtil.TAG_ANY_NUMERIC ) ? tag.getInt( NBT_PERIPHERAL_ID + suffix ) : -1; id = tag.contains( NBT_PERIPHERAL_ID + suffix, NBTUtil.TAG_ANY_NUMERIC ) ? tag.getInt( NBT_PERIPHERAL_ID + suffix ) : -1;

View File

@ -29,9 +29,9 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile
private Direction modemDirection = Direction.DOWN; private Direction modemDirection = Direction.DOWN;
private boolean destroyed = false; private boolean destroyed = false;
public TileWirelessModem( BlockEntityType<? extends TileWirelessModem> type, boolean advanced ) public TileWirelessModem( BlockEntityType<? extends TileWirelessModem> type, boolean advanced, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
this.advanced = advanced; this.advanced = advanced;
modem = new Peripheral( this ); modem = new Peripheral( this );
} }
@ -44,9 +44,10 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile
} }
@Override @Override
public void resetBlock() public void setCachedState(BlockState state)
{ {
super.resetBlock(); super.setCachedState(state);
if(state != null) return;
hasModemDirection = false; hasModemDirection = false;
world.getBlockTickScheduler() world.getBlockTickScheduler()
.schedule( getPos(), .schedule( getPos(),

View File

@ -48,7 +48,7 @@ public class BlockMonitor extends BlockGeneric
@Nullable @Nullable
public BlockState getPlacementState( ItemPlacementContext context ) public BlockState getPlacementState( ItemPlacementContext context )
{ {
float pitch = context.getPlayer() == null ? 0 : context.getPlayer().pitch; float pitch = context.getPlayer() == null ? 0 : context.getPlayer().getPitch();
Direction orientation; Direction orientation;
if( pitch > 66.5f ) if( pitch > 66.5f )
{ {

View File

@ -82,15 +82,15 @@ public final class ClientMonitor extends ClientTerminal
deleteBuffers(); deleteBuffers();
tboBuffer = GlStateManager.genBuffers(); tboBuffer = GlStateManager._glGenBuffers();
GlStateManager.bindBuffers( GL31.GL_TEXTURE_BUFFER, tboBuffer ); GlStateManager._glBindBuffer( GL31.GL_TEXTURE_BUFFER, tboBuffer );
GL15.glBufferData( GL31.GL_TEXTURE_BUFFER, 0, GL15.GL_STATIC_DRAW ); GL15.glBufferData( GL31.GL_TEXTURE_BUFFER, 0, GL15.GL_STATIC_DRAW );
tboTexture = GlStateManager.genTextures(); tboTexture = GlStateManager._genTexture();
GL11.glBindTexture( GL31.GL_TEXTURE_BUFFER, tboTexture ); GL11.glBindTexture( GL31.GL_TEXTURE_BUFFER, tboTexture );
GL31.glTexBuffer( GL31.GL_TEXTURE_BUFFER, GL30.GL_R8UI, tboBuffer ); GL31.glTexBuffer( GL31.GL_TEXTURE_BUFFER, GL30.GL_R8UI, tboBuffer );
GL11.glBindTexture( GL31.GL_TEXTURE_BUFFER, 0 ); GL11.glBindTexture( GL31.GL_TEXTURE_BUFFER, 0 );
GlStateManager.bindBuffers( GL31.GL_TEXTURE_BUFFER, 0 ); GlStateManager._glBindBuffer( GL31.GL_TEXTURE_BUFFER, 0 );
addMonitor(); addMonitor();
return true; return true;
@ -102,7 +102,7 @@ public final class ClientMonitor extends ClientTerminal
} }
deleteBuffers(); deleteBuffers();
buffer = new VertexBuffer( FixedWidthFontRenderer.TYPE.getVertexFormat() ); buffer = new VertexBuffer();
addMonitor(); addMonitor();
return true; return true;
@ -122,7 +122,7 @@ public final class ClientMonitor extends ClientTerminal
if( tboTexture != 0 ) if( tboTexture != 0 )
{ {
GlStateManager.deleteTexture( tboTexture ); GlStateManager._deleteTexture( tboTexture );
tboTexture = 0; tboTexture = 0;
} }

View File

@ -19,7 +19,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
@ -58,9 +58,9 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
private int xIndex = 0; private int xIndex = 0;
private int yIndex = 0; private int yIndex = 0;
public TileMonitor( BlockEntityType<? extends TileMonitor> type, boolean advanced ) public TileMonitor( BlockEntityType<? extends TileMonitor> type, boolean advanced, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
this.advanced = advanced; this.advanced = advanced;
} }
@ -164,7 +164,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
} }
@Override @Override
protected final void readDescription( @Nonnull CompoundTag nbt ) protected final void readDescription( @Nonnull NbtCompound nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
@ -207,7 +207,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
} }
@Override @Override
protected void writeDescription( @Nonnull CompoundTag nbt ) protected void writeDescription( @Nonnull NbtCompound nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
nbt.putInt( NBT_X, xIndex ); nbt.putInt( NBT_X, xIndex );
@ -286,9 +286,9 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
} }
@Override @Override
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void readNbt( @Nonnull NbtCompound nbt )
{ {
super.fromTag( state, nbt ); super.readNbt( nbt );
xIndex = nbt.getInt( NBT_X ); xIndex = nbt.getInt( NBT_X );
yIndex = nbt.getInt( NBT_Y ); yIndex = nbt.getInt( NBT_Y );
@ -300,20 +300,21 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( CompoundTag tag ) public NbtCompound writeNbt( NbtCompound tag )
{ {
super.writeNbt( tag );
tag.putInt( NBT_X, xIndex ); tag.putInt( NBT_X, xIndex );
tag.putInt( NBT_Y, yIndex ); tag.putInt( NBT_Y, yIndex );
tag.putInt( NBT_WIDTH, width ); tag.putInt( NBT_WIDTH, width );
tag.putInt( NBT_HEIGHT, height ); tag.putInt( NBT_HEIGHT, height );
return super.toTag( tag ); return tag;
} }
@Override // @Override //TODO: make BlockEntityRenderer work with this, i guess.
public double getRenderDistance() // public double getRenderDistance()
{ // {
return ComputerCraft.monitorDistanceSq; // return ComputerCraft.monitorDistanceSq;
} // }
// Sizing and placement stuff // Sizing and placement stuff

View File

@ -23,7 +23,7 @@ import net.minecraft.inventory.Inventories;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -34,6 +34,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.Nameable; import net.minecraft.util.Nameable;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -70,9 +71,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
private String pageTitle = ""; private String pageTitle = "";
private boolean printing = false; private boolean printing = false;
public TilePrinter( BlockEntityType<TilePrinter> type ) public TilePrinter( BlockEntityType<TilePrinter> type, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
} }
@Override @Override
@ -165,9 +166,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
} }
@Override @Override
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void readNbt( @Nonnull NbtCompound nbt )
{ {
super.fromTag( state, nbt ); super.readNbt( nbt );
customName = nbt.contains( NBT_NAME ) ? Text.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; customName = nbt.contains( NBT_NAME ) ? Text.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null;
@ -180,13 +181,14 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
} }
// Read inventory // Read inventory
Inventories.fromTag( nbt, inventory ); Inventories.readNbt( nbt, inventory );
} }
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( @Nonnull CompoundTag nbt ) public NbtCompound writeNbt( @Nonnull NbtCompound nbt )
{ {
super.writeNbt( nbt );
if( customName != null ) if( customName != null )
{ {
nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) ); nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) );
@ -201,9 +203,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
} }
// Write inventory // Write inventory
Inventories.toTag( nbt, inventory ); Inventories.writeNbt( nbt, inventory );
return super.toTag( nbt ); return nbt;
} }
boolean isPrinting() boolean isPrinting()

View File

@ -10,11 +10,15 @@ import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty; import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -43,4 +47,11 @@ public class BlockSpeaker extends BlockGeneric
{ {
properties.add( FACING ); properties.add( FACING );
} }
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker( World world, BlockState state, BlockEntityType<T> type){
return world.isClient ? null : BlockSpeaker.checkType( type, ComputerCraftRegistry.ModTiles.SPEAKER, TileSpeaker::tick );
}
} }

View File

@ -9,8 +9,9 @@ package dan200.computercraft.shared.peripheral.speaker;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralTile; import dan200.computercraft.api.peripheral.IPeripheralTile;
import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.common.TileGeneric;
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -19,22 +20,21 @@ import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class TileSpeaker extends TileGeneric implements Tickable, IPeripheralTile public class TileSpeaker extends TileGeneric implements IPeripheralTile
{ {
public static final int MIN_TICKS_BETWEEN_SOUNDS = 1; public static final int MIN_TICKS_BETWEEN_SOUNDS = 1;
private final SpeakerPeripheral peripheral; private final SpeakerPeripheral peripheral;
public TileSpeaker( BlockEntityType<TileSpeaker> type ) public TileSpeaker( BlockEntityType<TileSpeaker> type, BlockPos pos, BlockState state )
{ {
super( type ); super( type, pos, state );
peripheral = new Peripheral( this ); peripheral = new Peripheral( this );
} }
@Override public static void tick( World world, BlockPos pos, BlockState state, TileSpeaker tileSpeaker )
public void tick()
{ {
peripheral.update(); tileSpeaker.peripheral.update();
} }
@Nonnull @Nonnull

View File

@ -68,7 +68,7 @@ public class PocketAPI implements ILuaAPI
return new Object[] { false, "Cannot find player" }; return new Object[] { false, "Cannot find player" };
} }
PlayerEntity player = (PlayerEntity) entity; PlayerEntity player = (PlayerEntity) entity;
PlayerInventory inventory = player.inventory; PlayerInventory inventory = player.getInventory();
IPocketUpgrade previousUpgrade = computer.getUpgrade(); IPocketUpgrade previousUpgrade = computer.getUpgrade();
// Attempt to find the upgrade, starting in the main segment, and then looking in the opposite // Attempt to find the upgrade, starting in the main segment, and then looking in the opposite
@ -143,7 +143,7 @@ public class PocketAPI implements ILuaAPI
return new Object[] { false, "Cannot find player" }; return new Object[] { false, "Cannot find player" };
} }
PlayerEntity player = (PlayerEntity) entity; PlayerEntity player = (PlayerEntity) entity;
PlayerInventory inventory = player.inventory; PlayerInventory inventory = player.getInventory();
IPocketUpgrade previousUpgrade = computer.getUpgrade(); IPocketUpgrade previousUpgrade = computer.getUpgrade();
if( previousUpgrade == null ) if( previousUpgrade == null )

View File

@ -22,7 +22,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -57,7 +57,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
if( entity instanceof PlayerEntity ) if( entity instanceof PlayerEntity )
{ {
PlayerInventory inventory = ((PlayerEntity) entity).inventory; PlayerInventory inventory = ((PlayerEntity) entity).getInventory();
return inventory.main.contains( stack ) || inventory.offHand.contains( stack ) ? entity : null; return inventory.main.contains( stack ) || inventory.offHand.contains( stack ) ? entity : null;
} }
else if( entity instanceof LivingEntity ) else if( entity instanceof LivingEntity )
@ -87,14 +87,14 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override @Override
public int getLight() public int getLight()
{ {
CompoundTag tag = getUserData(); NbtCompound tag = getUserData();
return tag.contains( NBT_LIGHT, NBTUtil.TAG_ANY_NUMERIC ) ? tag.getInt( NBT_LIGHT ) : -1; return tag.contains( NBT_LIGHT, NBTUtil.TAG_ANY_NUMERIC ) ? tag.getInt( NBT_LIGHT ) : -1;
} }
@Override @Override
public void setLight( int colour ) public void setLight( int colour )
{ {
CompoundTag tag = getUserData(); NbtCompound tag = getUserData();
if( colour >= 0 && colour <= 0xFFFFFF ) if( colour >= 0 && colour <= 0xFFFFFF )
{ {
if( !tag.contains( NBT_LIGHT, NBTUtil.TAG_ANY_NUMERIC ) || tag.getInt( NBT_LIGHT ) != colour ) if( !tag.contains( NBT_LIGHT, NBTUtil.TAG_ANY_NUMERIC ) || tag.getInt( NBT_LIGHT ) != colour )
@ -112,7 +112,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Nonnull @Nonnull
@Override @Override
public CompoundTag getUpgradeNBTData() public NbtCompound getUpgradeNBTData()
{ {
return ItemPocketComputer.getUpgradeInfo( stack ); return ItemPocketComputer.getUpgradeInfo( stack );
} }
@ -122,7 +122,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
{ {
if( entity instanceof PlayerEntity ) if( entity instanceof PlayerEntity )
{ {
((PlayerEntity) entity).inventory.markDirty(); ((PlayerEntity) entity).getInventory().markDirty();
} }
} }

View File

@ -33,7 +33,7 @@ import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
@ -92,7 +92,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
ClientComputer computer = getClientComputer( stack ); ClientComputer computer = getClientComputer( stack );
if( computer != null && computer.isOn() ) if( computer != null && computer.isOn() )
{ {
CompoundTag computerNBT = computer.getUserData(); NbtCompound computerNBT = computer.getUserData();
if( computerNBT != null && computerNBT.contains( NBT_LIGHT ) ) if( computerNBT != null && computerNBT.contains( NBT_LIGHT ) )
{ {
return computerNBT.getInt( NBT_LIGHT ); return computerNBT.getInt( NBT_LIGHT );
@ -103,7 +103,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
public static void setUpgrade( @Nonnull ItemStack stack, IPocketUpgrade upgrade ) public static void setUpgrade( @Nonnull ItemStack stack, IPocketUpgrade upgrade )
{ {
CompoundTag compound = stack.getOrCreateTag(); NbtCompound compound = stack.getOrCreateTag();
if( upgrade == null ) if( upgrade == null )
{ {
@ -119,7 +119,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
compound.remove( NBT_UPGRADE_INFO ); compound.remove( NBT_UPGRADE_INFO );
} }
public static CompoundTag getUpgradeInfo( @Nonnull ItemStack stack ) public static NbtCompound getUpgradeInfo( @Nonnull ItemStack stack )
{ {
return stack.getOrCreateSubTag( NBT_UPGRADE_INFO ); return stack.getOrCreateSubTag( NBT_UPGRADE_INFO );
} }
@ -147,7 +147,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
ItemStack stack = player.getStackInHand( hand ); ItemStack stack = player.getStackInHand( hand );
if( !world.isClient ) if( !world.isClient )
{ {
PocketServerComputer computer = createServerComputer( world, player.inventory, player, stack ); PocketServerComputer computer = createServerComputer( world, player.getInventory(), player, stack );
boolean stop = false; boolean stop = false;
if( computer != null ) if( computer != null )
@ -177,7 +177,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
if( !world.isClient ) if( !world.isClient )
{ {
// Server side // Server side
Inventory inventory = entity instanceof PlayerEntity ? ((PlayerEntity) entity).inventory : null; Inventory inventory = entity instanceof PlayerEntity ? ((PlayerEntity) entity).getInventory() : null;
PocketServerComputer computer = createServerComputer( world, inventory, entity, stack ); PocketServerComputer computer = createServerComputer( world, inventory, entity, stack );
if( computer != null ) if( computer != null )
{ {
@ -341,7 +341,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
public static IPocketUpgrade getUpgrade( @Nonnull ItemStack stack ) public static IPocketUpgrade getUpgrade( @Nonnull ItemStack stack )
{ {
CompoundTag compound = stack.getTag(); NbtCompound compound = stack.getTag();
return compound != null && compound.contains( NBT_UPGRADE ) ? PocketUpgrades.get( compound.getString( NBT_UPGRADE ) ) : null; return compound != null && compound.contains( NBT_UPGRADE ) ? PocketUpgrades.get( compound.getString( NBT_UPGRADE ) ) : null;
} }
@ -402,13 +402,13 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
private static int getInstanceID( @Nonnull ItemStack stack ) private static int getInstanceID( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_INSTANCE ) ? nbt.getInt( NBT_INSTANCE ) : -1; return nbt != null && nbt.contains( NBT_INSTANCE ) ? nbt.getInt( NBT_INSTANCE ) : -1;
} }
private static int getSessionID( @Nonnull ItemStack stack ) private static int getSessionID( @Nonnull ItemStack stack )
{ {
CompoundTag nbt = stack.getTag(); NbtCompound nbt = stack.getTag();
return nbt != null && nbt.contains( NBT_SESSION ) ? nbt.getInt( NBT_SESSION ) : -1; return nbt != null && nbt.contains( NBT_SESSION ) ? nbt.getInt( NBT_SESSION ) : -1;
} }

View File

@ -7,14 +7,18 @@
package dan200.computercraft.shared.turtle.blocks; package dan200.computercraft.shared.turtle.blocks;
import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.computer.blocks.BlockComputerBase; import dan200.computercraft.shared.computer.blocks.BlockComputerBase;
import dan200.computercraft.shared.computer.blocks.TileComputerBase; import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.turtle.items.ITurtleItem; import dan200.computercraft.shared.turtle.items.ITurtleItem;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory; import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -176,4 +180,10 @@ public class BlockTurtle extends BlockComputerBase<TileTurtle> implements Waterl
} }
} }
} }
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type){
return world.isClient ? null : BlockTurtle.checkType( type, ComputerCraftRegistry.ModTiles.TURTLE_NORMAL, TileTurtle::tick );
}
} }

View File

@ -18,6 +18,7 @@ import dan200.computercraft.shared.computer.blocks.TileComputerBase;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
import dan200.computercraft.shared.turtle.apis.TurtleAPI; import dan200.computercraft.shared.turtle.apis.TurtleAPI;
import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.core.TurtleBrain;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
@ -29,8 +30,8 @@ import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.DyeItem; import net.minecraft.item.DyeItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtList;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor; import net.minecraft.util.DyeColor;
@ -41,6 +42,7 @@ import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -57,9 +59,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
private TurtleBrain brain = new TurtleBrain( this ); private TurtleBrain brain = new TurtleBrain( this );
private MoveState moveState = MoveState.NOT_MOVED; private MoveState moveState = MoveState.NOT_MOVED;
public TileTurtle( BlockEntityType<? extends TileGeneric> type, ComputerFamily family ) public TileTurtle( BlockEntityType<? extends TileGeneric> type, ComputerFamily family, BlockPos pos, BlockState state )
{ {
super( type, family ); super( type, family, pos, state );
} }
@Override @Override
@ -233,7 +235,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
if( !player.isCreative() ) if( !player.isCreative() )
{ {
player.setStackInHand( hand, new ItemStack( Items.BUCKET ) ); player.setStackInHand( hand, new ItemStack( Items.BUCKET ) );
player.inventory.markDirty(); player.getInventory().markDirty();
} }
} }
} }
@ -263,24 +265,22 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
} }
} }
@Override public static void tick( World world, BlockPos pos, BlockState state, TileTurtle tileTurtle)
public void tick()
{ {
super.tick(); tileTurtle.brain.update();
brain.update(); if( !tileTurtle.getWorld().isClient && tileTurtle.inventoryChanged )
if( !getWorld().isClient && inventoryChanged )
{ {
ServerComputer computer = getServerComputer(); ServerComputer computer = tileTurtle.getServerComputer();
if( computer != null ) if( computer != null )
{ {
computer.queueEvent( "turtle_inventory" ); computer.queueEvent( "turtle_inventory" );
} }
inventoryChanged = false; tileTurtle.inventoryChanged = false;
for( int n = 0; n < size(); n++ ) for( int n = 0; n < tileTurtle.size(); n++ )
{ {
previousInventory.set( n, tileTurtle.previousInventory.set( n,
getStack( n ).copy() ); tileTurtle.getStack( n ).copy() );
} }
} }
} }
@ -292,19 +292,19 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Nonnull @Nonnull
@Override @Override
public CompoundTag toTag( @Nonnull CompoundTag nbt ) public NbtCompound writeNbt( @Nonnull NbtCompound nbt )
{ {
super.readNbt( nbt );
// Write inventory // Write inventory
ListTag nbttaglist = new ListTag(); NbtList nbttaglist = new NbtList();
for( int i = 0; i < INVENTORY_SIZE; i++ ) for( int i = 0; i < INVENTORY_SIZE; i++ )
{ {
if( !inventory.get( i ) if( !inventory.get( i )
.isEmpty() ) .isEmpty() )
{ {
CompoundTag tag = new CompoundTag(); NbtCompound tag = new NbtCompound();
tag.putByte( "Slot", (byte) i ); tag.putByte( "Slot", (byte) i );
inventory.get( i ) inventory.get( i ).writeNbt( tag );
.toTag( tag );
nbttaglist.add( tag ); nbttaglist.add( tag );
} }
} }
@ -313,27 +313,27 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Write brain // Write brain
nbt = brain.writeToNBT( nbt ); nbt = brain.writeToNBT( nbt );
return super.toTag( nbt ); return nbt;
} }
// IDirectionalTile // IDirectionalTile
@Override @Override
public void fromTag( @Nonnull BlockState state, @Nonnull CompoundTag nbt ) public void readNbt( @Nonnull NbtCompound nbt )
{ {
super.fromTag( state, nbt ); super.writeNbt( nbt );
// Read inventory // Read inventory
ListTag nbttaglist = nbt.getList( "Items", NBTUtil.TAG_COMPOUND ); NbtList nbttaglist = nbt.getList( "Items", NBTUtil.TAG_COMPOUND );
inventory.clear(); inventory.clear();
previousInventory.clear(); previousInventory.clear();
for( int i = 0; i < nbttaglist.size(); i++ ) for( int i = 0; i < nbttaglist.size(); i++ )
{ {
CompoundTag tag = nbttaglist.getCompound( i ); NbtCompound tag = nbttaglist.getCompound( i );
int slot = tag.getByte( "Slot" ) & 0xff; int slot = tag.getByte( "Slot" ) & 0xff;
if( slot < size() ) if( slot < size() )
{ {
inventory.set( slot, ItemStack.fromTag( tag ) ); inventory.set( slot, ItemStack.fromNbt( tag ) );
previousInventory.set( slot, inventory.get( slot ) previousInventory.set( slot, inventory.get( slot )
.copy() ); .copy() );
} }
@ -372,14 +372,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
} }
@Override @Override
protected void writeDescription( @Nonnull CompoundTag nbt ) protected void writeDescription( @Nonnull NbtCompound nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
brain.writeDescription( nbt ); brain.writeDescription( nbt );
} }
@Override @Override
protected void readDescription( @Nonnull CompoundTag nbt ) protected void readDescription( @Nonnull NbtCompound nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
brain.readDescription( nbt ); brain.readDescription( nbt );

View File

@ -27,7 +27,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType; import net.minecraft.entity.MovementType;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.tag.FluidTags; import net.minecraft.tag.FluidTags;
@ -62,7 +62,7 @@ public class TurtleBrain implements ITurtleAccess
private final Queue<TurtleCommandQueueEntry> commandQueue = new ArrayDeque<>(); private final Queue<TurtleCommandQueueEntry> commandQueue = new ArrayDeque<>();
private final Map<TurtleSide, ITurtleUpgrade> upgrades = new EnumMap<>( TurtleSide.class ); private final Map<TurtleSide, ITurtleUpgrade> upgrades = new EnumMap<>( TurtleSide.class );
private final Map<TurtleSide, IPeripheral> peripherals = new EnumMap<>( TurtleSide.class ); private final Map<TurtleSide, IPeripheral> peripherals = new EnumMap<>( TurtleSide.class );
private final Map<TurtleSide, CompoundTag> upgradeNBTData = new EnumMap<>( TurtleSide.class ); private final Map<TurtleSide, NbtCompound> upgradeNBTData = new EnumMap<>( TurtleSide.class );
TurtlePlayer cachedPlayer; TurtlePlayer cachedPlayer;
private TileTurtle owner; private TileTurtle owner;
private final Inventory inventory = (InventoryDelegate) () -> owner; private final Inventory inventory = (InventoryDelegate) () -> owner;
@ -256,7 +256,7 @@ public class TurtleBrain implements ITurtleAccess
{ {
// Copy the old turtle state into the new turtle // Copy the old turtle state into the new turtle
TileTurtle newTurtle = (TileTurtle) newTile; TileTurtle newTurtle = (TileTurtle) newTile;
newTurtle.setLocation( world, pos ); newTurtle.setLocation( world, pos ); //FIXME: setLocation no longer exists.
newTurtle.transferStateFrom( oldOwner ); newTurtle.transferStateFrom( oldOwner );
newTurtle.createServerComputer() newTurtle.createServerComputer()
.setWorld( world ); .setWorld( world );
@ -543,12 +543,12 @@ public class TurtleBrain implements ITurtleAccess
@Nonnull @Nonnull
@Override @Override
public CompoundTag getUpgradeNBTData( TurtleSide side ) public NbtCompound getUpgradeNBTData( TurtleSide side )
{ {
CompoundTag nbt = upgradeNBTData.get( side ); NbtCompound nbt = upgradeNBTData.get( side );
if( nbt == null ) if( nbt == null )
{ {
upgradeNBTData.put( side, nbt = new CompoundTag() ); upgradeNBTData.put( side, nbt = new NbtCompound() );
} }
return nbt; return nbt;
} }
@ -800,7 +800,7 @@ public class TurtleBrain implements ITurtleAccess
return previous + (next - previous) * f; return previous + (next - previous) * f;
} }
public void readFromNBT( CompoundTag nbt ) public void readFromNBT( NbtCompound nbt )
{ {
readCommon( nbt ); readCommon( nbt );
@ -810,7 +810,7 @@ public class TurtleBrain implements ITurtleAccess
// Read owner // Read owner
if( nbt.contains( "Owner", NBTUtil.TAG_COMPOUND ) ) if( nbt.contains( "Owner", NBTUtil.TAG_COMPOUND ) )
{ {
CompoundTag owner = nbt.getCompound( "Owner" ); NbtCompound owner = nbt.getCompound( "Owner" );
owningPlayer = new GameProfile( new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ), owner.getString( "Name" ) ); owningPlayer = new GameProfile( new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ), owner.getString( "Name" ) );
} }
else else
@ -824,7 +824,7 @@ public class TurtleBrain implements ITurtleAccess
* *
* @param nbt The tag to read from * @param nbt The tag to read from
*/ */
private void readCommon( CompoundTag nbt ) private void readCommon( NbtCompound nbt )
{ {
// Read fields // Read fields
colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1; colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1;
@ -851,7 +851,7 @@ public class TurtleBrain implements ITurtleAccess
} }
} }
public CompoundTag writeToNBT( CompoundTag nbt ) public NbtCompound writeToNBT( NbtCompound nbt )
{ {
writeCommon( nbt ); writeCommon( nbt );
@ -861,7 +861,7 @@ public class TurtleBrain implements ITurtleAccess
// Write owner // Write owner
if( owningPlayer != null ) if( owningPlayer != null )
{ {
CompoundTag owner = new CompoundTag(); NbtCompound owner = new NbtCompound();
nbt.put( "Owner", owner ); nbt.put( "Owner", owner );
owner.putLong( "UpperId", owningPlayer.getId() owner.putLong( "UpperId", owningPlayer.getId()
@ -874,7 +874,7 @@ public class TurtleBrain implements ITurtleAccess
return nbt; return nbt;
} }
private void writeCommon( CompoundTag nbt ) private void writeCommon( NbtCompound nbt )
{ {
nbt.putInt( NBT_FUEL, fuelLevel ); nbt.putInt( NBT_FUEL, fuelLevel );
if( colourHex != -1 ) if( colourHex != -1 )
@ -917,7 +917,7 @@ public class TurtleBrain implements ITurtleAccess
.toString() : null; .toString() : null;
} }
public void readDescription( CompoundTag nbt ) public void readDescription( NbtCompound nbt )
{ {
readCommon( nbt ); readCommon( nbt );
@ -931,7 +931,7 @@ public class TurtleBrain implements ITurtleAccess
} }
} }
public void writeDescription( CompoundTag nbt ) public void writeDescription( NbtCompound nbt )
{ {
writeCommon( nbt ); writeCommon( nbt );
nbt.putInt( "Animation", animation.ordinal() ); nbt.putInt( "Animation", animation.ordinal() );

View File

@ -131,11 +131,11 @@ public class TurtleMoveCommand implements ITurtleCommand
private static TurtleCommandResult canEnter( TurtlePlayer turtlePlayer, World world, BlockPos position ) private static TurtleCommandResult canEnter( TurtlePlayer turtlePlayer, World world, BlockPos position )
{ {
if( World.isOutOfBuildLimitVertically( position ) ) if( world.isOutOfHeightLimit( position ) )
{ {
return TurtleCommandResult.failure( position.getY() < 0 ? "Too low to move" : "Too high to move" ); return TurtleCommandResult.failure( position.getY() < 0 ? "Too low to move" : "Too high to move" );
} }
if( !World.isInBuildLimit( position ) ) if( !world.isInBuildLimit( position ) )
{ {
return TurtleCommandResult.failure( "Cannot leave the world" ); return TurtleCommandResult.failure( "Cannot leave the world" );
} }

View File

@ -193,24 +193,24 @@ public class TurtlePlaceCommand implements ITurtleCommand
if( direction.getAxis() != Direction.Axis.Y ) if( direction.getAxis() != Direction.Axis.Y )
{ {
turtlePlayer.yaw = direction.asRotation(); turtlePlayer.setYaw(direction.asRotation());
turtlePlayer.pitch = 0.0f; turtlePlayer.setPitch(0.0f);
} }
else else
{ {
turtlePlayer.yaw = turtle.getDirection() turtlePlayer.setYaw(turtle.getDirection()
.asRotation(); .asRotation());
turtlePlayer.pitch = DirectionUtil.toPitchAngle( direction ); turtlePlayer.setPitch(DirectionUtil.toPitchAngle( direction ));
} }
turtlePlayer.setPos( posX, posY, posZ ); turtlePlayer.setPos( posX, posY, posZ );
turtlePlayer.prevX = posX; turtlePlayer.prevX = posX;
turtlePlayer.prevY = posY; turtlePlayer.prevY = posY;
turtlePlayer.prevZ = posZ; turtlePlayer.prevZ = posZ;
turtlePlayer.prevPitch = turtlePlayer.pitch; turtlePlayer.prevPitch = turtlePlayer.getPitch();
turtlePlayer.prevYaw = turtlePlayer.yaw; turtlePlayer.prevYaw = turtlePlayer.getYaw();
turtlePlayer.headYaw = turtlePlayer.yaw; turtlePlayer.headYaw = turtlePlayer.getYaw();
turtlePlayer.prevHeadYaw = turtlePlayer.headYaw; turtlePlayer.prevHeadYaw = turtlePlayer.headYaw;
} }
@ -403,7 +403,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
Direction side, boolean allowReplaceable, String[] outErrorMessage ) Direction side, boolean allowReplaceable, String[] outErrorMessage )
{ {
World world = turtle.getWorld(); World world = turtle.getWorld();
if( !World.isInBuildLimit( position ) || world.isAir( position ) || (context.getStack() if( !world.isInBuildLimit( position ) || world.isAir( position ) || (context.getStack()
.getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, .getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world,
position )) ) position )) )
{ {

View File

@ -84,11 +84,11 @@ public final class TurtlePlayer extends FakePlayer
BlockPos position = turtle.getPosition(); BlockPos position = turtle.getPosition();
setPos( position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5 ); setPos( position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5 );
yaw = turtle.getDirection() setYaw(turtle.getDirection()
.asRotation(); .asRotation());
pitch = 0.0f; setPitch(0.0f);
inventory.clear(); getInventory().clear();
} }
public static TurtlePlayer get( ITurtleAccess access ) public static TurtlePlayer get( ITurtleAccess access )
@ -112,23 +112,23 @@ public final class TurtlePlayer extends FakePlayer
public void loadInventory( @Nonnull ItemStack currentStack ) public void loadInventory( @Nonnull ItemStack currentStack )
{ {
// Load up the fake inventory // Load up the fake inventory
inventory.selectedSlot = 0; getInventory().selectedSlot = 0;
inventory.setStack( 0, currentStack ); getInventory().setStack( 0, currentStack );
} }
public ItemStack unloadInventory( ITurtleAccess turtle ) public ItemStack unloadInventory( ITurtleAccess turtle )
{ {
// Get the item we placed with // Get the item we placed with
ItemStack results = inventory.getStack( 0 ); ItemStack results = getInventory().getStack( 0 );
inventory.setStack( 0, ItemStack.EMPTY ); getInventory().setStack( 0, ItemStack.EMPTY );
// Store (or drop) anything else we found // Store (or drop) anything else we found
BlockPos dropPosition = turtle.getPosition(); BlockPos dropPosition = turtle.getPosition();
Direction dropDirection = turtle.getDirection() Direction dropDirection = turtle.getDirection()
.getOpposite(); .getOpposite();
for( int i = 0; i < inventory.size(); i++ ) for( int i = 0; i < getInventory().size(); i++ )
{ {
ItemStack stack = inventory.getStack( i ); ItemStack stack = getInventory().getStack( i );
if( !stack.isEmpty() ) if( !stack.isEmpty() )
{ {
ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() ); ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() );
@ -136,10 +136,10 @@ public final class TurtlePlayer extends FakePlayer
{ {
WorldUtil.dropItemStack( remainder, turtle.getWorld(), dropPosition, dropDirection ); WorldUtil.dropItemStack( remainder, turtle.getWorld(), dropPosition, dropDirection );
} }
inventory.setStack( i, ItemStack.EMPTY ); getInventory().setStack( i, ItemStack.EMPTY );
} }
} }
inventory.markDirty(); getInventory().markDirty();
return results; return results;
} }
@ -207,30 +207,30 @@ public final class TurtlePlayer extends FakePlayer
{ {
} }
@Override // @Override //FIXME: These need to be fixed.
public void openEditBookScreen( @Nonnull ItemStack stack, @Nonnull Hand hand ) // public void openEditBookScreen( @Nonnull ItemStack stack, @Nonnull Hand hand )
{ // {
} // }
@Override @Override
public void closeHandledScreen() public void closeHandledScreen()
{ {
} }
@Override // @Override
public void updateCursorStack() // public void updateCursorStack()
{ // {
} // }
@Override // @Override
protected void onStatusEffectApplied( @Nonnull StatusEffectInstance id ) // protected void onStatusEffectApplied( @Nonnull StatusEffectInstance id )
{ // {
} // }
@Override // @Override
protected void onStatusEffectUpgraded( @Nonnull StatusEffectInstance id, boolean apply ) // protected void onStatusEffectUpgraded( @Nonnull StatusEffectInstance id, boolean apply )
{ // {
} // }
@Override @Override
protected void onStatusEffectRemoved( @Nonnull StatusEffectInstance effect ) protected void onStatusEffectRemoved( @Nonnull StatusEffectInstance effect )

View File

@ -135,7 +135,7 @@ public class TurtleSuckCommand implements ITurtleCommand
{ {
if( remainder.isEmpty() && leaveStack.isEmpty() ) if( remainder.isEmpty() && leaveStack.isEmpty() )
{ {
entity.remove(); entity.discard();
} }
else if( remainder.isEmpty() ) else if( remainder.isEmpty() )
{ {

View File

@ -15,7 +15,7 @@ import dan200.computercraft.shared.computer.items.ItemComputerBase;
import dan200.computercraft.shared.turtle.blocks.BlockTurtle; import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
@ -148,7 +148,7 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
@Override @Override
public ITurtleUpgrade getUpgrade( @Nonnull ItemStack stack, @Nonnull TurtleSide side ) public ITurtleUpgrade getUpgrade( @Nonnull ItemStack stack, @Nonnull TurtleSide side )
{ {
CompoundTag tag = stack.getTag(); NbtCompound tag = stack.getTag();
if( tag == null ) if( tag == null )
{ {
return null; return null;
@ -161,14 +161,14 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
@Override @Override
public int getFuelLevel( @Nonnull ItemStack stack ) public int getFuelLevel( @Nonnull ItemStack stack )
{ {
CompoundTag tag = stack.getTag(); NbtCompound tag = stack.getTag();
return tag != null && tag.contains( NBT_FUEL ) ? tag.getInt( NBT_FUEL ) : 0; return tag != null && tag.contains( NBT_FUEL ) ? tag.getInt( NBT_FUEL ) : 0;
} }
@Override @Override
public Identifier getOverlay( @Nonnull ItemStack stack ) public Identifier getOverlay( @Nonnull ItemStack stack )
{ {
CompoundTag tag = stack.getTag(); NbtCompound tag = stack.getTag();
return tag != null && tag.contains( NBT_OVERLAY ) ? new Identifier( tag.getString( NBT_OVERLAY ) ) : null; return tag != null && tag.contains( NBT_OVERLAY ) ? new Identifier( tag.getString( NBT_OVERLAY ) ) : null;
} }

View File

@ -117,7 +117,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
results.add( result ); results.add( result );
result.onCraft( world, player, result.getCount() ); result.onCraft( world, player, result.getCount() );
DefaultedList<ItemStack> remainders = recipe.getRemainingStacks( this ); DefaultedList<ItemStack> remainders = recipe.getRemainder( this );
for( int slot = 0; slot < remainders.size(); slot++ ) for( int slot = 0; slot < remainders.size(); slot++ )
{ {

View File

@ -15,7 +15,7 @@ import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeriph
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.util.ModelIdentifier; import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -67,7 +67,7 @@ public class TurtleModem extends AbstractTurtleUpgrade
boolean active = false; boolean active = false;
if( turtle != null ) if( turtle != null )
{ {
CompoundTag turtleNBT = turtle.getUpgradeNBTData( side ); NbtCompound turtleNBT = turtle.getUpgradeNBTData( side );
active = turtleNBT.contains( "active" ) && turtleNBT.getBoolean( "active" ); active = turtleNBT.contains( "active" ) && turtleNBT.getBoolean( "active" );
} }

View File

@ -26,15 +26,15 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.util.math.AffineTransformation; import net.minecraft.util.math.AffineTransformation;
import net.minecraft.client.util.math.Vector3f; import net.minecraft.util.math.Vec3f;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -76,7 +76,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
@Override @Override
public boolean isItemSuitable( @Nonnull ItemStack stack ) public boolean isItemSuitable( @Nonnull ItemStack stack )
{ {
CompoundTag tag = stack.getTag(); NbtCompound tag = stack.getTag();
if( tag == null || tag.isEmpty() ) return true; if( tag == null || tag.isEmpty() ) return true;
// Check we've not got anything vaguely interesting on the item. We allow other mods to add their // Check we've not got anything vaguely interesting on the item. We allow other mods to add their
@ -107,7 +107,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side ) public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{ {
float xOffset = side == TurtleSide.LEFT ? -0.40625f : 0.40625f; float xOffset = side == TurtleSide.LEFT ? -0.40625f : 0.40625f;
return TransformedModel.of( getCraftingItem(), new AffineTransformation( new Vector3f( xOffset + 1, 0, 1 ), Vector3f.POSITIVE_Y.getDegreesQuaternion( 270 ), new Vector3f( 1, 1, 1 ), Vector3f.POSITIVE_Z.getDegreesQuaternion( 90 ) ) ); return TransformedModel.of( getCraftingItem(), new AffineTransformation( new Vec3f( xOffset + 1, 0, 1 ), Vec3f.POSITIVE_Y.getDegreesQuaternion( 270 ), new Vec3f( 1, 1, 1 ), Vec3f.POSITIVE_Z.getDegreesQuaternion( 90 ) ) );
} }
private TurtleCommandResult attack( ITurtleAccess turtle, Direction direction, TurtleSide side ) private TurtleCommandResult attack( ITurtleAccess turtle, Direction direction, TurtleSide side )
@ -255,7 +255,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
{ {
state.getBlock() state.getBlock()
.onBroken( world, blockPosition, state ); .onBroken( world, blockPosition, state );
if( turtlePlayer.isUsingEffectiveTool( state ) ) if( turtlePlayer.canHarvest( state ) )
{ {
state.getBlock() state.getBlock()
.afterBreak( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getMainHandStack() ); .afterBreak( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getMainHandStack() );

View File

@ -242,10 +242,10 @@ public class FakeNetHandler extends ServerPlayNetworkHandler
{ {
} }
@Override // @Override
public void onConfirmScreenAction( ConfirmScreenActionC2SPacket packet ) // public void onConfirmScreenAction( ConfirmScreenActionC2SPacket packet )
{ // {
} // }
@Override @Override
public void onSignUpdate( @Nonnull UpdateSignC2SPacket packet ) public void onSignUpdate( @Nonnull UpdateSignC2SPacket packet )

View File

@ -26,7 +26,7 @@ public final class FixedPointTileEntityType<T extends BlockEntity> extends Block
private FixedPointTileEntityType( Supplier<Block> block, Supplier<T> builder ) private FixedPointTileEntityType( Supplier<Block> block, Supplier<T> builder )
{ {
super( builder, Collections.emptySet(), null ); super( builder, Collections.emptySet(), null ); //FIXME: Replace with the new BlockEntity handlers.
this.block = block; this.block = block;
} }
@ -35,11 +35,11 @@ public final class FixedPointTileEntityType<T extends BlockEntity> extends Block
return new FixedPointSupplier<>( block, builder ).factory; return new FixedPointSupplier<>( block, builder ).factory;
} }
@Override // @Override
public boolean supports( @Nonnull Block block ) // public boolean supports( @Nonnull Block block )
{ // {
return block == this.block.get(); // return block == this.block.get();
} // }
private static final class FixedPointSupplier<T extends BlockEntity> implements Supplier<T> private static final class FixedPointSupplier<T extends BlockEntity> implements Supplier<T>
{ {

View File

@ -29,8 +29,8 @@ public final class ImpostorRecipe extends ShapedRecipe
{ {
String group = JsonHelper.getString( json, "group", "" ); String group = JsonHelper.getString( json, "group", "" );
ShapedRecipe recipe = RecipeSerializer.SHAPED.read( identifier, json ); ShapedRecipe recipe = RecipeSerializer.SHAPED.read( identifier, json );
ItemStack result = ShapedRecipe.getItemStack( JsonHelper.getObject( json, "result" ) ); ItemStack result = ShapedRecipe.outputFromJson( JsonHelper.getObject( json, "result" ) );
return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getPreviewInputs(), result ); return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getIngredients(), result );
} }
@Override @Override
@ -54,7 +54,7 @@ public final class ImpostorRecipe extends ShapedRecipe
buf.writeVarInt( recipe.getWidth() ); buf.writeVarInt( recipe.getWidth() );
buf.writeVarInt( recipe.getHeight() ); buf.writeVarInt( recipe.getHeight() );
buf.writeString( recipe.getGroup() ); buf.writeString( recipe.getGroup() );
for( Ingredient ingredient : recipe.getPreviewInputs() ) for( Ingredient ingredient : recipe.getIngredients() )
{ {
ingredient.write( buf ); ingredient.write( buf );
} }

View File

@ -42,7 +42,7 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe
throw new JsonParseException( "Too many ingredients for shapeless recipe the max is 9" ); throw new JsonParseException( "Too many ingredients for shapeless recipe the max is 9" );
} }
ItemStack itemstack = ShapedRecipe.getItemStack( JsonHelper.getObject( json, "result" ) ); ItemStack itemstack = ShapedRecipe.outputFromJson( JsonHelper.getObject( json, "result" ) );
return new ImpostorShapelessRecipe( id, s, itemstack, ingredients ); return new ImpostorShapelessRecipe( id, s, itemstack, ingredients );
} }
@ -81,10 +81,10 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe
public void write( @Nonnull PacketByteBuf buffer, @Nonnull ImpostorShapelessRecipe recipe ) public void write( @Nonnull PacketByteBuf buffer, @Nonnull ImpostorShapelessRecipe recipe )
{ {
buffer.writeString( recipe.getGroup() ); buffer.writeString( recipe.getGroup() );
buffer.writeVarInt( recipe.getPreviewInputs() buffer.writeVarInt( recipe.getIngredients()
.size() ); .size() );
for( Ingredient ingredient : recipe.getPreviewInputs() ) for( Ingredient ingredient : recipe.getIngredients() )
{ {
ingredient.write( buffer ); ingredient.write( buffer );
} }

View File

@ -49,7 +49,7 @@ public final class InventoryUtil
return ((InventoryProvider) block).getInventory( blockState, world, pos ); return ((InventoryProvider) block).getInventory( blockState, world, pos );
} }
// Check if block is BlockEntity w/ Inventory // Check if block is BlockEntity w/ Inventory
if( block.hasBlockEntity() ) if( blockState.hasBlockEntity() )
{ {
BlockEntity tileEntity = world.getBlockEntity( pos ); BlockEntity tileEntity = world.getBlockEntity( pos );

View File

@ -40,7 +40,7 @@ public final class NBTUtil
private NBTUtil() {} private NBTUtil() {}
private static Tag toNBTTag( Object object ) private static NbtElement toNBTTag( Object object )
{ {
if( object == null ) if( object == null )
{ {
@ -48,25 +48,25 @@ public final class NBTUtil
} }
if( object instanceof Boolean ) if( object instanceof Boolean )
{ {
return ByteTag.of( (byte) ((boolean) (Boolean) object ? 1 : 0) ); return NbtByte.of( (byte) ((boolean) (Boolean) object ? 1 : 0) );
} }
if( object instanceof Number ) if( object instanceof Number )
{ {
return DoubleTag.of( ((Number) object).doubleValue() ); return NbtDouble.of( ((Number) object).doubleValue() );
} }
if( object instanceof String ) if( object instanceof String )
{ {
return StringTag.of( object.toString() ); return NbtString.of( object.toString() );
} }
if( object instanceof Map ) if( object instanceof Map )
{ {
Map<?, ?> m = (Map<?, ?>) object; Map<?, ?> m = (Map<?, ?>) object;
CompoundTag nbt = new CompoundTag(); NbtCompound nbt = new NbtCompound();
int i = 0; int i = 0;
for( Map.Entry<?, ?> entry : m.entrySet() ) for( Map.Entry<?, ?> entry : m.entrySet() )
{ {
Tag key = toNBTTag( entry.getKey() ); NbtElement key = toNBTTag( entry.getKey() );
Tag value = toNBTTag( entry.getKey() ); NbtElement value = toNBTTag( entry.getKey() );
if( key != null && value != null ) if( key != null && value != null )
{ {
nbt.put( "k" + i, key ); nbt.put( "k" + i, key );
@ -81,18 +81,18 @@ public final class NBTUtil
return null; return null;
} }
public static CompoundTag encodeObjects( Object[] objects ) public static NbtCompound encodeObjects( Object[] objects )
{ {
if( objects == null || objects.length <= 0 ) if( objects == null || objects.length <= 0 )
{ {
return null; return null;
} }
CompoundTag nbt = new CompoundTag(); NbtCompound nbt = new NbtCompound();
nbt.putInt( "len", objects.length ); nbt.putInt( "len", objects.length );
for( int i = 0; i < objects.length; i++ ) for( int i = 0; i < objects.length; i++ )
{ {
Tag child = toNBTTag( objects[i] ); NbtElement child = toNBTTag( objects[i] );
if( child != null ) if( child != null )
{ {
nbt.put( Integer.toString( i ), child ); nbt.put( Integer.toString( i ), child );
@ -101,7 +101,7 @@ public final class NBTUtil
return nbt; return nbt;
} }
private static Object fromNBTTag( Tag tag ) private static Object fromNBTTag( NbtElement tag )
{ {
if( tag == null ) if( tag == null )
{ {
@ -110,14 +110,14 @@ public final class NBTUtil
switch( tag.getType() ) switch( tag.getType() )
{ {
case TAG_BYTE: case TAG_BYTE:
return ((ByteTag) tag).getByte() > 0; return ((NbtByte) tag).byteValue() > 0;
case TAG_DOUBLE: case TAG_DOUBLE:
return ((DoubleTag) tag).getDouble(); return ((NbtDouble) tag).doubleValue();
default: default:
case TAG_STRING: case TAG_STRING:
return tag.asString(); return tag.asString();
case TAG_COMPOUND: case TAG_COMPOUND:
CompoundTag c = (CompoundTag) tag; NbtCompound c = (NbtCompound) tag;
int len = c.getInt( "len" ); int len = c.getInt( "len" );
Map<Object, Object> map = new HashMap<>( len ); Map<Object, Object> map = new HashMap<>( len );
for( int i = 0; i < len; i++ ) for( int i = 0; i < len; i++ )
@ -133,7 +133,7 @@ public final class NBTUtil
} }
} }
public static Object toLua( Tag tag ) public static Object toLua( NbtElement tag )
{ {
if( tag == null ) if( tag == null )
{ {
@ -147,15 +147,15 @@ public final class NBTUtil
case TAG_SHORT: case TAG_SHORT:
case TAG_INT: case TAG_INT:
case TAG_LONG: case TAG_LONG:
return ((AbstractNumberTag) tag).getLong(); return ((AbstractNbtNumber) tag).longValue();
case TAG_FLOAT: case TAG_FLOAT:
case TAG_DOUBLE: case TAG_DOUBLE:
return ((AbstractNumberTag) tag).getDouble(); return ((AbstractNbtNumber) tag).doubleValue();
case TAG_STRING: // String case TAG_STRING: // String
return tag.asString(); return tag.asString();
case TAG_COMPOUND: // Compound case TAG_COMPOUND: // Compound
{ {
CompoundTag compound = (CompoundTag) tag; NbtCompound compound = (NbtCompound) tag;
Map<String, Object> map = new HashMap<>( compound.getSize() ); Map<String, Object> map = new HashMap<>( compound.getSize() );
for( String key : compound.getKeys() ) for( String key : compound.getKeys() )
{ {
@ -169,7 +169,7 @@ public final class NBTUtil
} }
case TAG_LIST: case TAG_LIST:
{ {
ListTag list = (ListTag) tag; NbtList list = (NbtList) tag;
Map<Integer, Object> map = new HashMap<>( list.size() ); Map<Integer, Object> map = new HashMap<>( list.size() );
for( int i = 0; i < list.size(); i++ ) for( int i = 0; i < list.size(); i++ )
{ {
@ -179,7 +179,7 @@ public final class NBTUtil
} }
case TAG_BYTE_ARRAY: case TAG_BYTE_ARRAY:
{ {
byte[] array = ((ByteArrayTag) tag).getByteArray(); byte[] array = ((NbtByteArray) tag).getByteArray();
Map<Integer, Byte> map = new HashMap<>( array.length ); Map<Integer, Byte> map = new HashMap<>( array.length );
for( int i = 0; i < array.length; i++ ) for( int i = 0; i < array.length; i++ )
{ {
@ -188,7 +188,7 @@ public final class NBTUtil
return map; return map;
} }
case TAG_INT_ARRAY: case TAG_INT_ARRAY:
int[] array = ((IntArrayTag) tag).getIntArray(); int[] array = ((NbtIntArray) tag).getIntArray();
Map<Integer, Integer> map = new HashMap<>( array.length ); Map<Integer, Integer> map = new HashMap<>( array.length );
for( int i = 0; i < array.length; i++ ) for( int i = 0; i < array.length; i++ )
{ {
@ -201,7 +201,7 @@ public final class NBTUtil
} }
} }
public static Object[] decodeObjects( CompoundTag tag ) public static Object[] decodeObjects( NbtCompound tag )
{ {
int len = tag.getInt( "len" ); int len = tag.getInt( "len" );
if( len <= 0 ) if( len <= 0 )
@ -222,7 +222,7 @@ public final class NBTUtil
} }
@Nullable @Nullable
public static String getNBTHash( @Nullable CompoundTag tag ) public static String getNBTHash( @Nullable NbtCompound tag )
{ {
if( tag == null ) if( tag == null )
{ {

View File

@ -6,7 +6,7 @@
package dan200.computercraft.shared.util; package dan200.computercraft.shared.util;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
public class Palette public class Palette
@ -83,7 +83,7 @@ public class Palette
} }
} }
public CompoundTag writeToNBT( CompoundTag nbt ) public NbtCompound writeToNBT( NbtCompound nbt )
{ {
int[] rgb8 = new int[colours.length]; int[] rgb8 = new int[colours.length];
@ -105,7 +105,7 @@ public class Palette
return (r << 16) | (g << 8) | b; return (r << 16) | (g << 8) | b;
} }
public void readFromNBT( CompoundTag nbt ) public void readFromNBT( NbtCompound nbt )
{ {
if( !nbt.contains( "term_palette" ) ) if( !nbt.contains( "term_palette" ) )
{ {

View File

@ -36,7 +36,7 @@ public final class WorldUtil
public static boolean isLiquidBlock( World world, BlockPos pos ) public static boolean isLiquidBlock( World world, BlockPos pos )
{ {
if( !World.isInBuildLimit( pos ) ) if( !world.isInBuildLimit( pos ) )
{ {
return false; return false;
} }

View File

@ -1,7 +1,7 @@
{ {
"required": true, "required": true,
"package": "dan200.computercraft.fabric.mixin", "package": "dan200.computercraft.fabric.mixin",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_16",
"mixins": [ "mixins": [
"MinecraftServerAccess", "MinecraftServerAccess",
"MixinBlock", "MixinBlock",

View File

@ -20,8 +20,10 @@
"Toad-Dev" "Toad-Dev"
], ],
"depends": { "depends": {
"fabricloader": ">=0.4.0", "fabricloader": ">=0.11.3",
"fabric": "*" "fabric": "*"
"minecraft": "1.17.x",
"java": ">=16",
}, },
"suggests": { "suggests": {
"modmenu": "*" "modmenu": "*"