1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-27 16:02:17 +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
run: git submodule update --init --recursive
- name: Set up Java 8
- name: Set up Java 16
uses: actions/setup-java@v1
with:
java-version: 8
java-version: 16
- name: Cache gradle dependencies
uses: actions/cache@v2

View File

@ -1,7 +1,7 @@
<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")
[![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)
# CC: R Version VS CC: T Version

View File

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

View File

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

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
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
zipStorePath=wrapper/dists

View File

@ -8,7 +8,7 @@ package dan200.computercraft.api;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.Identifier;
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
// null one.
CompoundTag shareTag = stack.getTag();
CompoundTag craftingShareTag = crafting.getTag();
NbtCompound shareTag = stack.getTag();
NbtCompound craftingShareTag = crafting.getTag();
if( shareTag == craftingShareTag ) return true;
if( shareTag == null ) return craftingShareTag.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.BakedModelManager;
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.item.ItemStack;

View File

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

View File

@ -53,7 +53,7 @@ public class FakePlayer extends ServerPlayerEntity
{
public FakePlayer( ServerWorld world, GameProfile gameProfile )
{
super( world.getServer(), world, gameProfile, new ServerPlayerInteractionManager( world ) );
super( world.getServer(), world, gameProfile );
networkHandler = new FakeNetHandler( this );
}
@ -128,7 +128,7 @@ public class FakePlayer extends ServerPlayerEntity
}
@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
public void onSlotUpdate( ScreenHandler container, int slot, ItemStack stack )
{
}
@Override
public void onHandlerRegistered( ScreenHandler container, DefaultedList<ItemStack> defaultedList )
{
}
@Override
public void onPropertyUpdate( ScreenHandler container, int key, int value )
{
}
// @Override
// public void onSlotUpdate( ScreenHandler container, int slot, ItemStack stack )
// {
// }
//
// @Override
// public void onHandlerRegistered( ScreenHandler container, DefaultedList<ItemStack> defaultedList )
// {
// }
//
// @Override
// public void onPropertyUpdate( ScreenHandler container, int key, int value )
// {
// }
@Override
public void closeHandledScreen()
{
}
@Override
public void updateCursorStack()
{
}
// @Override
// public void updateCursorStack()
// {
// }
@Override
public int unlockRecipes( Collection<Recipe<?>> recipes )
@ -191,17 +191,17 @@ public class FakePlayer extends ServerPlayerEntity
}
@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
protected void onStatusEffectApplied( StatusEffectInstance statusEffectInstance )
protected void onStatusEffectApplied( StatusEffectInstance statusEffectInstance, @Nullable Entity source )
{
}
@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
public void setGameMode( GameMode gameMode )
{
}
// @Override
// public void setGameMode( GameMode gameMode )
// {
// }
@Override
public void sendMessage( Text message, MessageType type, UUID senderUuid )
@ -232,15 +232,15 @@ public class FakePlayer extends ServerPlayerEntity
return "[Fake Player]";
}
@Override
public void sendResourcePackUrl( String url, String hash )
{
}
// @Override
// public void sendResourcePackUrl( String url, String hash )
// {
// }
@Override
public void onStoppedTracking( Entity entity )
{
}
// @Override
// public void onStoppedTracking( Entity entity )
// {
// }
@Override
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.shared.util.ItemStorage;
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.Direction;
import net.minecraft.util.math.Vec3d;
@ -255,7 +255,7 @@ public interface ITurtleAccess
* @see #updateUpgradeNBTData(TurtleSide)
*/
@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.

View File

@ -14,7 +14,7 @@ import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.MinecraftClient;
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.math.Matrix4f;
import org.lwjgl.opengl.GL11;
@ -23,7 +23,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
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_WIDTH = 6;
public static final float WIDTH = 256.0f;
@ -394,21 +394,21 @@ public final class FixedWidthFontRenderer
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
RenderLayer.MultiPhaseParameters.builder()
RenderLayer.MultiPhaseParameters.Builder()
.texture( new RenderPhase.Texture( FONT,
false,
false ) ) // blur, minimap
.alpha( ONE_TENTH_ALPHA )
.transparency( TRANSLUCENT_TRANSPARENCY )
.lightmap( DISABLE_LIGHTMAP )
.writeMaskState( COLOR_MASK )
.build( false ) );
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,
false,
false ) ) // blur, minimap
.alpha( ONE_TENTH_ALPHA )
.transparency( TRANSLUCENT_TRANSPARENCY )
.writeMaskState( ALL_MASK )
.lightmap( DISABLE_LIGHTMAP )
.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.MARGIN;
import java.util.List;
public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<T>
{
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 );
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 );
}
@ -109,7 +111,7 @@ public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
// Draw a border around the terminal
RenderSystem.color4f( 1, 1, 1, 1 );
RenderSystem.clearColor( 1, 1, 1, 1 );
client.getTextureManager()
.bindTexture( ComputerBorderRenderer.getTexture( family ) );
ComputerBorderRenderer.render( terminalWrapper.getX() - MARGIN, terminalWrapper.getY() - MARGIN,
@ -144,7 +146,7 @@ public class GuiComputer<T extends ContainerComputerBase> extends HandledScreen<
public void removed()
{
super.removed();
children.remove( terminal );
children().remove( terminal );
terminal = null;
client.keyboard.setRepeatEvents( false );
}

View File

@ -36,7 +36,7 @@ public class GuiDiskDrive extends HandledScreen<ContainerDiskDrive>
@Override
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()
.bindTexture( BACKGROUND );
drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight );

View File

@ -44,7 +44,7 @@ public class GuiPrinter extends HandledScreen<ContainerPrinter>
@Override
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()
.bindTexture( BACKGROUND );
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 )
{
// 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();
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance()

View File

@ -44,7 +44,7 @@ public class GuiTurtle extends GuiComputer<ContainerTurtle>
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
// 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()
.bindTexture( texture );
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.Tessellator;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f;
@ -84,11 +85,11 @@ public class ComputerBorderRenderer
{
Tessellator tessellator = Tessellator.getInstance();
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 );
RenderSystem.enableAlphaTest();
RenderSystem.enableDepthTest(); //TODO: enableAlphaTest(). FIXME
tessellator.draw();
}

View File

@ -13,12 +13,12 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3f;
@Environment( EnvType.CLIENT )
public abstract class ItemMapLikeRenderer
@ -75,18 +75,18 @@ public abstract class ItemMapLikeRenderer
HeldItemRendererAccess access = (HeldItemRendererAccess) renderer;
float pitchAngle = access.callGetMapAngle( pitch );
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() )
{
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.LEFT );
transform.pop();
}
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 );
renderItem( transform, render, stack );
@ -114,7 +114,7 @@ public abstract class ItemMapLikeRenderer
if( !minecraft.player.isInvisible() )
{
transform.push();
transform.multiply( Vector3f.POSITIVE_Z.getDegreesQuaternion( offset * 10f ) );
transform.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( offset * 10f ) );
((HeldItemRendererAccess) minecraft.getHeldItemRenderer())
.callRenderArmHoldingItem( transform, render, combinedLight, equipProgress, swingProgress, side );
transform.pop();
@ -130,8 +130,8 @@ public abstract class ItemMapLikeRenderer
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
transform.translate( offset * f3, f4 - 0.3f * f2, f5 );
transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( f2 * -45f ) );
transform.multiply( Vector3f.POSITIVE_Y.getDegreesQuaternion( offset * f2 * -30f ) );
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( f2 * -45f ) );
transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( offset * f2 * -30f ) );
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.Tessellator;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.Matrix4f;
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
// in ItemRenderer
transform.push();
transform.multiply( Vector3f.POSITIVE_Y.getDegreesQuaternion( 180f ) );
transform.multiply( Vector3f.POSITIVE_Z.getDegreesQuaternion( 180f ) );
transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( 180f ) );
transform.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( 180f ) );
transform.scale( 0.5f, 0.5f, 0.5f );
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();
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 );
@ -131,7 +132,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
Tessellator tessellator = Tessellator.getInstance();
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 )
.color( r, g, b, 1.0f )
.next();

View File

@ -9,7 +9,7 @@ package dan200.computercraft.client.render;
import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.client.render.VertexConsumerProvider;
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.util.math.Matrix4f;
@ -33,7 +33,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
@Override
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.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
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.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.VertexFormats;
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 java.util.List;
@ -66,7 +66,7 @@ public final class ModelTransformer
for( VertexFormatElement element : format.getElements() ) // For each vertex element
{
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] ),
Float.intBitsToFloat( vertexData[start + 1] ),
@ -81,7 +81,7 @@ public final class ModelTransformer
vertexData[start + 1] = Float.floatToRawIntBits( pos.getY() );
vertexData[start + 2] = Float.floatToRawIntBits( pos.getZ() );
}
offsetBytes += element.getSize();
offsetBytes += element.getLength();
}
}
return copy;

View File

@ -7,11 +7,11 @@ package dan200.computercraft.client.render;
import com.google.common.base.Strings;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.systems.RenderSystem;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.texture.TextureUtil;
import net.minecraft.util.math.Matrix4f;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL13;
@ -19,6 +19,7 @@ import org.lwjgl.opengl.GL20;
import java.io.InputStream;
import java.nio.FloatBuffer;
import java.util.List;
class MonitorTextureBufferShader
{
@ -42,7 +43,7 @@ class MonitorTextureBufferShader
static void setupUniform( Matrix4f transform, int width, int height, Palette palette, boolean greyscale )
{
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();
RenderSystem.glUniformMatrix4( uniformMv, false, MATRIX_BUFFER );
@ -77,7 +78,7 @@ class MonitorTextureBufferShader
{
if( ok )
{
GlStateManager.useProgram( program );
GlStateManager.glLinkProgram( program );
}
return ok;
}
@ -101,14 +102,15 @@ class MonitorTextureBufferShader
int vertexShader = loadShader( GL20.GL_VERTEX_SHADER, "assets/computercraft/shaders/monitor.vert" );
int fragmentShader = loadShader( GL20.GL_FRAGMENT_SHADER, "assets/computercraft/shaders/monitor.frag" );
program = GlStateManager.createProgram();
GlStateManager.attachShader( program, vertexShader );
GlStateManager.attachShader( program, fragmentShader );
program = GlStateManager.glCreateProgram();
GlStateManager.glAttachShader( program, vertexShader );
GlStateManager.glAttachShader( program, fragmentShader );
GL20.glBindAttribLocation( program, 0, "v_pos" );
GlStateManager.linkProgram( program );
boolean ok = GlStateManager.getProgram( program, GL20.GL_LINK_STATUS ) != 0;
String log = GlStateManager.getProgramInfoLog( program, Short.MAX_VALUE )
GlStateManager.glLinkProgram( program );
boolean ok = GlStateManager.glGetProgrami( program, GL20.GL_LINK_STATUS ) != 0;
String log = GlStateManager.glGetProgramInfoLog( program, Short.MAX_VALUE )
.trim();
if( !Strings.isNullOrEmpty( log ) )
{
@ -117,8 +119,8 @@ class MonitorTextureBufferShader
GL20.glDetachShader( program, vertexShader );
GL20.glDetachShader( program, fragmentShader );
GlStateManager.deleteShader( vertexShader );
GlStateManager.deleteShader( fragmentShader );
GlStateManager.glDeleteShader( vertexShader );
GlStateManager.glDeleteShader( fragmentShader );
if( !ok )
{
@ -150,15 +152,15 @@ class MonitorTextureBufferShader
{
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.compileShader( shader );
GlStateManager.glShaderSource( shader, contents );
GlStateManager.glCompileShader( shader );
boolean ok = GlStateManager.getShader( shader, GL20.GL_COMPILE_STATUS ) != 0;
String log = GlStateManager.getShaderInfoLog( shader, Short.MAX_VALUE )
boolean ok = GlStateManager.glGetShaderi( shader, GL20.GL_COMPILE_STATUS ) != 0;
String log = GlStateManager.glGetShaderInfoLog( shader, Short.MAX_VALUE )
.trim();
if( !Strings.isNullOrEmpty( log ) )
{
@ -174,7 +176,7 @@ class MonitorTextureBufferShader
private static int getUniformLocation( int program, String name )
{
int uniform = GlStateManager.getUniformLocation( program, name );
int uniform = GlStateManager._glGetUniformLocation( program, name );
if( uniform == -1 )
{
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.shared.util.Palette;
import net.minecraft.client.render.*;
import net.minecraft.client.render.VertexFormat.DrawMode;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f;
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;
public final class PrintoutRenderer
{
{ //FIXME Use BufferBuilders
/**
* Width of a page.
*/
@ -186,24 +187,22 @@ public final class PrintoutRenderer
.next();
}
private static final class Type extends RenderPhase
private static final class Type extends RenderLayer
{
static final RenderLayer TYPE = RenderLayer.of( "printout_background",
VertexFormats.POSITION_TEXTURE,
GL11.GL_QUADS,
VertexFormat.DrawMode.QUADS,
1024,
false,
false,
// useDelegate, needsSorting
RenderLayer.MultiPhaseParameters.builder()
.texture( new RenderPhase.Texture( BG, false, false ) ) // blur, minimap
.alpha( ONE_TENTH_ALPHA )
.transparency( TRANSLUCENT_TRANSPARENCY )
.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.BlockEntityRenderer;
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.Vector3f;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Matrix4f;
@ -37,8 +37,8 @@ import java.nio.ByteBuffer;
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.
*/
@ -89,8 +89,8 @@ public class TileEntityMonitorRenderer extends BlockEntityRenderer<TileMonitor>
originPos.getY() - monitorPos.getY() + 0.5,
originPos.getZ() - monitorPos.getZ() + 0.5 );
transform.multiply( Vector3f.NEGATIVE_Y.getDegreesQuaternion( yaw ) );
transform.multiply( Vector3f.POSITIVE_X.getDegreesQuaternion( pitch ) );
transform.multiply( Vec3f.NEGATIVE_Y.getDegreesQuaternion( yaw ) );
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( pitch ) );
transform.translate( -0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0,
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.util.ModelIdentifier;
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.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
@ -38,8 +38,8 @@ import javax.annotation.Nonnull;
import java.util.List;
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 ADVANCED_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_advanced", "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( 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" )) )
{
// Flip the model
@ -189,7 +189,7 @@ public class TileEntityTurtleRenderer extends BlockEntityRenderer<TileTurtle>
float toolAngle = turtle.getToolRenderAngle( side, f );
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 );
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.ModelTransformation;
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 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.entity.EntityRenderDispatcher;
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.util.Identifier;
import javax.annotation.Nonnull;
public class TurtlePlayerRenderer extends EntityRenderer<TurtlePlayer>
{
public TurtlePlayerRenderer( EntityRenderDispatcher renderManager )
{ //FIXME Make sure this isn't an issue. Context was EntityRenderDispatcher.
public TurtlePlayerRenderer( Context renderManager )
{
super( renderManager );
}
public TurtlePlayerRenderer( EntityRenderDispatcher entityRenderDispatcher, EntityRendererRegistry.Context context )
public TurtlePlayerRenderer( Context entityRenderDispatcher, EntityRendererRegistry.Context context )
{
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.texture.Sprite;
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.world.ClientWorld;
import net.minecraft.entity.LivingEntity;
@ -70,8 +70,7 @@ public class TurtleSmartItemModel implements BakedModel
{
@Nonnull
@Override
public BakedModel apply( @Nonnull BakedModel originalModel, @Nonnull ItemStack stack, @Nullable ClientWorld world,
@Nullable LivingEntity entity )
public BakedModel apply( BakedModel originalModel, ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity, int seed)
{
ItemTurtle turtle = (ItemTurtle) stack.getItem();
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.Resource;
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.InvalidIdentifierException;
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
* 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();
@ -324,7 +325,7 @@ public final class ResourceMount implements IMount
synchronized void add( ReloadableResourceManager manager, ResourceMount mount )
{
if( managers.add( manager ) ) manager.registerListener( this );
if( managers.add( manager ) ) manager.registerReloader( this );
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.Palette;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import javax.annotation.Nonnull;
@ -366,7 +366,7 @@ public class Terminal
setChanged();
}
public synchronized CompoundTag writeToNBT( CompoundTag nbt )
public synchronized NbtCompound writeToNBT( NbtCompound nbt )
{
nbt.putInt( "term_cursorX", cursorX );
nbt.putInt( "term_cursorY", cursorY );
@ -384,7 +384,7 @@ public class Terminal
return nbt;
}
public synchronized void readFromNBT( CompoundTag nbt )
public synchronized void readFromNBT( NbtCompound nbt )
{
cursorX = nbt.getInt( "term_cursorX" );
cursorY = nbt.getInt( "term_cursorY" );

View File

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

View File

@ -32,7 +32,7 @@ public class MixinWorld
@Inject( method = "setBlockEntity", at = @At( "HEAD" ) )
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 );
}
@ -42,7 +42,7 @@ public class MixinWorld
{
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 )
{
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 )
@ -43,7 +43,7 @@ public final class BundledRedstone
private static int getUnmaskedOutput( World world, BlockPos pos, Direction side )
{
if( !World.isInBuildLimit( pos ) )
if( !world.isInBuildLimit( pos ) )
{
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.upgrades.*;
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.screenhandler.v1.ScreenHandlerRegistry;
import net.minecraft.block.AbstractBlock;
@ -151,19 +152,19 @@ public final class ComputerCraftRegistry
public static final BlockEntityType<TileMonitor> MONITOR_NORMAL = ofBlock( () -> ModBlocks.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,
"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,
"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,
"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,
"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,
"turtle_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<TileWirelessModem> WIRELESS_MODEM_NORMAL = ofBlock( () -> ModBlocks.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,
"wireless_modem_advanced",
f -> new TileWirelessModem( f, true ) );
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,
new Identifier( MOD_ID, id ),
FixedPointTileEntityType.create( Objects.requireNonNull( block ), factory ) );
FabricBlockEntityTypeBuilder.create);
}
}

View File

@ -35,7 +35,7 @@ public final class Peripherals
@Nullable
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

View File

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

View File

@ -94,8 +94,8 @@ public abstract class BlockGeneric extends BlockWithEntity
@Nullable
@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.shared.network.client.TerminalState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
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" );
if( nbt.contains( "terminal" ) )
{
CompoundTag terminal = nbt.getCompound( "terminal" );
NbtCompound terminal = nbt.getCompound( "terminal" );
resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
this.terminal.readFromNBT( terminal );
}

View File

@ -7,7 +7,7 @@
package dan200.computercraft.shared.common;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
public interface IColouredItem
{
@ -20,7 +20,7 @@ public interface IColouredItem
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;
}
@ -35,7 +35,7 @@ public interface IColouredItem
{
if( colour == -1 )
{
CompoundTag tag = stack.getTag();
NbtCompound tag = stack.getTag();
if( tag != null )
{
tag.remove( NBT_COLOUR );

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import java.util.concurrent.atomic.AtomicBoolean;
@ -85,12 +85,12 @@ public class ServerTerminal implements ITerminal
return new TerminalState( colour, terminal );
}
public void writeDescription( CompoundTag nbt )
public void writeDescription( NbtCompound nbt )
{
nbt.putBoolean( "colour", colour );
if( terminal != null )
{
CompoundTag terminal = new CompoundTag();
NbtCompound terminal = new NbtCompound();
terminal.putInt( "term_width", this.terminal.getWidth() );
terminal.putInt( "term_height", this.terminal.getHeight() );
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.BlockEntityType;
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.Hand;
import net.minecraft.util.hit.BlockHitResult;
@ -21,9 +21,9 @@ import javax.annotation.Nonnull;
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()
@ -82,23 +82,23 @@ public abstract class TileGeneric extends BlockEntity implements BlockEntityClie
}
@Override
public void fromClientTag( CompoundTag compoundTag )
public void fromClientTag( NbtCompound compoundTag )
{
readDescription( compoundTag );
}
protected void readDescription( @Nonnull CompoundTag nbt )
protected void readDescription( @Nonnull NbtCompound nbt )
{
}
@Override
public CompoundTag toClientTag( CompoundTag compoundTag )
public NbtCompound toClientTag( NbtCompound compoundTag )
{
writeDescription( 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.BlockState;
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.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
@ -204,7 +204,7 @@ public class CommandAPI implements ILuaAPI
World world = computer.getWorld();
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 ) );
if( !World.isInBuildLimit( min ) || !World.isInBuildLimit( max ) )
if( !world.isInBuildLimit( min ) || !world.isInBuildLimit( max ) )
{
throw new LuaException( "Co-ordinates out of range" );
}
@ -252,7 +252,7 @@ public class CommandAPI implements ILuaAPI
BlockEntity tile = world.getBlockEntity( pos );
if( tile != null )
{
table.put( "nbt", NBTUtil.toLua( tile.toTag( new CompoundTag() ) ) );
table.put( "nbt", NBTUtil.toLua( tile.writeNbt( new NbtCompound() ) ) );
}
return table;
@ -289,7 +289,7 @@ public class CommandAPI implements ILuaAPI
// Get the details of the block
World world = computer.getWorld();
BlockPos position = new BlockPos( x, y, z );
if( World.isInBuildLimit( position ) )
if( world.isInBuildLimit( 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.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
@ -19,6 +20,7 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameRules;
@ -32,9 +34,9 @@ public class TileCommandComputer extends TileComputer
{
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();
}

View File

@ -17,6 +17,7 @@ import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import javax.annotation.Nonnull;
@ -26,9 +27,9 @@ public class TileComputer extends TileComputerBase
{
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 )

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

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared.computer.core;
import dan200.computercraft.shared.common.ClientTerminal;
import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.network.server.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
public class ClientComputer extends ClientTerminal implements IComputer
{
@ -17,7 +17,7 @@ public class ClientComputer extends ClientTerminal implements IComputer
private boolean on = false;
private boolean blinking = false;
private CompoundTag userData = null;
private NbtCompound userData = null;
public ClientComputer( int instanceID )
@ -26,7 +26,7 @@ public class ClientComputer extends ClientTerminal implements IComputer
this.instanceID = instanceID;
}
public CompoundTag getUserData()
public NbtCompound getUserData()
{
return userData;
}
@ -123,7 +123,7 @@ public class ClientComputer extends ClientTerminal implements IComputer
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;
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 me.shedaniel.cloth.api.utils.v1.GameInstanceUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
@ -42,7 +42,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
private final Computer computer;
private World world;
private BlockPos position;
private CompoundTag userData;
private NbtCompound userData;
private boolean changed;
private boolean changedLastFrame;
@ -128,11 +128,11 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
computer.unload();
}
public CompoundTag getUserData()
public NbtCompound getUserData()
{
if( userData == null )
{
userData = new CompoundTag();
userData = new NbtCompound();
}
return userData;
}

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.computer.items;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import javax.annotation.Nonnull;
@ -18,7 +18,7 @@ public interface IComputerItem
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;
}

View File

@ -45,7 +45,7 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe
ComputerFamily family = RecipeUtil.getFamily( json, "family" );
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 );
}
@ -78,7 +78,7 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe
buf.writeVarInt( recipe.getWidth() );
buf.writeVarInt( recipe.getHeight() );
buf.writeString( recipe.getGroup() );
for( Ingredient ingredient : recipe.getPreviewInputs() )
for( Ingredient ingredient : recipe.getIngredients() )
{
ingredient.write( buf );
}

View File

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

View File

@ -17,7 +17,7 @@ import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
@ -85,7 +85,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem
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;
}

View File

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

View File

@ -16,7 +16,7 @@ import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
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 )
{
ItemStack result = new ItemStack( ComputerCraftRegistry.ModItems.TREASURE_DISK );
CompoundTag nbt = result.getOrCreateTag();
NbtCompound nbt = result.getOrCreateTag();
nbt.putString( NBT_SUB_PATH, subPath );
int slash = subPath.indexOf( '/' );
@ -62,7 +62,7 @@ public class ItemTreasureDisk extends Item implements IMedia
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();
}
@ -84,7 +84,7 @@ public class ItemTreasureDisk extends Item implements IMedia
@Nonnull
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";
}
@ -128,7 +128,7 @@ public class ItemTreasureDisk extends Item implements IMedia
@Nonnull
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";
}
}

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.ServerComputer;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import javax.annotation.Nonnull;
@ -20,7 +20,7 @@ import javax.annotation.Nonnull;
public class ComputerDataClientMessage extends ComputerClientMessage
{
private ComputerState state;
private CompoundTag userData;
private NbtCompound userData;
public ComputerDataClientMessage( ServerComputer computer )
{
@ -38,7 +38,7 @@ public class ComputerDataClientMessage extends ComputerClientMessage
{
super.toBytes( buf );
buf.writeEnumConstant( state );
buf.writeCompoundTag( userData );
buf.writeNbt( userData );
}
@Override
@ -46,7 +46,7 @@ public class ComputerDataClientMessage extends ComputerClientMessage
{
super.fromBytes( buf );
state = buf.readEnumConstant( ComputerState.class );
userData = buf.readCompoundTag();
userData = buf.readNbt();
}
@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.ServerComputer;
import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import javax.annotation.Nonnull;
@ -42,7 +42,7 @@ public class QueueEventServerMessage extends ComputerServerMessage
{
super.toBytes( buf );
buf.writeString( event );
buf.writeCompoundTag( args == null ? null : NBTUtil.encodeObjects( args ) );
buf.writeNbt( args == null ? null : NBTUtil.encodeObjects( args ) );
}
@Override
@ -51,7 +51,7 @@ public class QueueEventServerMessage extends ComputerServerMessage
super.fromBytes( buf );
event = buf.readString( Short.MAX_VALUE );
CompoundTag args = buf.readCompoundTag();
NbtCompound args = buf.readNbt();
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.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.BlockState;
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.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
@ -50,6 +54,12 @@ public class BlockDiskDrive extends BlockGeneric
.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
public void afterBreak(
@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.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.sound.SoundEvent;
@ -32,10 +32,10 @@ import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Nameable;
import net.minecraft.util.Tickable;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -43,7 +43,7 @@ import java.util.HashMap;
import java.util.Map;
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_ITEM = "Item";
@ -57,9 +57,9 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private boolean restartRecord = false;
private boolean ejectQueued;
public TileDiskDrive( BlockEntityType<TileDiskDrive> type )
public TileDiskDrive( BlockEntityType<TileDiskDrive> type, BlockPos pos, BlockState state )
{
super( type );
super( type, pos, state );
}
@Override
@ -108,22 +108,23 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
}
@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;
if( nbt.contains( NBT_ITEM ) )
{
CompoundTag item = nbt.getCompound( NBT_ITEM );
diskStack = ItemStack.fromTag( item );
NbtCompound item = nbt.getCompound( NBT_ITEM );
diskStack = ItemStack.fromNbt( item );
diskMount = null;
}
}
@Nonnull
@Override
public CompoundTag toTag( @Nonnull CompoundTag nbt )
public NbtCompound writeNbt( @Nonnull NbtCompound nbt )
{
super.writeNbt( nbt );
if( customName != null )
{
nbt.putString( NBT_NAME, Text.Serializer.toJson( customName ) );
@ -131,11 +132,11 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
if( !diskStack.isEmpty() )
{
CompoundTag item = new CompoundTag();
diskStack.toTag( item );
NbtCompound item = new NbtCompound();
diskStack.writeNbt( item );
nbt.put( NBT_ITEM, item );
}
return super.toTag( nbt );
return nbt;
}
@Override
@ -148,40 +149,39 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
super.markDirty();
}
@Override
public void tick()
public static void tick( World world, BlockPos pos, BlockState state, TileDiskDrive tileDiskDrive)
{
// Ejection
if( ejectQueued )
if( tileDiskDrive.ejectQueued )
{
ejectContents( false );
ejectQueued = false;
tileDiskDrive.ejectContents( false );
tileDiskDrive.ejectQueued = false;
}
// Music
synchronized( this )
synchronized( tileDiskDrive )
{
if( !world.isClient && recordPlaying != recordQueued || restartRecord )
if( !world.isClient && tileDiskDrive.recordPlaying != tileDiskDrive.recordQueued || tileDiskDrive.restartRecord )
{
restartRecord = false;
if( recordQueued )
tileDiskDrive.restartRecord = false;
if( tileDiskDrive.recordQueued )
{
IMedia contents = getDiskMedia();
SoundEvent record = contents != null ? contents.getAudio( diskStack ) : null;
IMedia contents = tileDiskDrive.getDiskMedia();
SoundEvent record = contents != null ? contents.getAudio( tileDiskDrive.diskStack ) : null;
if( record != null )
{
recordPlaying = true;
playRecord();
tileDiskDrive.recordPlaying = true;
tileDiskDrive.playRecord();
}
else
{
recordQueued = false;
tileDiskDrive.recordQueued = false;
}
}
else
{
stopRecord();
recordPlaying = false;
tileDiskDrive.stopRecord();
tileDiskDrive.recordPlaying = false;
}
}
}
@ -479,7 +479,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
private synchronized void ejectContents( boolean destroyed )
{
if( getWorld().isClient || diskStack.isEmpty() )
if( this.world.isClient || diskStack.isEmpty() )
{
return;
}

View File

@ -12,12 +12,13 @@ import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtElement;
import net.minecraft.tag.ServerTagManagerHolder;
import net.minecraft.tag.TagGroup;
import net.minecraft.text.Text;
import net.minecraft.util.registry.Registry;
import javax.annotation.Nonnull;
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
// 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()
.filter( id -> Objects.requireNonNull( itemTags.getTag( id ) ).contains( stack.getItem() ) )
.collect( Collectors.toList() )
) ); // chaos x2
CompoundTag tag = stack.getTag();
NbtCompound tag = stack.getTag();
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 ) )
{
ListTag loreTag = displayTag.getList( "Lore", NBTUtil.TAG_STRING );
NbtList loreTag = displayTag.getList( "Lore", NBTUtil.TAG_STRING );
data.put( "lore", loreTag.stream()
.map( ItemData::parseTextComponent )
.filter( Objects::nonNull )
@ -112,7 +113,7 @@ public class ItemData
@Nullable
private static Text parseTextComponent( @Nonnull Tag x )
private static Text parseTextComponent( @Nonnull NbtElement x )
{
try
{
@ -138,7 +139,7 @@ public class ItemData
if( stack.getItem() instanceof EnchantedBookItem && (hideFlags & 32) == 0 )
{
addEnchantments( EnchantedBookItem.getEnchantmentTag( stack ), enchants );
addEnchantments( EnchantedBookItem.getEnchantmentNbt( stack ), enchants );
}
if( stack.hasEnchantments() && (hideFlags & 1) == 0 )
@ -161,14 +162,14 @@ public class ItemData
* @param enchants The enchantment map to add it to.
* @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;
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();
Integer level = entry.getValue();

View File

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

View File

@ -20,7 +20,7 @@ import dan200.computercraft.shared.util.TickScheduler;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
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.TranslatableText;
import net.minecraft.util.ActionResult;
@ -49,9 +49,9 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
private boolean destroyed = 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++ )
{
Direction facing = Direction.byId( i );
@ -315,9 +315,9 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
}
@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 );
for( int i = 0; i < peripherals.length; i++ )
{
@ -327,14 +327,15 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile
@Nonnull
@Override
public CompoundTag toTag( CompoundTag nbt )
public NbtCompound writeNbt( NbtCompound nbt )
{
super.writeNbt( nbt );
nbt.putBoolean( NBT_PERIPHERAL_ENABLED, peripheralAccessAllowed );
for( int i = 0; i < peripherals.length; i++ )
{
peripherals[i].write( nbt, Integer.toString( i ) );
}
return super.toTag( nbt );
return nbt;
}
@Override

View File

@ -12,7 +12,7 @@ import dan200.computercraft.shared.Peripherals;
import dan200.computercraft.shared.util.IDAssigner;
import dan200.computercraft.shared.util.NBTUtil;
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.Direction;
import net.minecraft.world.World;
@ -135,7 +135,7 @@ public final class WiredModemLocalPeripheral
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 )
{
@ -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;

View File

@ -29,9 +29,9 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile
private Direction modemDirection = Direction.DOWN;
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;
modem = new Peripheral( this );
}
@ -44,9 +44,10 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile
}
@Override
public void resetBlock()
public void setCachedState(BlockState state)
{
super.resetBlock();
super.setCachedState(state);
if(state != null) return;
hasModemDirection = false;
world.getBlockTickScheduler()
.schedule( getPos(),

View File

@ -48,7 +48,7 @@ public class BlockMonitor extends BlockGeneric
@Nullable
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;
if( pitch > 66.5f )
{

View File

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

View File

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

View File

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

View File

@ -10,11 +10,15 @@ import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.common.BlockGeneric;
import net.minecraft.block.Block;
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.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import javax.annotation.Nullable;
@ -43,4 +47,11 @@ public class BlockSpeaker extends BlockGeneric
{
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.IPeripheralTile;
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.util.Tickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
@ -19,22 +20,21 @@ import net.minecraft.world.World;
import javax.annotation.Nonnull;
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;
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 );
}
@Override
public void tick()
public static void tick( World world, BlockPos pos, BlockState state, TileSpeaker tileSpeaker )
{
peripheral.update();
tileSpeaker.peripheral.update();
}
@Nonnull

View File

@ -68,7 +68,7 @@ public class PocketAPI implements ILuaAPI
return new Object[] { false, "Cannot find player" };
}
PlayerEntity player = (PlayerEntity) entity;
PlayerInventory inventory = player.inventory;
PlayerInventory inventory = player.getInventory();
IPocketUpgrade previousUpgrade = computer.getUpgrade();
// 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" };
}
PlayerEntity player = (PlayerEntity) entity;
PlayerInventory inventory = player.inventory;
PlayerInventory inventory = player.getInventory();
IPocketUpgrade previousUpgrade = computer.getUpgrade();
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.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
@ -57,7 +57,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
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;
}
else if( entity instanceof LivingEntity )
@ -87,14 +87,14 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
@Override
public int getLight()
{
CompoundTag tag = getUserData();
NbtCompound tag = getUserData();
return tag.contains( NBT_LIGHT, NBTUtil.TAG_ANY_NUMERIC ) ? tag.getInt( NBT_LIGHT ) : -1;
}
@Override
public void setLight( int colour )
{
CompoundTag tag = getUserData();
NbtCompound tag = getUserData();
if( colour >= 0 && colour <= 0xFFFFFF )
{
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
@Override
public CompoundTag getUpgradeNBTData()
public NbtCompound getUpgradeNBTData()
{
return ItemPocketComputer.getUpgradeInfo( stack );
}
@ -122,7 +122,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces
{
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.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
@ -92,7 +92,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
ClientComputer computer = getClientComputer( stack );
if( computer != null && computer.isOn() )
{
CompoundTag computerNBT = computer.getUserData();
NbtCompound computerNBT = computer.getUserData();
if( computerNBT != null && computerNBT.contains( 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 )
{
CompoundTag compound = stack.getOrCreateTag();
NbtCompound compound = stack.getOrCreateTag();
if( upgrade == null )
{
@ -119,7 +119,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
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 );
}
@ -147,7 +147,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
ItemStack stack = player.getStackInHand( hand );
if( !world.isClient )
{
PocketServerComputer computer = createServerComputer( world, player.inventory, player, stack );
PocketServerComputer computer = createServerComputer( world, player.getInventory(), player, stack );
boolean stop = false;
if( computer != null )
@ -177,7 +177,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
if( !world.isClient )
{
// 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 );
if( computer != null )
{
@ -341,7 +341,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
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;
}
@ -402,13 +402,13 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I
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;
}
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;
}

View File

@ -7,14 +7,18 @@
package dan200.computercraft.shared.turtle.blocks;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.ComputerCraftRegistry;
import dan200.computercraft.shared.computer.blocks.BlockComputerBase;
import dan200.computercraft.shared.computer.blocks.TileComputerBase;
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.items.ITurtleItem;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import net.minecraft.block.*;
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.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.ComputerState;
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.core.TurtleBrain;
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.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.ActionResult;
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.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -57,9 +59,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
private TurtleBrain brain = new TurtleBrain( this );
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
@ -233,7 +235,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
if( !player.isCreative() )
{
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 void tick()
public static void tick( World world, BlockPos pos, BlockState state, TileTurtle tileTurtle)
{
super.tick();
brain.update();
if( !getWorld().isClient && inventoryChanged )
tileTurtle.brain.update();
if( !tileTurtle.getWorld().isClient && tileTurtle.inventoryChanged )
{
ServerComputer computer = getServerComputer();
ServerComputer computer = tileTurtle.getServerComputer();
if( computer != null )
{
computer.queueEvent( "turtle_inventory" );
}
inventoryChanged = false;
for( int n = 0; n < size(); n++ )
tileTurtle.inventoryChanged = false;
for( int n = 0; n < tileTurtle.size(); n++ )
{
previousInventory.set( n,
getStack( n ).copy() );
tileTurtle.previousInventory.set( n,
tileTurtle.getStack( n ).copy() );
}
}
}
@ -292,19 +292,19 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
@Nonnull
@Override
public CompoundTag toTag( @Nonnull CompoundTag nbt )
public NbtCompound writeNbt( @Nonnull NbtCompound nbt )
{
super.readNbt( nbt );
// Write inventory
ListTag nbttaglist = new ListTag();
NbtList nbttaglist = new NbtList();
for( int i = 0; i < INVENTORY_SIZE; i++ )
{
if( !inventory.get( i )
.isEmpty() )
{
CompoundTag tag = new CompoundTag();
NbtCompound tag = new NbtCompound();
tag.putByte( "Slot", (byte) i );
inventory.get( i )
.toTag( tag );
inventory.get( i ).writeNbt( tag );
nbttaglist.add( tag );
}
}
@ -313,27 +313,27 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
// Write brain
nbt = brain.writeToNBT( nbt );
return super.toTag( nbt );
return nbt;
}
// IDirectionalTile
@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
ListTag nbttaglist = nbt.getList( "Items", NBTUtil.TAG_COMPOUND );
NbtList nbttaglist = nbt.getList( "Items", NBTUtil.TAG_COMPOUND );
inventory.clear();
previousInventory.clear();
for( int i = 0; i < nbttaglist.size(); i++ )
{
CompoundTag tag = nbttaglist.getCompound( i );
NbtCompound tag = nbttaglist.getCompound( i );
int slot = tag.getByte( "Slot" ) & 0xff;
if( slot < size() )
{
inventory.set( slot, ItemStack.fromTag( tag ) );
inventory.set( slot, ItemStack.fromNbt( tag ) );
previousInventory.set( slot, inventory.get( slot )
.copy() );
}
@ -372,14 +372,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default
}
@Override
protected void writeDescription( @Nonnull CompoundTag nbt )
protected void writeDescription( @Nonnull NbtCompound nbt )
{
super.writeDescription( nbt );
brain.writeDescription( nbt );
}
@Override
protected void readDescription( @Nonnull CompoundTag nbt )
protected void readDescription( @Nonnull NbtCompound nbt )
{
super.readDescription( nbt );
brain.readDescription( nbt );

View File

@ -27,7 +27,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType;
import net.minecraft.fluid.FluidState;
import net.minecraft.inventory.Inventory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.tag.FluidTags;
@ -62,7 +62,7 @@ public class TurtleBrain implements ITurtleAccess
private final Queue<TurtleCommandQueueEntry> commandQueue = new ArrayDeque<>();
private final Map<TurtleSide, ITurtleUpgrade> upgrades = 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;
private TileTurtle 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
TileTurtle newTurtle = (TileTurtle) newTile;
newTurtle.setLocation( world, pos );
newTurtle.setLocation( world, pos ); //FIXME: setLocation no longer exists.
newTurtle.transferStateFrom( oldOwner );
newTurtle.createServerComputer()
.setWorld( world );
@ -543,12 +543,12 @@ public class TurtleBrain implements ITurtleAccess
@Nonnull
@Override
public CompoundTag getUpgradeNBTData( TurtleSide side )
public NbtCompound getUpgradeNBTData( TurtleSide side )
{
CompoundTag nbt = upgradeNBTData.get( side );
NbtCompound nbt = upgradeNBTData.get( side );
if( nbt == null )
{
upgradeNBTData.put( side, nbt = new CompoundTag() );
upgradeNBTData.put( side, nbt = new NbtCompound() );
}
return nbt;
}
@ -800,7 +800,7 @@ public class TurtleBrain implements ITurtleAccess
return previous + (next - previous) * f;
}
public void readFromNBT( CompoundTag nbt )
public void readFromNBT( NbtCompound nbt )
{
readCommon( nbt );
@ -810,7 +810,7 @@ public class TurtleBrain implements ITurtleAccess
// Read owner
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" ) );
}
else
@ -824,7 +824,7 @@ public class TurtleBrain implements ITurtleAccess
*
* @param nbt The tag to read from
*/
private void readCommon( CompoundTag nbt )
private void readCommon( NbtCompound nbt )
{
// Read fields
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 );
@ -861,7 +861,7 @@ public class TurtleBrain implements ITurtleAccess
// Write owner
if( owningPlayer != null )
{
CompoundTag owner = new CompoundTag();
NbtCompound owner = new NbtCompound();
nbt.put( "Owner", owner );
owner.putLong( "UpperId", owningPlayer.getId()
@ -874,7 +874,7 @@ public class TurtleBrain implements ITurtleAccess
return nbt;
}
private void writeCommon( CompoundTag nbt )
private void writeCommon( NbtCompound nbt )
{
nbt.putInt( NBT_FUEL, fuelLevel );
if( colourHex != -1 )
@ -917,7 +917,7 @@ public class TurtleBrain implements ITurtleAccess
.toString() : null;
}
public void readDescription( CompoundTag nbt )
public void readDescription( NbtCompound nbt )
{
readCommon( nbt );
@ -931,7 +931,7 @@ public class TurtleBrain implements ITurtleAccess
}
}
public void writeDescription( CompoundTag nbt )
public void writeDescription( NbtCompound nbt )
{
writeCommon( nbt );
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 )
{
if( World.isOutOfBuildLimitVertically( position ) )
if( world.isOutOfHeightLimit( position ) )
{
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" );
}

View File

@ -193,24 +193,24 @@ public class TurtlePlaceCommand implements ITurtleCommand
if( direction.getAxis() != Direction.Axis.Y )
{
turtlePlayer.yaw = direction.asRotation();
turtlePlayer.pitch = 0.0f;
turtlePlayer.setYaw(direction.asRotation());
turtlePlayer.setPitch(0.0f);
}
else
{
turtlePlayer.yaw = turtle.getDirection()
.asRotation();
turtlePlayer.pitch = DirectionUtil.toPitchAngle( direction );
turtlePlayer.setYaw(turtle.getDirection()
.asRotation());
turtlePlayer.setPitch(DirectionUtil.toPitchAngle( direction ));
}
turtlePlayer.setPos( posX, posY, posZ );
turtlePlayer.prevX = posX;
turtlePlayer.prevY = posY;
turtlePlayer.prevZ = posZ;
turtlePlayer.prevPitch = turtlePlayer.pitch;
turtlePlayer.prevYaw = turtlePlayer.yaw;
turtlePlayer.prevPitch = turtlePlayer.getPitch();
turtlePlayer.prevYaw = turtlePlayer.getYaw();
turtlePlayer.headYaw = turtlePlayer.yaw;
turtlePlayer.headYaw = turtlePlayer.getYaw();
turtlePlayer.prevHeadYaw = turtlePlayer.headYaw;
}
@ -403,7 +403,7 @@ public class TurtlePlaceCommand implements ITurtleCommand
Direction side, boolean allowReplaceable, String[] outErrorMessage )
{
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,
position )) )
{

View File

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

View File

@ -135,7 +135,7 @@ public class TurtleSuckCommand implements ITurtleCommand
{
if( remainder.isEmpty() && leaveStack.isEmpty() )
{
entity.remove();
entity.discard();
}
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 net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
@ -148,7 +148,7 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
@Override
public ITurtleUpgrade getUpgrade( @Nonnull ItemStack stack, @Nonnull TurtleSide side )
{
CompoundTag tag = stack.getTag();
NbtCompound tag = stack.getTag();
if( tag == null )
{
return null;
@ -161,14 +161,14 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem
@Override
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;
}
@Override
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;
}

View File

@ -117,7 +117,7 @@ public class TurtleInventoryCrafting extends CraftingInventory
results.add( result );
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++ )
{

View File

@ -15,7 +15,7 @@ import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeriph
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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.math.BlockPos;
import net.minecraft.util.math.Direction;
@ -67,7 +67,7 @@ public class TurtleModem extends AbstractTurtleUpgrade
boolean active = false;
if( turtle != null )
{
CompoundTag turtleNBT = turtle.getUpgradeNBTData( side );
NbtCompound turtleNBT = turtle.getUpgradeNBTData( side );
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.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.util.math.AffineTransformation;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.math.AffineTransformation;
import net.minecraft.util.math.Vec3f;
import net.minecraft.entity.Entity;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
@ -76,7 +76,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
@Override
public boolean isItemSuitable( @Nonnull ItemStack stack )
{
CompoundTag tag = stack.getTag();
NbtCompound tag = stack.getTag();
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
@ -107,7 +107,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{
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 )
@ -255,7 +255,7 @@ public class TurtleTool extends AbstractTurtleUpgrade
{
state.getBlock()
.onBroken( world, blockPosition, state );
if( turtlePlayer.isUsingEffectiveTool( state ) )
if( turtlePlayer.canHarvest( state ) )
{
state.getBlock()
.afterBreak( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getMainHandStack() );

View File

@ -242,10 +242,10 @@ public class FakeNetHandler extends ServerPlayNetworkHandler
{
}
@Override
public void onConfirmScreenAction( ConfirmScreenActionC2SPacket packet )
{
}
// @Override
// public void onConfirmScreenAction( ConfirmScreenActionC2SPacket packet )
// {
// }
@Override
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 )
{
super( builder, Collections.emptySet(), null );
super( builder, Collections.emptySet(), null ); //FIXME: Replace with the new BlockEntity handlers.
this.block = block;
}
@ -35,11 +35,11 @@ public final class FixedPointTileEntityType<T extends BlockEntity> extends Block
return new FixedPointSupplier<>( block, builder ).factory;
}
@Override
public boolean supports( @Nonnull Block block )
{
return block == this.block.get();
}
// @Override
// public boolean supports( @Nonnull Block block )
// {
// return block == this.block.get();
// }
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", "" );
ShapedRecipe recipe = RecipeSerializer.SHAPED.read( identifier, json );
ItemStack result = ShapedRecipe.getItemStack( JsonHelper.getObject( json, "result" ) );
return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getPreviewInputs(), result );
ItemStack result = ShapedRecipe.outputFromJson( JsonHelper.getObject( json, "result" ) );
return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getIngredients(), result );
}
@Override
@ -54,7 +54,7 @@ public final class ImpostorRecipe extends ShapedRecipe
buf.writeVarInt( recipe.getWidth() );
buf.writeVarInt( recipe.getHeight() );
buf.writeString( recipe.getGroup() );
for( Ingredient ingredient : recipe.getPreviewInputs() )
for( Ingredient ingredient : recipe.getIngredients() )
{
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" );
}
ItemStack itemstack = ShapedRecipe.getItemStack( JsonHelper.getObject( json, "result" ) );
ItemStack itemstack = ShapedRecipe.outputFromJson( JsonHelper.getObject( json, "result" ) );
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 )
{
buffer.writeString( recipe.getGroup() );
buffer.writeVarInt( recipe.getPreviewInputs()
buffer.writeVarInt( recipe.getIngredients()
.size() );
for( Ingredient ingredient : recipe.getPreviewInputs() )
for( Ingredient ingredient : recipe.getIngredients() )
{
ingredient.write( buffer );
}

View File

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

View File

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

View File

@ -6,7 +6,7 @@
package dan200.computercraft.shared.util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
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];
@ -105,7 +105,7 @@ public class Palette
return (r << 16) | (g << 8) | b;
}
public void readFromNBT( CompoundTag nbt )
public void readFromNBT( NbtCompound nbt )
{
if( !nbt.contains( "term_palette" ) )
{

View File

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

View File

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

View File

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