diff --git a/build.gradle b/build.gradle index e22fdfdc3..559e9b54c 100644 --- a/build.gradle +++ b/build.gradle @@ -75,7 +75,7 @@ minecraft { } } - mappings channel: 'snapshot', version: "${mappings_version}".toString() + mappings channel: 'official', version: project.mc_version accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg') } diff --git a/gradle.properties b/gradle.properties index 7ab23e64e..f9ef4fecd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,3 @@ mod_version=1.95.1 # Minecraft properties (update mods.toml when changing) mc_version=1.15.2 forge_version=31.1.41 -mappings_version=20200429-1.15.1 diff --git a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java index 6b6db770a..116b3135b 100644 --- a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java +++ b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java @@ -54,7 +54,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI public static InputStream getResourceFile( String domain, String subPath ) { - IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager(); + IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResources(); try { return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream(); @@ -97,7 +97,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI @Override public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath ) { - IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager(); + IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResources(); ResourceMount mount = ResourceMount.get( domain, subPath, manager ); return mount.exists( "" ) ? mount : null; } @@ -162,7 +162,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI @Override public LazyOptional getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); return tile == null ? LazyOptional.empty() : tile.getCapability( CAPABILITY_WIRED_ELEMENT, side ); } } diff --git a/src/main/java/dan200/computercraft/api/client/TransformedModel.java b/src/main/java/dan200/computercraft/api/client/TransformedModel.java index 40b2281fd..a130d27a8 100644 --- a/src/main/java/dan200/computercraft/api/client/TransformedModel.java +++ b/src/main/java/dan200/computercraft/api/client/TransformedModel.java @@ -43,7 +43,7 @@ public final class TransformedModel public static TransformedModel of( @Nonnull ItemStack item, @Nonnull TransformationMatrix transform ) { - IBakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getItemModel( item ); + IBakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getItemModel( item ); return new TransformedModel( model, transform ); } diff --git a/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java b/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java index 75f64d2a0..6578245cc 100644 --- a/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java +++ b/src/main/java/dan200/computercraft/api/pocket/AbstractPocketUpgrade.java @@ -35,7 +35,7 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade protected AbstractPocketUpgrade( ResourceLocation id, NonNullSupplier item ) { - this( id, Util.makeTranslationKey( "upgrade", id ) + ".adjective", item ); + this( id, Util.makeDescriptionId( "upgrade", id ) + ".adjective", item ); } protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemStack stack ) diff --git a/src/main/java/dan200/computercraft/api/turtle/AbstractTurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/AbstractTurtleUpgrade.java index 2aa7af918..72490953a 100644 --- a/src/main/java/dan200/computercraft/api/turtle/AbstractTurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/AbstractTurtleUpgrade.java @@ -37,7 +37,7 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, NonNullSupplier stack ) { - this( id, type, Util.makeTranslationKey( "upgrade", id ) + ".adjective", stack ); + this( id, type, Util.makeDescriptionId( "upgrade", id ) + ".adjective", stack ); } protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemStack stack ) diff --git a/src/main/java/dan200/computercraft/client/ClientRegistry.java b/src/main/java/dan200/computercraft/client/ClientRegistry.java index 381dc91ce..00bc4ea0c 100644 --- a/src/main/java/dan200/computercraft/client/ClientRegistry.java +++ b/src/main/java/dan200/computercraft/client/ClientRegistry.java @@ -78,7 +78,7 @@ public final class ClientRegistry @SubscribeEvent public static void onTextureStitchEvent( TextureStitchEvent.Pre event ) { - if( !event.getMap().getTextureLocation().equals( PlayerContainer.LOCATION_BLOCKS_TEXTURE ) ) return; + if( !event.getMap().location().equals( PlayerContainer.BLOCK_ATLAS ) ) return; for( String extra : EXTRA_TEXTURES ) { @@ -96,10 +96,10 @@ public final class ClientRegistry for( String modelName : EXTRA_MODELS ) { ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, "item/" + modelName ); - IUnbakedModel model = loader.getUnbakedModel( location ); - model.getTextures( loader::getUnbakedModel, new HashSet<>() ); + IUnbakedModel model = loader.getModel( location ); + model.getMaterials( loader::getModel, new HashSet<>() ); - IBakedModel baked = model.bakeModel( loader, ModelLoader.defaultTextureGetter(), SimpleModelTransform.IDENTITY, location ); + IBakedModel baked = model.bake( loader, ModelLoader.defaultTextureGetter(), SimpleModelTransform.IDENTITY, location ); if( baked != null ) { registry.put( new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, modelName ), "inventory" ), baked ); diff --git a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java index 689ce251a..164c0f70e 100644 --- a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java +++ b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java @@ -29,7 +29,7 @@ public class ClientTableFormatter implements TableFormatter private static FontRenderer renderer() { - return Minecraft.getInstance().fontRenderer; + return Minecraft.getInstance().font; } @Override @@ -41,7 +41,7 @@ public class ClientTableFormatter implements TableFormatter FontRenderer renderer = renderer(); - float spaceWidth = renderer.getStringWidth( " " ); + float spaceWidth = renderer.width( " " ); int spaces = MathHelper.floor( extraWidth / spaceWidth ); int extra = extraWidth - (int) (spaces * spaceWidth); @@ -57,32 +57,32 @@ public class ClientTableFormatter implements TableFormatter @Override public int getWidth( ITextComponent component ) { - return renderer().getStringWidth( component.getFormattedText() ); + return renderer().width( component.getColoredString() ); } @Override public void writeLine( int id, ITextComponent component ) { Minecraft mc = Minecraft.getInstance(); - NewChatGui chat = mc.ingameGUI.getChatGUI(); + NewChatGui chat = mc.gui.getChat(); // Trim the text if it goes over the allowed length - int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() ); - List list = RenderComponentsUtil.splitText( component, maxWidth, mc.fontRenderer, false, false ); - if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id ); + int maxWidth = MathHelper.floor( chat.getWidth() / chat.getScale() ); + List list = RenderComponentsUtil.wrapComponents( component, maxWidth, mc.font, false, false ); + if( !list.isEmpty() ) chat.addMessage( list.get( 0 ), id ); } @Override public int display( TableBuilder table ) { - NewChatGui chat = Minecraft.getInstance().ingameGUI.getChatGUI(); + NewChatGui chat = Minecraft.getInstance().gui.getChat(); int lastHeight = lastHeights.get( table.getId() ); int height = TableFormatter.super.display( table ); lastHeights.put( table.getId(), height ); - for( int i = height; i < lastHeight; i++ ) chat.deleteChatLine( i + table.getId() ); + for( int i = height; i < lastHeight; i++ ) chat.removeById( i + table.getId() ); return height; } } diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 7ea6a4ad0..05444fd5b 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -62,22 +62,22 @@ public final class FixedWidthFontRenderer int xStart = 1 + column * (FONT_WIDTH + 2); int yStart = 1 + row * (FONT_HEIGHT + 2); - buffer.pos( transform, x, y, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, yStart / WIDTH ).endVertex(); - buffer.pos( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); - buffer.pos( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex(); - buffer.pos( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex(); - buffer.pos( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); - buffer.pos( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); + buffer.vertex( transform, x, y, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, yStart / WIDTH ).endVertex(); + buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); + buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex(); + buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex(); + buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); + buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex(); } private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, float r, float g, float b ) { - buffer.pos( transform, x, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_START ).endVertex(); - buffer.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex(); - buffer.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex(); - buffer.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex(); - buffer.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex(); - buffer.pos( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_END ).endVertex(); + buffer.vertex( transform, x, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_START ).endVertex(); + buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_END ).endVertex(); + buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_START ).endVertex(); + buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_START ).endVertex(); + buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_END ).endVertex(); + buffer.vertex( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_END ).endVertex(); } private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex ) @@ -178,9 +178,9 @@ public final class FixedWidthFontRenderer { bindFont(); - IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); + IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource(); drawString( IDENTITY, ((IRenderTypeBuffer) renderer).getBuffer( TYPE ), x, y, text, textColour, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize ); - renderer.finish(); + renderer.endBatch(); } public static void drawTerminalWithoutCursor( @@ -263,10 +263,10 @@ public final class FixedWidthFontRenderer { bindFont(); - IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); + IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource(); IVertexBuilder buffer = renderer.getBuffer( TYPE ); drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize ); - renderer.finish( TYPE ); + renderer.endBatch( TYPE ); } public static void drawTerminal( @@ -287,9 +287,9 @@ public final class FixedWidthFontRenderer { bindFont(); - IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); + IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource(); drawEmptyTerminal( transform, renderer, x, y, width, height ); - renderer.finish(); + renderer.endBatch(); } public static void drawEmptyTerminal( float x, float y, float width, float height ) @@ -305,7 +305,7 @@ public final class FixedWidthFontRenderer private static void bindFont() { - Minecraft.getInstance().getTextureManager().bindTexture( FONT ); + Minecraft.getInstance().getTextureManager().bind( FONT ); RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP ); } @@ -315,26 +315,26 @@ public final class FixedWidthFontRenderer private static final VertexFormat FORMAT = DefaultVertexFormats.POSITION_COLOR_TEX; - static final RenderType MAIN = RenderType.makeType( + static final RenderType MAIN = RenderType.create( "terminal_font", FORMAT, GL_MODE, 1024, false, false, // useDelegate, needsSorting - RenderType.State.getBuilder() - .texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap - .alpha( DEFAULT_ALPHA ) - .lightmap( LIGHTMAP_DISABLED ) - .writeMask( COLOR_WRITE ) - .build( false ) + RenderType.State.builder() + .setTextureState( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap + .setAlphaState( DEFAULT_ALPHA ) + .setLightmapState( NO_LIGHTMAP ) + .setWriteMaskState( COLOR_WRITE ) + .createCompositeState( false ) ); - static final RenderType BLOCKER = RenderType.makeType( + static final RenderType BLOCKER = RenderType.create( "terminal_blocker", FORMAT, GL_MODE, 256, false, false, // useDelegate, needsSorting - RenderType.State.getBuilder() - .texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap - .alpha( DEFAULT_ALPHA ) - .writeMask( DEPTH_WRITE ) - .lightmap( LIGHTMAP_DISABLED ) - .build( false ) + RenderType.State.builder() + .setTextureState( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap + .setAlphaState( DEFAULT_ALPHA ) + .setWriteMaskState( DEPTH_WRITE ) + .setLightmapState( NO_LIGHTMAP ) + .createCompositeState( false ) ); private Type( String name, Runnable setup, Runnable destroy ) diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index ad3a3cc24..4996be560 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -74,18 +74,18 @@ public final class GuiComputer extends Containe @Override protected void init() { - minecraft.keyboardListener.enableRepeatEvents( true ); + minecraft.keyboardHandler.setSendRepeatsToGui( true ); int termPxWidth = termWidth * FixedWidthFontRenderer.FONT_WIDTH; int termPxHeight = termHeight * FixedWidthFontRenderer.FONT_HEIGHT; - xSize = termPxWidth + MARGIN * 2 + BORDER * 2; - ySize = termPxHeight + MARGIN * 2 + BORDER * 2; + imageWidth = termPxWidth + MARGIN * 2 + BORDER * 2; + imageHeight = termPxHeight + MARGIN * 2 + BORDER * 2; super.init(); terminal = new WidgetTerminal( minecraft, () -> computer, termWidth, termHeight, MARGIN, MARGIN, MARGIN, MARGIN ); - terminalWrapper = new WidgetWrapper( terminal, MARGIN + BORDER + guiLeft, MARGIN + BORDER + guiTop, termPxWidth, termPxHeight ); + terminalWrapper = new WidgetWrapper( terminal, MARGIN + BORDER + leftPos, MARGIN + BORDER + topPos, termPxWidth, termPxHeight ); children.add( terminalWrapper ); setFocused( terminalWrapper ); @@ -97,7 +97,7 @@ public final class GuiComputer extends Containe super.removed(); children.remove( terminal ); terminal = null; - minecraft.keyboardListener.enableRepeatEvents( false ); + minecraft.keyboardHandler.setSendRepeatsToGui( false ); } @Override @@ -120,14 +120,14 @@ public final class GuiComputer extends Containe } @Override - public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) + public void renderBg( float partialTicks, int mouseX, int mouseY ) { // Draw terminal terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() ); // Draw a border around the terminal RenderSystem.color4f( 1, 1, 1, 1 ); - minecraft.getTextureManager().bindTexture( ComputerBorderRenderer.getTexture( family ) ); + minecraft.getTextureManager().bind( ComputerBorderRenderer.getTexture( family ) ); ComputerBorderRenderer.render( terminalWrapper.getX() - MARGIN, terminalWrapper.getY() - MARGIN, getBlitOffset(), terminalWrapper.getWidth() + MARGIN * 2, terminalWrapper.getHeight() + MARGIN * 2 @@ -139,7 +139,7 @@ public final class GuiComputer extends Containe { renderBackground(); super.render( mouseX, mouseY, partialTicks ); - renderHoveredToolTip( mouseX, mouseY ); + renderTooltip( mouseX, mouseY ); } @Override diff --git a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java index f521d07d3..6b724a34a 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java @@ -22,19 +22,19 @@ public class GuiDiskDrive extends ContainerScreen } @Override - protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) + protected void renderLabels( int mouseX, int mouseY ) { - String title = this.title.getFormattedText(); - font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 ); - font.drawString( title, 8, ySize - 96 + 2, 0x404040 ); + String title = this.title.getColoredString(); + font.draw( title, (imageWidth - font.width( title )) / 2.0f, 6, 0x404040 ); + font.draw( title, 8, imageHeight - 96 + 2, 0x404040 ); } @Override - protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) + protected void renderBg( float partialTicks, int mouseX, int mouseY ) { RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); - minecraft.getTextureManager().bindTexture( BACKGROUND ); - blit( guiLeft, guiTop, 0, 0, xSize, ySize ); + minecraft.getTextureManager().bind( BACKGROUND ); + blit( leftPos, topPos, 0, 0, imageWidth, imageHeight ); } @Override @@ -42,6 +42,6 @@ public class GuiDiskDrive extends ContainerScreen { renderBackground(); super.render( mouseX, mouseY, partialTicks ); - renderHoveredToolTip( mouseX, mouseY ); + renderTooltip( mouseX, mouseY ); } } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java index 6f86c09b7..2b38703ee 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java @@ -23,21 +23,21 @@ public class GuiPrinter extends ContainerScreen } @Override - protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) + protected void renderLabels( int mouseX, int mouseY ) { - String title = getTitle().getFormattedText(); - font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 ); - font.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 ); + String title = getTitle().getColoredString(); + font.draw( title, (imageWidth - font.width( title )) / 2.0f, 6, 0x404040 ); + font.draw( I18n.get( "container.inventory" ), 8, imageHeight - 96 + 2, 0x404040 ); } @Override - protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) + protected void renderBg( float partialTicks, int mouseX, int mouseY ) { RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); - minecraft.getTextureManager().bindTexture( BACKGROUND ); - blit( guiLeft, guiTop, 0, 0, xSize, ySize ); + minecraft.getTextureManager().bind( BACKGROUND ); + blit( leftPos, topPos, 0, 0, imageWidth, imageHeight ); - if( getContainer().isPrinting() ) blit( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 ); + if( getMenu().isPrinting() ) blit( leftPos + 34, topPos + 21, 176, 0, 25, 45 ); } @Override @@ -45,6 +45,6 @@ public class GuiPrinter extends ContainerScreen { renderBackground(); super.render( mouseX, mouseY, partialTicks ); - renderHoveredToolTip( mouseX, mouseY ); + renderTooltip( mouseX, mouseY ); } } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java index 08ec7d892..9574d3f04 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java @@ -34,7 +34,7 @@ public class GuiPrintout extends ContainerScreen { super( container, player, title ); - ySize = Y_SIZE; + imageHeight = Y_SIZE; String[] text = ItemPrintout.getText( container.getStack() ); m_text = new TextBuffer[text.length]; @@ -91,16 +91,16 @@ public class GuiPrintout extends ContainerScreen } @Override - public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) + public void renderBg( float partialTicks, int mouseX, int mouseY ) { // Draw the printout RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); RenderSystem.enableDepthTest(); - IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); - drawBorder( IDENTITY, renderer, guiLeft, guiTop, getBlitOffset(), m_page, m_pages, m_book ); - drawText( IDENTITY, renderer, guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); - renderer.finish(); + IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource(); + drawBorder( IDENTITY, renderer, leftPos, topPos, getBlitOffset(), m_page, m_pages, m_book ); + drawText( IDENTITY, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); + renderer.endBatch(); } @Override @@ -112,6 +112,6 @@ public class GuiPrintout extends ContainerScreen setBlitOffset( getBlitOffset() + 1 ); super.render( mouseX, mouseY, partialTicks ); - renderHoveredToolTip( mouseX, mouseY ); + renderTooltip( mouseX, mouseY ); } } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java index 6bec2b78c..4548bbaa2 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java @@ -39,15 +39,15 @@ public class GuiTurtle extends ContainerScreen m_family = container.getFamily(); m_computer = (ClientComputer) container.getComputer(); - xSize = 254; - ySize = 217; + imageWidth = 254; + imageHeight = 217; } @Override protected void init() { super.init(); - minecraft.keyboardListener.enableRepeatEvents( true ); + minecraft.keyboardHandler.setSendRepeatsToGui( true ); int termPxWidth = ComputerCraft.turtleTermWidth * FixedWidthFontRenderer.FONT_WIDTH; int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT; @@ -58,7 +58,7 @@ public class GuiTurtle extends ContainerScreen ComputerCraft.turtleTermHeight, 2, 2, 2, 2 ); - terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + guiLeft, 2 + 8 + guiTop, termPxWidth, termPxHeight ); + terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + leftPos, 2 + 8 + topPos, termPxWidth, termPxHeight ); children.add( terminalWrapper ); setFocused( terminalWrapper ); @@ -70,7 +70,7 @@ public class GuiTurtle extends ContainerScreen super.removed(); children.remove( terminal ); terminal = null; - minecraft.keyboardListener.enableRepeatEvents( false ); + minecraft.keyboardHandler.setSendRepeatsToGui( false ); } @Override @@ -101,13 +101,13 @@ public class GuiTurtle extends ContainerScreen RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); int slotX = slot % 4; int slotY = slot / 4; - minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); - blit( guiLeft + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18, guiTop + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18, 0, 217, 24, 24 ); + minecraft.getTextureManager().bind( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); + blit( leftPos + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18, topPos + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18, 0, 217, 24, 24 ); } } @Override - protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) + protected void renderBg( float partialTicks, int mouseX, int mouseY ) { // Draw term boolean advanced = m_family == ComputerFamily.ADVANCED; @@ -115,8 +115,8 @@ public class GuiTurtle extends ContainerScreen // Draw border/inventory RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); - minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); - blit( guiLeft, guiTop, 0, 0, xSize, ySize ); + minecraft.getTextureManager().bind( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); + blit( leftPos, topPos, 0, 0, imageWidth, imageHeight ); drawSelectionSlot( advanced ); } @@ -126,7 +126,7 @@ public class GuiTurtle extends ContainerScreen { renderBackground(); super.render( mouseX, mouseY, partialTicks ); - renderHoveredToolTip( mouseX, mouseY ); + renderTooltip( mouseX, mouseY ); } @Override diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java index d64e24e9e..343e5229e 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java @@ -91,7 +91,7 @@ public class WidgetTerminal implements IGuiEventListener case GLFW.GLFW_KEY_V: // Ctrl+V for paste - String clipboard = client.keyboardListener.getClipboardString(); + String clipboard = client.keyboardHandler.getClipboard(); if( clipboard != null ) { // Clip to the first occurrence of \r or \n @@ -111,7 +111,7 @@ public class WidgetTerminal implements IGuiEventListener } // Filter the string - clipboard = SharedConstants.filterAllowedCharacters( clipboard ); + clipboard = SharedConstants.filterText( clipboard ); if( !clipboard.isEmpty() ) { // Clip to 512 characters and queue the event diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 50afc8f4f..e0b01fd0f 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -35,12 +35,12 @@ public final class ComputerCraftProxyClient registerContainers(); // While turtles themselves are not transparent, their upgrades may be. - RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_NORMAL.get(), RenderType.getTranslucent() ); - RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_ADVANCED.get(), RenderType.getTranslucent() ); + RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_NORMAL.get(), RenderType.translucent() ); + RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_ADVANCED.get(), RenderType.translucent() ); // Monitors' textures have transparent fronts and so count as cutouts. - RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_NORMAL.get(), RenderType.getCutout() ); - RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_ADVANCED.get(), RenderType.getCutout() ); + RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_NORMAL.get(), RenderType.cutout() ); + RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_ADVANCED.get(), RenderType.cutout() ); // Setup TESRs ClientRegistry.bindTileEntityRenderer( Registry.ModTiles.MONITOR_NORMAL.get(), TileEntityMonitorRenderer::new ); @@ -55,15 +55,15 @@ public final class ComputerCraftProxyClient { // My IDE doesn't think so, but we do actually need these generics. - ScreenManager.>registerFactory( Registry.ModContainers.COMPUTER.get(), GuiComputer::create ); - ScreenManager.>registerFactory( Registry.ModContainers.POCKET_COMPUTER.get(), GuiComputer::createPocket ); - ScreenManager.registerFactory( Registry.ModContainers.TURTLE.get(), GuiTurtle::new ); + ScreenManager.>register( Registry.ModContainers.COMPUTER.get(), GuiComputer::create ); + ScreenManager.>register( Registry.ModContainers.POCKET_COMPUTER.get(), GuiComputer::createPocket ); + ScreenManager.register( Registry.ModContainers.TURTLE.get(), GuiTurtle::new ); - ScreenManager.registerFactory( Registry.ModContainers.PRINTER.get(), GuiPrinter::new ); - ScreenManager.registerFactory( Registry.ModContainers.DISK_DRIVE.get(), GuiDiskDrive::new ); - ScreenManager.registerFactory( Registry.ModContainers.PRINTOUT.get(), GuiPrintout::new ); + ScreenManager.register( Registry.ModContainers.PRINTER.get(), GuiPrinter::new ); + ScreenManager.register( Registry.ModContainers.DISK_DRIVE.get(), GuiDiskDrive::new ); + ScreenManager.register( Registry.ModContainers.PRINTOUT.get(), GuiPrintout::new ); - ScreenManager.>registerFactory( Registry.ModContainers.VIEW_COMPUTER.get(), GuiComputer::createView ); + ScreenManager.>register( Registry.ModContainers.VIEW_COMPUTER.get(), GuiComputer::createView ); } @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT ) @@ -72,7 +72,7 @@ public final class ComputerCraftProxyClient @SubscribeEvent public static void onWorldUnload( WorldEvent.Unload event ) { - if( event.getWorld().isRemote() ) + if( event.getWorld().isClientSide() ) { ClientMonitor.destroyAll(); } diff --git a/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java b/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java index f87fa8782..5f517b1d1 100644 --- a/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java @@ -45,35 +45,35 @@ public final class CableHighlightRenderer public static void drawHighlight( DrawHighlightEvent.HighlightBlock event ) { BlockRayTraceResult hit = event.getTarget(); - BlockPos pos = hit.getPos(); - World world = event.getInfo().getRenderViewEntity().getEntityWorld(); + BlockPos pos = hit.getBlockPos(); + World world = event.getInfo().getEntity().getCommandSenderWorld(); ActiveRenderInfo info = event.getInfo(); BlockState state = world.getBlockState( pos ); // We only care about instances with both cable and modem. - if( state.getBlock() != Registry.ModBlocks.CABLE.get() || state.get( BlockCable.MODEM ).getFacing() == null || !state.get( BlockCable.CABLE ) ) + if( state.getBlock() != Registry.ModBlocks.CABLE.get() || state.getValue( BlockCable.MODEM ).getFacing() == null || !state.getValue( BlockCable.CABLE ) ) { return; } event.setCanceled( true ); - VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) + VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getLocation().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ? CableShapes.getModemShape( state ) : CableShapes.getCableShape( state ); - Vec3d cameraPos = info.getProjectedView(); - double xOffset = pos.getX() - cameraPos.getX(); - double yOffset = pos.getY() - cameraPos.getY(); - double zOffset = pos.getZ() - cameraPos.getZ(); + Vec3d cameraPos = info.getPosition(); + double xOffset = pos.getX() - cameraPos.x(); + double yOffset = pos.getY() - cameraPos.y(); + double zOffset = pos.getZ() - cameraPos.z(); - IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() ); - Matrix4f matrix4f = event.getMatrix().getLast().getMatrix(); - shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> { - buffer.pos( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) ) + IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() ); + Matrix4f matrix4f = event.getMatrix().last().pose(); + shape.forAllEdges( ( x1, y1, z1, x2, y2, z2 ) -> { + buffer.vertex( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) ) .color( 0, 0, 0, 0.4f ).endVertex(); - buffer.pos( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) ) + buffer.vertex( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) ) .color( 0, 0, 0, 0.4f ).endVertex(); } ); } diff --git a/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java b/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java index 4eacb4779..a7357f0d2 100644 --- a/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ComputerBorderRenderer.java @@ -85,13 +85,13 @@ public class ComputerBorderRenderer public static void render( int x, int y, int z, int width, int height ) { Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); + BufferBuilder buffer = tessellator.getBuilder(); buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX ); render( IDENTITY, buffer, x, y, z, width, height ); RenderSystem.enableAlphaTest(); - tessellator.draw(); + tessellator.end(); } public static void render( Matrix4f transform, IVertexBuilder buffer, int x, int y, int z, int width, int height ) @@ -166,9 +166,9 @@ public class ComputerBorderRenderer private void renderTexture( int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight ) { - builder.pos( transform, x, y + height, z ).color( r, g, b, 1.0f ).tex( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); - builder.pos( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).tex( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); - builder.pos( transform, x + width, y, z ).color( r, g, b, 1.0f ).tex( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).endVertex(); - builder.pos( transform, x, y, z ).color( r, g, b, 1.0f ).tex( u * TEX_SCALE, v * TEX_SCALE ).endVertex(); + builder.vertex( transform, x, y + height, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); + builder.vertex( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex(); + builder.vertex( transform, x + width, y, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).endVertex(); + builder.vertex( transform, x, y, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, v * TEX_SCALE ).endVertex(); } } diff --git a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java index 9176dd722..af0248b02 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java @@ -33,8 +33,8 @@ public abstract class ItemMapLikeRenderer { PlayerEntity player = Minecraft.getInstance().player; - transform.push(); - if( hand == Hand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() ) + transform.pushPose(); + if( hand == Hand.MAIN_HAND && player.getOffhandItem().isEmpty() ) { renderItemFirstPersonCenter( transform, render, lightTexture, pitch, equipProgress, swingProgress, stack ); } @@ -42,11 +42,11 @@ public abstract class ItemMapLikeRenderer { renderItemFirstPersonSide( transform, render, lightTexture, - hand == Hand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(), + hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(), equipProgress, swingProgress, stack ); } - transform.pop(); + transform.popPose(); } /** @@ -70,15 +70,15 @@ public abstract class ItemMapLikeRenderer // If the player is not invisible then render a single arm if( !minecraft.player.isInvisible() ) { - transform.push(); - transform.rotate( Vector3f.ZP.rotationDegrees( offset * 10f ) ); - minecraft.getFirstPersonRenderer().renderArmFirstPerson( transform, render, combinedLight, equipProgress, swingProgress, side ); - transform.pop(); + transform.pushPose(); + transform.mulPose( Vector3f.ZP.rotationDegrees( offset * 10f ) ); + minecraft.getItemInHandRenderer().renderPlayerArm( transform, render, combinedLight, equipProgress, swingProgress, side ); + transform.popPose(); } // Setup the appropriate transformations. This is just copied from the // corresponding method in ItemRenderer. - transform.push(); + transform.pushPose(); transform.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f ); float f1 = MathHelper.sqrt( swingProgress ); float f2 = MathHelper.sin( f1 * (float) Math.PI ); @@ -86,12 +86,12 @@ 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.rotate( Vector3f.XP.rotationDegrees( f2 * -45f ) ); - transform.rotate( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) ); + transform.mulPose( Vector3f.XP.rotationDegrees( f2 * -45f ) ); + transform.mulPose( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) ); renderItem( transform, render, stack ); - transform.pop(); + transform.popPose(); } /** @@ -109,7 +109,7 @@ public abstract class ItemMapLikeRenderer private void renderItemFirstPersonCenter( MatrixStack transform, IRenderTypeBuffer render, int combinedLight, float pitch, float equipProgress, float swingProgress, ItemStack stack ) { Minecraft minecraft = Minecraft.getInstance(); - FirstPersonRenderer renderer = minecraft.getFirstPersonRenderer(); + FirstPersonRenderer renderer = minecraft.getItemInHandRenderer(); // Setup the appropriate transformations. This is just copied from the // corresponding method in ItemRenderer. @@ -118,20 +118,20 @@ public abstract class ItemMapLikeRenderer float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI ); transform.translate( 0, -tX / 2, tZ ); - float pitchAngle = renderer.getMapAngleFromPitch( pitch ); + float pitchAngle = renderer.calculateMapTilt( pitch ); transform.translate( 0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f ); - transform.rotate( Vector3f.XP.rotationDegrees( pitchAngle * -85.0f ) ); + transform.mulPose( Vector3f.XP.rotationDegrees( pitchAngle * -85.0f ) ); if( !minecraft.player.isInvisible() ) { - transform.push(); - transform.rotate( Vector3f.YP.rotationDegrees( 90.0F ) ); - renderer.renderArm( transform, render, combinedLight, HandSide.RIGHT ); - renderer.renderArm( transform, render, combinedLight, HandSide.LEFT ); - transform.pop(); + transform.pushPose(); + transform.mulPose( Vector3f.YP.rotationDegrees( 90.0F ) ); + renderer.renderMapHand( transform, render, combinedLight, HandSide.RIGHT ); + renderer.renderMapHand( transform, render, combinedLight, HandSide.LEFT ); + transform.popPose(); } float rX = MathHelper.sin( swingRt * (float) Math.PI ); - transform.rotate( Vector3f.XP.rotationDegrees( rX * 20.0F ) ); + transform.mulPose( Vector3f.XP.rotationDegrees( rX * 20.0F ) ); transform.scale( 2.0F, 2.0F, 2.0F ); renderItem( transform, render, stack ); diff --git a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java index 0b356f0fe..499d82202 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java @@ -79,9 +79,9 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer // Setup various transformations. Note that these are partially adapted from the corresponding method // in ItemRenderer - transform.push(); - transform.rotate( Vector3f.YP.rotationDegrees( 180f ) ); - transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) ); + transform.pushPose(); + transform.mulPose( Vector3f.YP.rotationDegrees( 180f ) ); + transform.mulPose( Vector3f.ZP.rotationDegrees( 180f ) ); transform.scale( 0.5f, 0.5f, 0.5f ); float scale = 0.75f / Math.max( width + BORDER * 2, height + BORDER * 2 + LIGHT_HEIGHT ); @@ -93,7 +93,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer ComputerFamily family = item.getFamily(); int frameColour = item.getColour( stack ); - Matrix4f matrix = transform.getLast().getMatrix(); + Matrix4f matrix = transform.last().pose(); renderFrame( matrix, family, frameColour, width, height ); // Render the light @@ -110,26 +110,26 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer FixedWidthFontRenderer.drawEmptyTerminal( matrix, 0, 0, width, height ); } - transform.pop(); + transform.popPose(); } private static void renderFrame( Matrix4f transform, ComputerFamily family, int colour, int width, int height ) { RenderSystem.enableBlend(); Minecraft.getInstance().getTextureManager() - .bindTexture( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) ); + .bind( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) ); float r = ((colour >>> 16) & 0xFF) / 255.0f; float g = ((colour >>> 8) & 0xFF) / 255.0f; float b = (colour & 0xFF) / 255.0f; Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); + BufferBuilder buffer = tessellator.getBuilder(); buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX ); ComputerBorderRenderer.render( transform, buffer, 0, 0, 0, width, height, LIGHT_HEIGHT, r, g, b ); - tessellator.draw(); + tessellator.end(); } private static void renderLight( Matrix4f transform, int colour, int width, int height ) @@ -141,14 +141,14 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer float b = (colour & 0xFF) / 255.0f; Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); + BufferBuilder buffer = tessellator.getBuilder(); buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR ); - buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( transform, width, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( transform, width, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); - buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.vertex( transform, width, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.vertex( transform, width, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); + buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex(); - tessellator.draw(); + tessellator.end(); RenderSystem.enableTexture(); } } diff --git a/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java index 4549060df..fcf52f2e1 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java @@ -52,7 +52,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer @Override protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack ) { - transform.rotate( Vector3f.XP.rotationDegrees( 180f ) ); + transform.mulPose( Vector3f.XP.rotationDegrees( 180f ) ); transform.scale( 0.42f, 0.42f, -0.42f ); transform.translate( -0.5f, -0.48f, 0.0f ); @@ -70,7 +70,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer // Move a little bit forward to ensure we're not clipping with the frame transform.translate( 0.0f, 0.0f, -0.001f ); - transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) ); + transform.mulPose( Vector3f.ZP.rotationDegrees( 180f ) ); transform.scale( 0.95f, 0.95f, -0.95f ); transform.translate( -0.5f, -0.5f, 0.0f ); @@ -104,7 +104,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer transform.scale( scale, scale, scale ); transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 ); - Matrix4f matrix = transform.getLast().getMatrix(); + Matrix4f matrix = transform.last().pose(); drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book ); drawText( matrix, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) diff --git a/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java b/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java index a954938a3..35a6c0dbb 100644 --- a/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java @@ -40,12 +40,12 @@ public final class MonitorHighlightRenderer public static void drawHighlight( DrawHighlightEvent.HighlightBlock event ) { // Preserve normal behaviour when crouching. - if( event.getInfo().getRenderViewEntity().isCrouching() ) return; + if( event.getInfo().getEntity().isCrouching() ) return; - World world = event.getInfo().getRenderViewEntity().getEntityWorld(); - BlockPos pos = event.getTarget().getPos(); + World world = event.getInfo().getEntity().getCommandSenderWorld(); + BlockPos pos = event.getTarget().getBlockPos(); - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( !(tile instanceof TileMonitor) ) return; TileMonitor monitor = (TileMonitor) tile; @@ -61,13 +61,13 @@ public final class MonitorHighlightRenderer if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() ); MatrixStack transformStack = event.getMatrix(); - Vec3d cameraPos = event.getInfo().getProjectedView(); - transformStack.push(); - transformStack.translate( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() ); + Vec3d cameraPos = event.getInfo().getPosition(); + transformStack.pushPose(); + transformStack.translate( pos.getX() - cameraPos.x(), pos.getY() - cameraPos.y(), pos.getZ() - cameraPos.z() ); // I wish I could think of a better way to do this - IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() ); - Matrix4f transform = transformStack.getLast().getMatrix(); + IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() ); + Matrix4f transform = transformStack.last().pose(); if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 0, UP ); if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 1, UP ); if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, transform, 1, 0, 0, UP ); @@ -81,16 +81,16 @@ public final class MonitorHighlightRenderer if( faces.contains( WEST ) || faces.contains( UP ) ) line( buffer, transform, 0, 1, 0, SOUTH ); if( faces.contains( EAST ) || faces.contains( UP ) ) line( buffer, transform, 1, 1, 0, SOUTH ); - transformStack.pop(); + transformStack.popPose(); } private static void line( IVertexBuilder buffer, Matrix4f transform, float x, float y, float z, Direction direction ) { - buffer.pos( transform, x, y, z ).color( 0, 0, 0, 0.4f ).endVertex(); - buffer.pos( transform, - x + direction.getXOffset(), - y + direction.getYOffset(), - z + direction.getZOffset() + buffer.vertex( transform, x, y, z ).color( 0, 0, 0, 0.4f ).endVertex(); + buffer.vertex( transform, + x + direction.getStepX(), + y + direction.getStepY(), + z + direction.getStepZ() ).color( 0, 0, 0, 0.4f ).endVertex(); } } diff --git a/src/main/java/dan200/computercraft/client/render/MonitorTextureBufferShader.java b/src/main/java/dan200/computercraft/client/render/MonitorTextureBufferShader.java index 241823f33..2e669f79b 100644 --- a/src/main/java/dan200/computercraft/client/render/MonitorTextureBufferShader.java +++ b/src/main/java/dan200/computercraft/client/render/MonitorTextureBufferShader.java @@ -42,7 +42,7 @@ class MonitorTextureBufferShader static void setupUniform( Matrix4f transform, int width, int height, Palette palette, boolean greyscale ) { MATRIX_BUFFER.rewind(); - transform.write( MATRIX_BUFFER ); + transform.store( MATRIX_BUFFER ); MATRIX_BUFFER.rewind(); RenderSystem.glUniformMatrix4( uniformMv, false, MATRIX_BUFFER ); @@ -71,7 +71,7 @@ class MonitorTextureBufferShader { if( initialised ) { - if( ok ) GlStateManager.useProgram( program ); + if( ok ) GlStateManager._glUseProgram( program ); return ok; } @@ -94,14 +94,14 @@ 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 ).trim(); + 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 ) ) { ComputerCraft.log.warn( "Problems when linking monitor shader: {}", log ); @@ -109,8 +109,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 ) return false; @@ -137,13 +137,13 @@ class MonitorTextureBufferShader if( stream == null ) throw new IllegalArgumentException( "Cannot find " + path ); String contents = TextureUtil.readResourceAsString( stream ); - 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 ).trim(); + boolean ok = GlStateManager.glGetShaderi( shader, GL20.GL_COMPILE_STATUS ) != 0; + String log = GlStateManager.glGetShaderInfoLog( shader, Short.MAX_VALUE ).trim(); if( !Strings.isNullOrEmpty( log ) ) { ComputerCraft.log.warn( "Problems when loading monitor shader {}: {}", path, log ); @@ -155,7 +155,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 ); return uniform; } diff --git a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java index 69a9865a7..9127cb426 100644 --- a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java @@ -146,18 +146,18 @@ public final class PrintoutRenderer private static void drawTexture( Matrix4f matrix, IVertexBuilder buffer, float x, float y, float z, float u, float v, float width, float height ) { - buffer.pos( matrix, x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); - buffer.pos( matrix, x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); - buffer.pos( matrix, x + width, y, z ).tex( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex(); - buffer.pos( matrix, x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x, y + height, z ).uv( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x + width, y + height, z ).uv( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x + width, y, z ).uv( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x, y, z ).uv( u / BG_SIZE, v / BG_SIZE ).endVertex(); } private static void drawTexture( Matrix4f matrix, IVertexBuilder buffer, float x, float y, float z, float width, float height, float u, float v, float tWidth, float tHeight ) { - buffer.pos( matrix, x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); - buffer.pos( matrix, x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); - buffer.pos( matrix, x + width, y, z ).tex( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex(); - buffer.pos( matrix, x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x, y + height, z ).uv( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x + width, y + height, z ).uv( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x + width, y, z ).uv( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex(); + buffer.vertex( matrix, x, y, z ).uv( u / BG_SIZE, v / BG_SIZE ).endVertex(); } public static float offsetAt( int page ) @@ -167,14 +167,14 @@ public final class PrintoutRenderer private static final class Type extends RenderState { - static final RenderType TYPE = RenderType.makeType( + static final RenderType TYPE = RenderType.create( "printout_background", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 1024, false, false, // useDelegate, needsSorting - RenderType.State.getBuilder() - .texture( new RenderState.TextureState( BG, false, false ) ) // blur, minimap - .alpha( DEFAULT_ALPHA ) - .lightmap( LIGHTMAP_DISABLED ) - .build( false ) + RenderType.State.builder() + .setTextureState( new RenderState.TextureState( BG, false, false ) ) // blur, minimap + .setAlphaState( DEFAULT_ALPHA ) + .setLightmapState( NO_LIGHTMAP ) + .createCompositeState( false ) ); private Type( String name, Runnable setup, Runnable destroy ) diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 2fdcd3411..66f528e4b 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -58,7 +58,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer if( originTerminal == null ) return; TileMonitor origin = originTerminal.getOrigin(); - BlockPos monitorPos = monitor.getPos(); + BlockPos monitorPos = monitor.getBlockPos(); // Ensure each monitor terminal is rendered only once. We allow rendering a specific tile // multiple times in a single frame to ensure compatibility with shaders which may run a @@ -72,24 +72,24 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer originTerminal.lastRenderFrame = renderFrame; originTerminal.lastRenderPos = monitorPos; - BlockPos originPos = origin.getPos(); + BlockPos originPos = origin.getBlockPos(); // Determine orientation Direction dir = origin.getDirection(); Direction front = origin.getFront(); - float yaw = dir.getHorizontalAngle(); + float yaw = dir.toYRot(); float pitch = DirectionUtil.toPitchAngle( front ); // Setup initial transform - transform.push(); + transform.pushPose(); transform.translate( originPos.getX() - monitorPos.getX() + 0.5, originPos.getY() - monitorPos.getY() + 0.5, originPos.getZ() - monitorPos.getZ() + 0.5 ); - transform.rotate( Vector3f.YN.rotationDegrees( yaw ) ); - transform.rotate( Vector3f.XP.rotationDegrees( pitch ) ); + transform.mulPose( Vector3f.YN.rotationDegrees( yaw ) ); + transform.mulPose( Vector3f.XP.rotationDegrees( pitch ) ); transform.translate( -0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN, origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0, @@ -107,10 +107,10 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer int pixelWidth = width * FONT_WIDTH, pixelHeight = height * FONT_HEIGHT; double xScale = xSize / pixelWidth; double yScale = ySize / pixelHeight; - transform.push(); + transform.pushPose(); transform.scale( (float) xScale, (float) -yScale, 1.0f ); - Matrix4f matrix = transform.getLast().getMatrix(); + Matrix4f matrix = transform.last().pose(); // Sneaky hack here: we get a buffer now in order to flush existing ones and set up the appropriate // render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick @@ -124,24 +124,24 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer // reasonable. FixedWidthFontRenderer.drawCursor( matrix, buffer, 0, 0, terminal, !originTerminal.isColour() ); - transform.pop(); + transform.popPose(); } else { FixedWidthFontRenderer.drawEmptyTerminal( - transform.getLast().getMatrix(), renderer, + transform.last().pose(), renderer, -MARGIN, MARGIN, (float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2) ); } FixedWidthFontRenderer.drawBlocker( - transform.getLast().getMatrix(), renderer, + transform.last().pose(), renderer, (float) -TileMonitor.RENDER_MARGIN, (float) TileMonitor.RENDER_MARGIN, (float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2) ); - transform.pop(); + transform.popPose(); } private static void renderTerminal( Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin ) @@ -166,7 +166,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer int size = width * height * 3; if( tboContents == null || tboContents.capacity() < size ) { - tboContents = GLAllocation.createDirectByteBuffer( size ); + tboContents = GLAllocation.createByteBuffer( size ); } ByteBuffer monitorBuffer = tboContents; @@ -183,28 +183,28 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer } monitorBuffer.flip(); - GlStateManager.bindBuffer( GL31.GL_TEXTURE_BUFFER, monitor.tboBuffer ); - GlStateManager.bufferData( GL31.GL_TEXTURE_BUFFER, monitorBuffer, GL20.GL_STATIC_DRAW ); - GlStateManager.bindBuffer( GL31.GL_TEXTURE_BUFFER, 0 ); + GlStateManager._glBindBuffer( GL31.GL_TEXTURE_BUFFER, monitor.tboBuffer ); + GlStateManager._glBufferData( GL31.GL_TEXTURE_BUFFER, monitorBuffer, GL20.GL_STATIC_DRAW ); + GlStateManager._glBindBuffer( GL31.GL_TEXTURE_BUFFER, 0 ); } // Nobody knows what they're doing! - GlStateManager.activeTexture( MonitorTextureBufferShader.TEXTURE_INDEX ); + GlStateManager._activeTexture( MonitorTextureBufferShader.TEXTURE_INDEX ); GL11.glBindTexture( GL31.GL_TEXTURE_BUFFER, monitor.tboTexture ); - GlStateManager.activeTexture( GL13.GL_TEXTURE0 ); + GlStateManager._activeTexture( GL13.GL_TEXTURE0 ); MonitorTextureBufferShader.setupUniform( matrix, width, height, terminal.getPalette(), !monitor.isColour() ); Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); + BufferBuilder buffer = tessellator.getBuilder(); buffer.begin( GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION ); - buffer.pos( -xMargin, -yMargin, 0 ).endVertex(); - buffer.pos( -xMargin, pixelHeight + yMargin, 0 ).endVertex(); - buffer.pos( pixelWidth + xMargin, -yMargin, 0 ).endVertex(); - buffer.pos( pixelWidth + xMargin, pixelHeight + yMargin, 0 ).endVertex(); - tessellator.draw(); + buffer.vertex( -xMargin, -yMargin, 0 ).endVertex(); + buffer.vertex( -xMargin, pixelHeight + yMargin, 0 ).endVertex(); + buffer.vertex( pixelWidth + xMargin, -yMargin, 0 ).endVertex(); + buffer.vertex( pixelWidth + xMargin, pixelHeight + yMargin, 0 ).endVertex(); + tessellator.end(); - GlStateManager.useProgram( 0 ); + GlStateManager._glUseProgram( 0 ); break; } @@ -214,22 +214,22 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer if( redraw ) { Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder builder = tessellator.getBuffer(); - builder.begin( FixedWidthFontRenderer.TYPE.getDrawMode(), FixedWidthFontRenderer.TYPE.getVertexFormat() ); + BufferBuilder builder = tessellator.getBuilder(); + builder.begin( FixedWidthFontRenderer.TYPE.mode(), FixedWidthFontRenderer.TYPE.format() ); FixedWidthFontRenderer.drawTerminalWithoutCursor( IDENTITY, builder, 0, 0, terminal, !monitor.isColour(), yMargin, yMargin, xMargin, xMargin ); - builder.finishDrawing(); + builder.end(); vbo.upload( builder ); } - vbo.bindBuffer(); - FixedWidthFontRenderer.TYPE.getVertexFormat().setupBufferState( 0L ); - vbo.draw( matrix, FixedWidthFontRenderer.TYPE.getDrawMode() ); - VertexBuffer.unbindBuffer(); - FixedWidthFontRenderer.TYPE.getVertexFormat().clearBufferState(); + vbo.bind(); + FixedWidthFontRenderer.TYPE.format().setupBufferState( 0L ); + vbo.draw( matrix, FixedWidthFontRenderer.TYPE.mode() ); + VertexBuffer.unbind(); + FixedWidthFontRenderer.TYPE.format().clearBufferState(); break; } } diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java index d9717d84a..eee5c6b25 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java @@ -72,31 +72,31 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer } @Override - public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull MatrixStack transform, @Nonnull IRenderTypeBuffer renderer, int lightmapCoord, int overlayLight ) + public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull MatrixStack transform, @Nonnull IRenderTypeBuffer buffers, int lightmapCoord, int overlayLight ) { // Render the label String label = turtle.createProxy().getLabel(); - RayTraceResult hit = renderDispatcher.cameraHitResult; - if( label != null && hit.getType() == RayTraceResult.Type.BLOCK && turtle.getPos().equals( ((BlockRayTraceResult) hit).getPos() ) ) + RayTraceResult hit = renderer.cameraHitResult; + if( label != null && hit.getType() == RayTraceResult.Type.BLOCK && turtle.getBlockPos().equals( ((BlockRayTraceResult) hit).getBlockPos() ) ) { Minecraft mc = Minecraft.getInstance(); - FontRenderer font = renderDispatcher.fontRenderer; + FontRenderer font = renderer.font; - transform.push(); + transform.pushPose(); transform.translate( 0.5, 1.2, 0.5 ); - transform.rotate( mc.getRenderManager().getCameraOrientation() ); + transform.mulPose( mc.getEntityRenderDispatcher().cameraOrientation() ); transform.scale( -0.025f, -0.025f, 0.025f ); - Matrix4f matrix = transform.getLast().getMatrix(); - int opacity = (int) (mc.gameSettings.getTextBackgroundOpacity( 0.25f ) * 255) << 24; - float width = -font.getStringWidth( label ) / 2.0f; - font.renderString( label, width, (float) 0, 0x20ffffff, false, matrix, renderer, true, opacity, lightmapCoord ); - font.renderString( label, width, (float) 0, 0xffffffff, false, matrix, renderer, false, 0, lightmapCoord ); + Matrix4f matrix = transform.last().pose(); + int opacity = (int) (mc.options.getBackgroundOpacity( 0.25f ) * 255) << 24; + float width = -font.width( label ) / 2.0f; + font.drawInBatch( label, width, (float) 0, 0x20ffffff, false, matrix, buffers, true, opacity, lightmapCoord ); + font.drawInBatch( label, width, (float) 0, 0xffffffff, false, matrix, buffers, false, 0, lightmapCoord ); - transform.pop(); + transform.popPose(); } - transform.push(); + transform.pushPose(); // Setup the transform. Vec3d offset = turtle.getRenderOffset( partialTicks ); @@ -104,7 +104,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer transform.translate( offset.x, offset.y, offset.z ); transform.translate( 0.5f, 0.5f, 0.5f ); - transform.rotate( Vector3f.YP.rotationDegrees( 180.0f - yaw ) ); + transform.mulPose( Vector3f.YP.rotationDegrees( 180.0f - yaw ) ); if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) ) { // Flip the model @@ -117,7 +117,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer ComputerFamily family = turtle.getFamily(); ResourceLocation overlay = turtle.getOverlay(); - IVertexBuilder buffer = renderer.getBuffer( Atlases.getTranslucentCullBlockType() ); + IVertexBuilder buffer = buffers.getBuffer( Atlases.translucentCullBlockSheet() ); renderModel( transform, buffer, lightmapCoord, overlayLight, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } ); // Render the overlay @@ -131,31 +131,31 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.LEFT, partialTicks ); renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.RIGHT, partialTicks ); - transform.pop(); + transform.popPose(); } private void renderUpgrade( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, TileTurtle turtle, TurtleSide side, float f ) { ITurtleUpgrade upgrade = turtle.getUpgrade( side ); if( upgrade == null ) return; - transform.push(); + transform.pushPose(); float toolAngle = turtle.getToolRenderAngle( side, f ); transform.translate( 0.0f, 0.5f, 0.5f ); - transform.rotate( Vector3f.XN.rotationDegrees( toolAngle ) ); + transform.mulPose( Vector3f.XN.rotationDegrees( toolAngle ) ); transform.translate( 0.0f, -0.5f, -0.5f ); TransformedModel model = upgrade.getModel( turtle.getAccess(), side ); model.getMatrix().push( transform ); renderModel( transform, renderer, lightmapCoord, overlayLight, model.getModel(), null ); - transform.pop(); + transform.popPose(); - transform.pop(); + transform.popPose(); } private void renderModel( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, ModelResourceLocation modelLocation, int[] tints ) { - ModelManager modelManager = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getModelManager(); + ModelManager modelManager = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getModelManager(); renderModel( transform, renderer, lightmapCoord, overlayLight, modelManager.getModel( modelLocation ), tints ); } @@ -171,12 +171,12 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer private static void renderQuads( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder buffer, int lightmapCoord, int overlayLight, List quads, int[] tints ) { - MatrixStack.Entry matrix = transform.getLast(); + MatrixStack.Entry matrix = transform.last(); for( BakedQuad bakedquad : quads ) { int tint = -1; - if( tints != null && bakedquad.hasTintIndex() ) + if( tints != null && bakedquad.isTinted() ) { int idx = bakedquad.getTintIndex(); if( idx >= 0 && idx < tints.length ) tint = tints[bakedquad.getTintIndex()]; diff --git a/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java b/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java index 353166e47..d1eb8a585 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java +++ b/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java @@ -43,7 +43,7 @@ public final class TurtleModelLoader implements IModelLoader getTextures( IModelConfiguration owner, Function modelGetter, Set> missingTextureErrors ) { Set materials = new HashSet<>(); - materials.addAll( modelGetter.apply( family ).getTextures( modelGetter, missingTextureErrors ) ); - materials.addAll( modelGetter.apply( COLOUR_TURTLE_MODEL ).getTextures( modelGetter, missingTextureErrors ) ); + materials.addAll( modelGetter.apply( family ).getMaterials( modelGetter, missingTextureErrors ) ); + materials.addAll( modelGetter.apply( COLOUR_TURTLE_MODEL ).getMaterials( modelGetter, missingTextureErrors ) ); return materials; } diff --git a/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java b/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java index d690c5d40..b099ce309 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java +++ b/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java @@ -90,9 +90,9 @@ public class TurtleMultiModel implements IBakedModel } @Override - public boolean isAmbientOcclusion() + public boolean useAmbientOcclusion() { - return m_baseModel.isAmbientOcclusion(); + return m_baseModel.useAmbientOcclusion(); } @Override @@ -102,31 +102,31 @@ public class TurtleMultiModel implements IBakedModel } @Override - public boolean isBuiltInRenderer() + public boolean isCustomRenderer() { - return m_baseModel.isBuiltInRenderer(); + return m_baseModel.isCustomRenderer(); } @Override - public boolean func_230044_c_() + public boolean usesBlockLight() { - return m_baseModel.func_230044_c_(); + return m_baseModel.usesBlockLight(); } @Nonnull @Override @Deprecated - public TextureAtlasSprite getParticleTexture() + public TextureAtlasSprite getParticleIcon() { - return m_baseModel.getParticleTexture(); + return m_baseModel.getParticleIcon(); } @Nonnull @Override @Deprecated - public net.minecraft.client.renderer.model.ItemCameraTransforms getItemCameraTransforms() + public net.minecraft.client.renderer.model.ItemCameraTransforms getTransforms() { - return m_baseModel.getItemCameraTransforms(); + return m_baseModel.getTransforms(); } @Nonnull diff --git a/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java b/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java index 7fecf7514..ef05a8c92 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TurtlePlayerRenderer.java @@ -23,7 +23,7 @@ public class TurtlePlayerRenderer extends EntityRenderer @Nonnull @Override - public ResourceLocation getEntityTexture( @Nonnull TurtlePlayer entity ) + public ResourceLocation getTextureLocation( @Nonnull TurtlePlayer entity ) { return ComputerBorderRenderer.BACKGROUND_NORMAL; } diff --git a/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java b/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java index 3488cf7b8..047e5470c 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java +++ b/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java @@ -42,7 +42,7 @@ public class TurtleSmartItemModel implements IBakedModel stack.translate( 0, 0, 1 ); identity = TransformationMatrix.identity(); - flip = new TransformationMatrix( stack.getLast().getMatrix() ); + flip = new TransformationMatrix( stack.last().pose() ); } private static class TurtleModelCombination @@ -109,7 +109,7 @@ public class TurtleSmartItemModel implements IBakedModel { @Nonnull @Override - public IBakedModel getModelWithOverrides( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable LivingEntity entity ) + public IBakedModel resolve( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable LivingEntity entity ) { ItemTurtle turtle = (ItemTurtle) stack.getItem(); int colour = turtle.getColour( stack ); @@ -138,7 +138,7 @@ public class TurtleSmartItemModel implements IBakedModel private IBakedModel buildModel( TurtleModelCombination combo ) { Minecraft mc = Minecraft.getInstance(); - ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager(); + ModelManager modelManager = mc.getItemRenderer().getItemModelShaper().getModelManager(); ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas ); IBakedModel baseModel = combo.m_colour ? colourModel : familyModel; @@ -166,9 +166,9 @@ public class TurtleSmartItemModel implements IBakedModel } @Override - public boolean isAmbientOcclusion() + public boolean useAmbientOcclusion() { - return familyModel.isAmbientOcclusion(); + return familyModel.useAmbientOcclusion(); } @Override @@ -178,31 +178,31 @@ public class TurtleSmartItemModel implements IBakedModel } @Override - public boolean isBuiltInRenderer() + public boolean isCustomRenderer() { - return familyModel.isBuiltInRenderer(); + return familyModel.isCustomRenderer(); } @Override - public boolean func_230044_c_() + public boolean usesBlockLight() { - return familyModel.func_230044_c_(); + return familyModel.usesBlockLight(); } @Nonnull @Override @Deprecated - public TextureAtlasSprite getParticleTexture() + public TextureAtlasSprite getParticleIcon() { - return familyModel.getParticleTexture(); + return familyModel.getParticleIcon(); } @Nonnull @Override @Deprecated - public ItemCameraTransforms getItemCameraTransforms() + public ItemCameraTransforms getTransforms() { - return familyModel.getItemCameraTransforms(); + return familyModel.getTransforms(); } } diff --git a/src/main/java/dan200/computercraft/core/computer/Environment.java b/src/main/java/dan200/computercraft/core/computer/Environment.java index 3931629f1..9aebcfd33 100644 --- a/src/main/java/dan200/computercraft/core/computer/Environment.java +++ b/src/main/java/dan200/computercraft/core/computer/Environment.java @@ -20,6 +20,8 @@ import javax.annotation.Nonnull; import java.util.Arrays; import java.util.Iterator; +import dan200.computercraft.core.apis.IAPIEnvironment.IPeripheralChangeListener; + /** * Represents the "environment" that a {@link Computer} exists in. * diff --git a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java index 648a06ed0..ed21df789 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java @@ -104,7 +104,7 @@ public final class ResourceMount implements IMount { boolean hasAny = false; FileEntry newRoot = new FileEntry( new ResourceLocation( namespace, subPath ) ); - for( ResourceLocation file : manager.getAllResourceLocations( subPath, s -> true ) ) + for( ResourceLocation file : manager.listResources( subPath, s -> true ) ) { if( !file.getNamespace().equals( namespace ) ) continue; @@ -297,7 +297,7 @@ public final class ResourceMount implements IMount synchronized void add( IReloadableResourceManager manager, ResourceMount mount ) { - if( managers.add( manager ) ) manager.addReloadListener( this ); + if( managers.add( manager ) ) manager.registerReloadListener( this ); mounts.add( mount ); } } diff --git a/src/main/java/dan200/computercraft/data/BlockModelProvider.java b/src/main/java/dan200/computercraft/data/BlockModelProvider.java index c336b9948..e0091c24e 100644 --- a/src/main/java/dan200/computercraft/data/BlockModelProvider.java +++ b/src/main/java/dan200/computercraft/data/BlockModelProvider.java @@ -52,7 +52,7 @@ public class BlockModelProvider extends BlockStateProvider private void registerComputer( BlockComputer block ) { VariantBlockStateBuilder builder = getVariantBuilder( block ); - for( ComputerState state : BlockComputer.STATE.getAllowedValues() ) + for( ComputerState state : BlockComputer.STATE.getPossibleValues() ) { BlockModelBuilder model = models() .getBuilder( suffix( block, "_" + state ) ) @@ -61,7 +61,7 @@ public class BlockModelProvider extends BlockStateProvider .texture( "side", suffix( block, "_side" ) ) .texture( "front", suffix( block, "_front" + toSuffix( state ) ) ); - for( Direction facing : BlockComputer.FACING.getAllowedValues() ) + for( Direction facing : BlockComputer.FACING.getPossibleValues() ) { builder.partialState() .with( BlockComputer.STATE, state ) @@ -92,14 +92,14 @@ public class BlockModelProvider extends BlockStateProvider registerMonitorModel( name, "_ud", 21, 6, 0, 37 ); VariantBlockStateBuilder builder = getVariantBuilder( block ); - for( MonitorEdgeState edge : BlockMonitor.STATE.getAllowedValues() ) + for( MonitorEdgeState edge : BlockMonitor.STATE.getPossibleValues() ) { - String suffix = edge == MonitorEdgeState.NONE ? "" : "_" + edge.getName(); + String suffix = edge == MonitorEdgeState.NONE ? "" : "_" + edge.getSerializedName(); ModelFile model = models().getBuilder( suffix( block, suffix ) ); - for( Direction facing : BlockMonitor.FACING.getAllowedValues() ) + for( Direction facing : BlockMonitor.FACING.getPossibleValues() ) { - for( Direction orientation : BlockMonitor.ORIENTATION.getAllowedValues() ) + for( Direction orientation : BlockMonitor.ORIENTATION.getPossibleValues() ) { builder.partialState() .with( BlockMonitor.STATE, edge ) @@ -137,7 +137,7 @@ public class BlockModelProvider extends BlockStateProvider private static int toYAngle( Direction direction ) { - return ((int) direction.getHorizontalAngle() + 180) % 360; + return ((int) direction.toYRot() + 180) % 360; } private static String toSuffix( ComputerState state ) diff --git a/src/main/java/dan200/computercraft/data/LootTableProvider.java b/src/main/java/dan200/computercraft/data/LootTableProvider.java index b76ca31bd..3345bafea 100644 --- a/src/main/java/dan200/computercraft/data/LootTableProvider.java +++ b/src/main/java/dan200/computercraft/data/LootTableProvider.java @@ -40,17 +40,17 @@ public abstract class LootTableProvider implements IDataProvider } @Override - public void act( @Nonnull DirectoryCache cache ) + public void run( @Nonnull DirectoryCache cache ) { Map tables = new HashMap<>(); - ValidationTracker validation = new ValidationTracker( LootParameterSets.GENERIC, x -> null, tables::get ); + ValidationTracker validation = new ValidationTracker( LootParameterSets.ALL_PARAMS, x -> null, tables::get ); registerLoot( ( id, table ) -> { - if( tables.containsKey( id ) ) validation.addProblem( "Duplicate loot tables for " + id ); + if( tables.containsKey( id ) ) validation.reportProblem( "Duplicate loot tables for " + id ); tables.put( id, table ); } ); - tables.forEach( ( key, value ) -> LootTableManager.func_227508_a_( validation, key, value ) ); + tables.forEach( ( key, value ) -> LootTableManager.validate( validation, key, value ) ); Multimap problems = validation.getProblems(); if( !problems.isEmpty() ) @@ -64,7 +64,7 @@ public abstract class LootTableProvider implements IDataProvider Path path = getPath( key ); try { - IDataProvider.save( GSON, cache, LootTableManager.toJson( value ), path ); + IDataProvider.save( GSON, cache, LootTableManager.serialize( value ), path ); } catch( IOException e ) { diff --git a/src/main/java/dan200/computercraft/data/LootTables.java b/src/main/java/dan200/computercraft/data/LootTables.java index df7d1c8ed..9c3f9639e 100644 --- a/src/main/java/dan200/computercraft/data/LootTables.java +++ b/src/main/java/dan200/computercraft/data/LootTables.java @@ -47,8 +47,8 @@ public class LootTables extends LootTableProvider computerDrop( add, Registry.ModBlocks.TURTLE_ADVANCED ); add.accept( ComputerCraftProxyCommon.ForgeHandlers.LOOT_TREASURE_DISK, LootTable - .builder() - .setParameterSet( LootParameterSets.GENERIC ) + .lootTable() + .setParamSet( LootParameterSets.ALL_PARAMS ) .build() ); } @@ -56,13 +56,13 @@ public class LootTables extends LootTableProvider { Block block = wrapper.get(); add.accept( block.getLootTable(), LootTable - .builder() - .setParameterSet( LootParameterSets.BLOCK ) - .addLootPool( LootPool.builder() + .lootTable() + .setParamSet( LootParameterSets.BLOCK ) + .withPool( LootPool.lootPool() .name( "main" ) - .rolls( ConstantRange.of( 1 ) ) - .addEntry( ItemLootEntry.builder( block ) ) - .acceptCondition( SurvivesExplosion.builder() ) + .setRolls( ConstantRange.exactly( 1 ) ) + .add( ItemLootEntry.lootTableItem( block ) ) + .when( SurvivesExplosion.survivesExplosion() ) ).build() ); } @@ -70,16 +70,16 @@ public class LootTables extends LootTableProvider { Block block = wrapper.get(); add.accept( block.getLootTable(), LootTable - .builder() - .setParameterSet( LootParameterSets.BLOCK ) - .addLootPool( LootPool.builder() + .lootTable() + .setParamSet( LootParameterSets.BLOCK ) + .withPool( LootPool.lootPool() .name( "main" ) - .rolls( ConstantRange.of( 1 ) ) - .addEntry( DynamicLootEntry.func_216162_a( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) ) - .acceptCondition( Alternative.builder( + .setRolls( ConstantRange.exactly( 1 ) ) + .add( DynamicLootEntry.dynamicEntry( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) ) + .when( Alternative.alternative( BlockNamedEntityLootCondition.builder(), HasComputerIdLootCondition.builder(), - PlayerCreativeLootCondition.builder().inverted() + PlayerCreativeLootCondition.builder().invert() ) ) ).build() ); } diff --git a/src/main/java/dan200/computercraft/data/RecipeWrapper.java b/src/main/java/dan200/computercraft/data/RecipeWrapper.java index 8fd20d3b5..160a24ec6 100644 --- a/src/main/java/dan200/computercraft/data/RecipeWrapper.java +++ b/src/main/java/dan200/computercraft/data/RecipeWrapper.java @@ -50,42 +50,42 @@ public final class RecipeWrapper implements IFinishedRecipe } @Override - public void serialize( @Nonnull JsonObject jsonObject ) + public void serializeRecipeData( @Nonnull JsonObject jsonObject ) { - recipe.serialize( jsonObject ); + recipe.serializeRecipeData( jsonObject ); if( resultData != null ) { - JsonObject object = JSONUtils.getJsonObject( jsonObject, "result" ); + JsonObject object = JSONUtils.getAsJsonObject( jsonObject, "result" ); object.addProperty( "nbt", resultData.toString() ); } } @Nonnull @Override - public ResourceLocation getID() + public ResourceLocation getId() { - return recipe.getID(); + return recipe.getId(); } @Nonnull @Override - public IRecipeSerializer getSerializer() + public IRecipeSerializer getType() { return serializer; } @Nullable @Override - public JsonObject getAdvancementJson() + public JsonObject serializeAdvancement() { - return recipe.getAdvancementJson(); + return recipe.serializeAdvancement(); } @Nullable @Override - public ResourceLocation getAdvancementID() + public ResourceLocation getAdvancementId() { - return recipe.getAdvancementID(); + return recipe.getAdvancementId(); } } diff --git a/src/main/java/dan200/computercraft/data/Recipes.java b/src/main/java/dan200/computercraft/data/Recipes.java index 6c1b62dae..d8b294170 100644 --- a/src/main/java/dan200/computercraft/data/Recipes.java +++ b/src/main/java/dan200/computercraft/data/Recipes.java @@ -39,7 +39,7 @@ public class Recipes extends RecipeProvider } @Override - protected void registerRecipes( @Nonnull Consumer add ) + protected void buildShapelessRecipes( @Nonnull Consumer add ) { basicRecipes( add ); diskColours( add ); @@ -57,13 +57,13 @@ public class Recipes extends RecipeProvider for( Colour colour : Colour.VALUES ) { ShapelessRecipeBuilder - .shapelessRecipe( Registry.ModItems.DISK.get() ) - .addIngredient( Tags.Items.DUSTS_REDSTONE ) - .addIngredient( Items.PAPER ) - .addIngredient( DyeItem.getItem( ofColour( colour ) ) ) - .setGroup( "computercraft:disk" ) - .addCriterion( "has_drive", inventoryChange( Registry.ModBlocks.DISK_DRIVE.get() ) ) - .build( RecipeWrapper.wrap( + .shapeless( Registry.ModItems.DISK.get() ) + .requires( Tags.Items.DUSTS_REDSTONE ) + .requires( Items.PAPER ) + .requires( DyeItem.byColor( ofColour( colour ) ) ) + .group( "computercraft:disk" ) + .unlocks( "has_drive", inventoryChange( Registry.ModBlocks.DISK_DRIVE.get() ) ) + .save( RecipeWrapper.wrap( ImpostorShapelessRecipe.SERIALIZER, add, x -> x.putInt( IColouredItem.NBT_COLOUR, colour.getHex() ) ), new ResourceLocation( ComputerCraft.MOD_ID, "disk_" + (colour.ordinal() + 1) ) ); @@ -87,14 +87,14 @@ public class Recipes extends RecipeProvider TurtleUpgrades.getVanillaUpgrades().forEach( upgrade -> { ItemStack result = TurtleItemFactory.create( -1, null, -1, family, null, upgrade, -1, null ); ShapedRecipeBuilder - .shapedRecipe( result.getItem() ) - .setGroup( String.format( "%s:turtle_%s", ComputerCraft.MOD_ID, nameId ) ) - .patternLine( "#T" ) - .key( '#', base.getItem() ) - .key( 'T', upgrade.getCraftingItem().getItem() ) - .addCriterion( "has_items", + .shaped( result.getItem() ) + .group( String.format( "%s:turtle_%s", ComputerCraft.MOD_ID, nameId ) ) + .pattern( "#T" ) + .define( '#', base.getItem() ) + .define( 'T', upgrade.getCraftingItem().getItem() ) + .unlocks( "has_items", inventoryChange( base.getItem(), upgrade.getCraftingItem().getItem() ) ) - .build( + .save( RecipeWrapper.wrap( ImpostorRecipe.SERIALIZER, add, result.getTag() ), new ResourceLocation( ComputerCraft.MOD_ID, String.format( "turtle_%s/%s/%s", nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath() @@ -121,15 +121,15 @@ public class Recipes extends RecipeProvider PocketUpgrades.getVanillaUpgrades().forEach( upgrade -> { ItemStack result = PocketComputerItemFactory.create( -1, null, -1, family, null ); ShapedRecipeBuilder - .shapedRecipe( result.getItem() ) - .setGroup( String.format( "%s:pocket_%s", ComputerCraft.MOD_ID, nameId ) ) - .patternLine( "#" ) - .patternLine( "P" ) - .key( '#', base.getItem() ) - .key( 'P', upgrade.getCraftingItem().getItem() ) - .addCriterion( "has_items", + .shaped( result.getItem() ) + .group( String.format( "%s:pocket_%s", ComputerCraft.MOD_ID, nameId ) ) + .pattern( "#" ) + .pattern( "P" ) + .define( '#', base.getItem() ) + .define( 'P', upgrade.getCraftingItem().getItem() ) + .unlocks( "has_items", inventoryChange( base.getItem(), upgrade.getCraftingItem().getItem() ) ) - .build( + .save( RecipeWrapper.wrap( ImpostorRecipe.SERIALIZER, add, result.getTag() ), new ResourceLocation( ComputerCraft.MOD_ID, String.format( "pocket_%s/%s/%s", nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath() @@ -142,167 +142,167 @@ public class Recipes extends RecipeProvider private void basicRecipes( @Nonnull Consumer add ) { ShapedRecipeBuilder - .shapedRecipe( Registry.ModItems.CABLE.get(), 6 ) - .patternLine( " # " ) - .patternLine( "#R#" ) - .patternLine( " # " ) - .key( '#', Tags.Items.STONE ) - .key( 'R', Tags.Items.DUSTS_REDSTONE ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .addCriterion( "has_modem", inventoryChange( CCTags.COMPUTER ) ) - .build( add ); + .shaped( Registry.ModItems.CABLE.get(), 6 ) + .pattern( " # " ) + .pattern( "#R#" ) + .pattern( " # " ) + .define( '#', Tags.Items.STONE ) + .define( 'R', Tags.Items.DUSTS_REDSTONE ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .unlocks( "has_modem", inventoryChange( CCTags.COMPUTER ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.COMPUTER_NORMAL.get() ) - .patternLine( "###" ) - .patternLine( "#R#" ) - .patternLine( "#G#" ) - .key( '#', Tags.Items.STONE ) - .key( 'R', Tags.Items.DUSTS_REDSTONE ) - .key( 'G', Tags.Items.GLASS_PANES ) - .addCriterion( "has_redstone", inventoryChange( Tags.Items.DUSTS_REDSTONE ) ) - .build( add ); + .shaped( Registry.ModBlocks.COMPUTER_NORMAL.get() ) + .pattern( "###" ) + .pattern( "#R#" ) + .pattern( "#G#" ) + .define( '#', Tags.Items.STONE ) + .define( 'R', Tags.Items.DUSTS_REDSTONE ) + .define( 'G', Tags.Items.GLASS_PANES ) + .unlocks( "has_redstone", inventoryChange( Tags.Items.DUSTS_REDSTONE ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.COMPUTER_ADVANCED.get() ) - .patternLine( "###" ) - .patternLine( "#R#" ) - .patternLine( "#G#" ) - .key( '#', Tags.Items.INGOTS_GOLD ) - .key( 'R', Tags.Items.DUSTS_REDSTONE ) - .key( 'G', Tags.Items.GLASS_PANES ) - .addCriterion( "has_components", inventoryChange( Items.REDSTONE, Items.GOLD_INGOT ) ) - .build( add ); + .shaped( Registry.ModBlocks.COMPUTER_ADVANCED.get() ) + .pattern( "###" ) + .pattern( "#R#" ) + .pattern( "#G#" ) + .define( '#', Tags.Items.INGOTS_GOLD ) + .define( 'R', Tags.Items.DUSTS_REDSTONE ) + .define( 'G', Tags.Items.GLASS_PANES ) + .unlocks( "has_components", inventoryChange( Items.REDSTONE, Items.GOLD_INGOT ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.COMPUTER_COMMAND.get() ) - .patternLine( "###" ) - .patternLine( "#R#" ) - .patternLine( "#G#" ) - .key( '#', Tags.Items.INGOTS_GOLD ) - .key( 'R', Blocks.COMMAND_BLOCK ) - .key( 'G', Tags.Items.GLASS_PANES ) - .addCriterion( "has_components", inventoryChange( Blocks.COMMAND_BLOCK ) ) - .build( add ); + .shaped( Registry.ModBlocks.COMPUTER_COMMAND.get() ) + .pattern( "###" ) + .pattern( "#R#" ) + .pattern( "#G#" ) + .define( '#', Tags.Items.INGOTS_GOLD ) + .define( 'R', Blocks.COMMAND_BLOCK ) + .define( 'G', Tags.Items.GLASS_PANES ) + .unlocks( "has_components", inventoryChange( Blocks.COMMAND_BLOCK ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.DISK_DRIVE.get() ) - .patternLine( "###" ) - .patternLine( "#R#" ) - .patternLine( "#R#" ) - .key( '#', Tags.Items.STONE ) - .key( 'R', Tags.Items.DUSTS_REDSTONE ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .build( add ); + .shaped( Registry.ModBlocks.DISK_DRIVE.get() ) + .pattern( "###" ) + .pattern( "#R#" ) + .pattern( "#R#" ) + .define( '#', Tags.Items.STONE ) + .define( 'R', Tags.Items.DUSTS_REDSTONE ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.MONITOR_NORMAL.get() ) - .patternLine( "###" ) - .patternLine( "#G#" ) - .patternLine( "###" ) - .key( '#', Tags.Items.STONE ) - .key( 'G', Tags.Items.GLASS_PANES ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .build( add ); + .shaped( Registry.ModBlocks.MONITOR_NORMAL.get() ) + .pattern( "###" ) + .pattern( "#G#" ) + .pattern( "###" ) + .define( '#', Tags.Items.STONE ) + .define( 'G', Tags.Items.GLASS_PANES ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.MONITOR_ADVANCED.get(), 4 ) - .patternLine( "###" ) - .patternLine( "#G#" ) - .patternLine( "###" ) - .key( '#', Tags.Items.INGOTS_GOLD ) - .key( 'G', Tags.Items.GLASS_PANES ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .build( add ); + .shaped( Registry.ModBlocks.MONITOR_ADVANCED.get(), 4 ) + .pattern( "###" ) + .pattern( "#G#" ) + .pattern( "###" ) + .define( '#', Tags.Items.INGOTS_GOLD ) + .define( 'G', Tags.Items.GLASS_PANES ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModItems.POCKET_COMPUTER_NORMAL.get() ) - .patternLine( "###" ) - .patternLine( "#A#" ) - .patternLine( "#G#" ) - .key( '#', Tags.Items.STONE ) - .key( 'A', Items.GOLDEN_APPLE ) - .key( 'G', Tags.Items.GLASS_PANES ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .addCriterion( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) ) - .build( add ); + .shaped( Registry.ModItems.POCKET_COMPUTER_NORMAL.get() ) + .pattern( "###" ) + .pattern( "#A#" ) + .pattern( "#G#" ) + .define( '#', Tags.Items.STONE ) + .define( 'A', Items.GOLDEN_APPLE ) + .define( 'G', Tags.Items.GLASS_PANES ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .unlocks( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModItems.POCKET_COMPUTER_ADVANCED.get() ) - .patternLine( "###" ) - .patternLine( "#A#" ) - .patternLine( "#G#" ) - .key( '#', Tags.Items.INGOTS_GOLD ) - .key( 'A', Items.GOLDEN_APPLE ) - .key( 'G', Tags.Items.GLASS_PANES ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .addCriterion( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) ) - .build( add ); + .shaped( Registry.ModItems.POCKET_COMPUTER_ADVANCED.get() ) + .pattern( "###" ) + .pattern( "#A#" ) + .pattern( "#G#" ) + .define( '#', Tags.Items.INGOTS_GOLD ) + .define( 'A', Items.GOLDEN_APPLE ) + .define( 'G', Tags.Items.GLASS_PANES ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .unlocks( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.PRINTER.get() ) - .patternLine( "###" ) - .patternLine( "#R#" ) - .patternLine( "#D#" ) - .key( '#', Tags.Items.STONE ) - .key( 'R', Tags.Items.DUSTS_REDSTONE ) - .key( 'D', Tags.Items.DYES ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .build( add ); + .shaped( Registry.ModBlocks.PRINTER.get() ) + .pattern( "###" ) + .pattern( "#R#" ) + .pattern( "#D#" ) + .define( '#', Tags.Items.STONE ) + .define( 'R', Tags.Items.DUSTS_REDSTONE ) + .define( 'D', Tags.Items.DYES ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.SPEAKER.get() ) - .patternLine( "###" ) - .patternLine( "#N#" ) - .patternLine( "#R#" ) - .key( '#', Tags.Items.STONE ) - .key( 'N', Blocks.NOTE_BLOCK ) - .key( 'R', Tags.Items.DUSTS_REDSTONE ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .build( add ); + .shaped( Registry.ModBlocks.SPEAKER.get() ) + .pattern( "###" ) + .pattern( "#N#" ) + .pattern( "#R#" ) + .define( '#', Tags.Items.STONE ) + .define( 'N', Blocks.NOTE_BLOCK ) + .define( 'R', Tags.Items.DUSTS_REDSTONE ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModItems.WIRED_MODEM.get() ) - .patternLine( "###" ) - .patternLine( "#R#" ) - .patternLine( "###" ) - .key( '#', Tags.Items.STONE ) - .key( 'R', Tags.Items.DUSTS_REDSTONE ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .addCriterion( "has_cable", inventoryChange( Registry.ModItems.CABLE.get() ) ) - .build( add ); + .shaped( Registry.ModItems.WIRED_MODEM.get() ) + .pattern( "###" ) + .pattern( "#R#" ) + .pattern( "###" ) + .define( '#', Tags.Items.STONE ) + .define( 'R', Tags.Items.DUSTS_REDSTONE ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .unlocks( "has_cable", inventoryChange( Registry.ModItems.CABLE.get() ) ) + .save( add ); ShapelessRecipeBuilder - .shapelessRecipe( Registry.ModBlocks.WIRED_MODEM_FULL.get() ) - .addIngredient( Registry.ModItems.WIRED_MODEM.get() ) - .addCriterion( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) ) - .build( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_from" ) ); + .shapeless( Registry.ModBlocks.WIRED_MODEM_FULL.get() ) + .requires( Registry.ModItems.WIRED_MODEM.get() ) + .unlocks( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) ) + .save( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_from" ) ); ShapelessRecipeBuilder - .shapelessRecipe( Registry.ModItems.WIRED_MODEM.get() ) - .addIngredient( Registry.ModBlocks.WIRED_MODEM_FULL.get() ) - .addCriterion( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) ) - .build( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_to" ) ); + .shapeless( Registry.ModItems.WIRED_MODEM.get() ) + .requires( Registry.ModBlocks.WIRED_MODEM_FULL.get() ) + .unlocks( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) ) + .save( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_to" ) ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) - .patternLine( "###" ) - .patternLine( "#E#" ) - .patternLine( "###" ) - .key( '#', Tags.Items.STONE ) - .key( 'E', Tags.Items.ENDER_PEARLS ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .build( add ); + .shaped( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) + .pattern( "###" ) + .pattern( "#E#" ) + .pattern( "###" ) + .define( '#', Tags.Items.STONE ) + .define( 'E', Tags.Items.ENDER_PEARLS ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .save( add ); ShapedRecipeBuilder - .shapedRecipe( Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get() ) - .patternLine( "###" ) - .patternLine( "#E#" ) - .patternLine( "###" ) - .key( '#', Tags.Items.INGOTS_GOLD ) - .key( 'E', Items.ENDER_EYE ) - .addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) ) - .addCriterion( "has_wireless", inventoryChange( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) ) - .build( add ); + .shaped( Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get() ) + .pattern( "###" ) + .pattern( "#E#" ) + .pattern( "###" ) + .define( '#', Tags.Items.INGOTS_GOLD ) + .define( 'E', Items.ENDER_EYE ) + .unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) ) + .unlocks( "has_wireless", inventoryChange( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) ) + .save( add ); } private static DyeColor ofColour( Colour colour ) @@ -312,11 +312,11 @@ public class Recipes extends RecipeProvider private static InventoryChangeTrigger.Instance inventoryChange( Tag stack ) { - return InventoryChangeTrigger.Instance.forItems( ItemPredicate.Builder.create().tag( stack ).build() ); + return InventoryChangeTrigger.Instance.hasItem( ItemPredicate.Builder.item().of( stack ).build() ); } private static InventoryChangeTrigger.Instance inventoryChange( IItemProvider... stack ) { - return InventoryChangeTrigger.Instance.forItems( stack ); + return InventoryChangeTrigger.Instance.hasItem( stack ); } } diff --git a/src/main/java/dan200/computercraft/data/Tags.java b/src/main/java/dan200/computercraft/data/Tags.java index 2556e4fae..12f17b59e 100644 --- a/src/main/java/dan200/computercraft/data/Tags.java +++ b/src/main/java/dan200/computercraft/data/Tags.java @@ -32,15 +32,15 @@ public class Tags extends ItemTagsProvider } @Override - protected void registerTags() + protected void addTags() { - getBuilder( COMPUTER ) + tag( COMPUTER ) .add( Registry.ModItems.COMPUTER_NORMAL.get() ) .add( Registry.ModItems.COMPUTER_ADVANCED.get() ) .add( Registry.ModItems.COMPUTER_COMMAND.get() ); - getBuilder( TURTLE ).add( Registry.ModItems.TURTLE_NORMAL.get(), Registry.ModItems.TURTLE_ADVANCED.get() ); - getBuilder( WIRED_MODEM ).add( Registry.ModItems.WIRED_MODEM.get(), Registry.ModItems.WIRED_MODEM_FULL.get() ); - getBuilder( MONITOR ) + tag( TURTLE ).add( Registry.ModItems.TURTLE_NORMAL.get(), Registry.ModItems.TURTLE_ADVANCED.get() ); + tag( WIRED_MODEM ).add( Registry.ModItems.WIRED_MODEM.get(), Registry.ModItems.WIRED_MODEM_FULL.get() ); + tag( MONITOR ) .add( Registry.ModItems.MONITOR_NORMAL.get() ) .add( Registry.ModItems.MONITOR_ADVANCED.get() ); } diff --git a/src/main/java/dan200/computercraft/shared/BundledRedstone.java b/src/main/java/dan200/computercraft/shared/BundledRedstone.java index f2ae897a7..d6894fc2a 100644 --- a/src/main/java/dan200/computercraft/shared/BundledRedstone.java +++ b/src/main/java/dan200/computercraft/shared/BundledRedstone.java @@ -31,12 +31,12 @@ public final class BundledRedstone public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) { - return World.isValid( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1; + return World.isInWorldBounds( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1; } private static int getUnmaskedOutput( World world, BlockPos pos, Direction side ) { - if( !World.isValid( pos ) ) return -1; + if( !World.isInWorldBounds( pos ) ) return -1; // Try the providers in order: int combinedSignal = -1; diff --git a/src/main/java/dan200/computercraft/shared/Config.java b/src/main/java/dan200/computercraft/shared/Config.java index 4a61a226a..a3e43029b 100644 --- a/src/main/java/dan200/computercraft/shared/Config.java +++ b/src/main/java/dan200/computercraft/shared/Config.java @@ -31,6 +31,9 @@ import java.util.stream.Collectors; import static net.minecraftforge.common.ForgeConfigSpec.Builder; import static net.minecraftforge.common.ForgeConfigSpec.ConfigValue; +import net.minecraftforge.common.ForgeConfigSpec.Builder; +import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; + @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD ) public final class Config { diff --git a/src/main/java/dan200/computercraft/shared/Peripherals.java b/src/main/java/dan200/computercraft/shared/Peripherals.java index b30185de9..1f809ccb9 100644 --- a/src/main/java/dan200/computercraft/shared/Peripherals.java +++ b/src/main/java/dan200/computercraft/shared/Peripherals.java @@ -40,13 +40,13 @@ public final class Peripherals @Nullable public static IPeripheral getPeripheral( World world, BlockPos pos, Direction side, NonNullConsumer> invalidate ) { - return World.isValid( pos ) && !world.isRemote ? getPeripheralAt( world, pos, side, invalidate ) : null; + return World.isInWorldBounds( pos ) && !world.isClientSide ? getPeripheralAt( world, pos, side, invalidate ) : null; } @Nullable private static IPeripheral getPeripheralAt( World world, BlockPos pos, Direction side, NonNullConsumer> invalidate ) { - TileEntity block = world.getTileEntity( pos ); + TileEntity block = world.getBlockEntity( pos ); if( block != null ) { LazyOptional peripheral = block.getCapability( CAPABILITY_PERIPHERAL, side ); diff --git a/src/main/java/dan200/computercraft/shared/Registry.java b/src/main/java/dan200/computercraft/shared/Registry.java index 5bbdf3bec..dd9240465 100644 --- a/src/main/java/dan200/computercraft/shared/Registry.java +++ b/src/main/java/dan200/computercraft/shared/Registry.java @@ -96,17 +96,17 @@ public final class Registry private static Block.Properties properties() { - return Block.Properties.create( Material.ROCK ).hardnessAndResistance( 2 ); + return Block.Properties.of( Material.STONE ).strength( 2 ); } private static Block.Properties turtleProperties() { - return Block.Properties.create( Material.ROCK ).hardnessAndResistance( 2.5f ); + return Block.Properties.of( Material.STONE ).strength( 2.5f ); } private static Block.Properties modemProperties() { - return Block.Properties.create( Material.ROCK ).hardnessAndResistance( 1.5f ); + return Block.Properties.of( Material.STONE ).strength( 1.5f ); } public static final RegistryObject COMPUTER_NORMAL = BLOCKS.register( "computer_normal", @@ -115,7 +115,7 @@ public final class Registry () -> new BlockComputer( properties(), ComputerFamily.ADVANCED, ModTiles.COMPUTER_ADVANCED ) ); public static final RegistryObject COMPUTER_COMMAND = BLOCKS.register( "computer_command", () -> new BlockComputer( - Block.Properties.create( Material.ROCK ).hardnessAndResistance( -1, 6000000.0F ), + Block.Properties.of( Material.STONE ).strength( -1, 6000000.0F ), ComputerFamily.COMMAND, ModTiles.COMPUTER_COMMAND ) ); @@ -187,7 +187,7 @@ public final class Registry private static Item.Properties properties() { - return new Item.Properties().group( mainItemGroup ); + return new Item.Properties().tab( mainItemGroup ); } private static RegistryObject ofBlock( RegistryObject parent, BiFunction supplier ) @@ -200,24 +200,24 @@ public final class Registry public static final RegistryObject COMPUTER_COMMAND = ofBlock( ModBlocks.COMPUTER_COMMAND, ItemComputer::new ); public static final RegistryObject POCKET_COMPUTER_NORMAL = ITEMS.register( "pocket_computer_normal", - () -> new ItemPocketComputer( properties().maxStackSize( 1 ), ComputerFamily.NORMAL ) ); + () -> new ItemPocketComputer( properties().stacksTo( 1 ), ComputerFamily.NORMAL ) ); public static final RegistryObject POCKET_COMPUTER_ADVANCED = ITEMS.register( "pocket_computer_advanced", - () -> new ItemPocketComputer( properties().maxStackSize( 1 ), ComputerFamily.ADVANCED ) ); + () -> new ItemPocketComputer( properties().stacksTo( 1 ), ComputerFamily.ADVANCED ) ); public static final RegistryObject TURTLE_NORMAL = ofBlock( ModBlocks.TURTLE_NORMAL, ItemTurtle::new ); public static final RegistryObject TURTLE_ADVANCED = ofBlock( ModBlocks.TURTLE_ADVANCED, ItemTurtle::new ); public static final RegistryObject DISK = - ITEMS.register( "disk", () -> new ItemDisk( properties().maxStackSize( 1 ) ) ); + ITEMS.register( "disk", () -> new ItemDisk( properties().stacksTo( 1 ) ) ); public static final RegistryObject TREASURE_DISK = - ITEMS.register( "treasure_disk", () -> new ItemTreasureDisk( properties().maxStackSize( 1 ) ) ); + ITEMS.register( "treasure_disk", () -> new ItemTreasureDisk( properties().stacksTo( 1 ) ) ); public static final RegistryObject PRINTED_PAGE = ITEMS.register( "printed_page", - () -> new ItemPrintout( properties().maxStackSize( 1 ), ItemPrintout.Type.PAGE ) ); + () -> new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.PAGE ) ); public static final RegistryObject PRINTED_PAGES = ITEMS.register( "printed_pages", - () -> new ItemPrintout( properties().maxStackSize( 1 ), ItemPrintout.Type.PAGES ) ); + () -> new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.PAGES ) ); public static final RegistryObject PRINTED_BOOK = ITEMS.register( "printed_book", - () -> new ItemPrintout( properties().maxStackSize( 1 ), ItemPrintout.Type.BOOK ) ); + () -> new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.BOOK ) ); public static final RegistryObject SPEAKER = ofBlock( ModBlocks.SPEAKER, BlockItem::new ); public static final RegistryObject DISK_DRIVE = ofBlock( ModBlocks.DISK_DRIVE, BlockItem::new ); @@ -284,10 +284,10 @@ public final class Registry static final DeferredRegister> ENTITIES = new DeferredRegister<>( ForgeRegistries.ENTITIES, ComputerCraft.MOD_ID ); public static final RegistryObject> TURTLE_PLAYER = ENTITIES.register( "turtle_player", () -> - EntityType.Builder.create( EntityClassification.MISC ) - .disableSerialization() - .disableSummoning() - .size( 0, 0 ) + EntityType.Builder.createNothing( EntityClassification.MISC ) + .noSave() + .noSummon() + .sized( 0, 0 ) .build( ComputerCraft.MOD_ID + ":turtle_player" ) ); } diff --git a/src/main/java/dan200/computercraft/shared/TurtlePermissions.java b/src/main/java/dan200/computercraft/shared/TurtlePermissions.java index 4593035d9..7fd6b9b6a 100644 --- a/src/main/java/dan200/computercraft/shared/TurtlePermissions.java +++ b/src/main/java/dan200/computercraft/shared/TurtlePermissions.java @@ -20,13 +20,13 @@ public final class TurtlePermissions public static boolean isBlockEnterable( World world, BlockPos pos, PlayerEntity player ) { MinecraftServer server = world.getServer(); - return server == null || world.isRemote || !server.isBlockProtected( world, pos, player ); + return server == null || world.isClientSide || !server.isUnderSpawnProtection( world, pos, player ); } public static boolean isBlockEditable( World world, BlockPos pos, PlayerEntity player ) { MinecraftServer server = world.getServer(); - return server == null || world.isRemote || !server.isBlockProtected( world, pos, player ); + return server == null || world.isClientSide || !server.isUnderSpawnProtection( world, pos, player ); } @SubscribeEvent diff --git a/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java b/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java index 95617d03d..33ae57947 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java @@ -75,13 +75,13 @@ public final class CommandComputerCraft List computers = new ArrayList<>( ComputerCraft.serverComputerRegistry.getComputers() ); // Unless we're on a server, limit the number of rows we can send. - World world = source.getWorld(); - BlockPos pos = new BlockPos( source.getPos() ); + World world = source.getLevel(); + BlockPos pos = new BlockPos( source.getPosition() ); computers.sort( ( a, b ) -> { if( a.getWorld() == b.getWorld() && a.getWorld() == world ) { - return Double.compare( a.getPosition().distanceSq( pos ), b.getPosition().distanceSq( pos ) ); + return Double.compare( a.getPosition().distSqr( pos ), b.getPosition().distSqr( pos ) ); } else if( a.getWorld() == world ) { @@ -145,7 +145,7 @@ public final class CommandComputerCraft if( computer.isOn() ) shutdown++; computer.shutdown(); } - context.getSource().sendFeedback( translate( "commands.computercraft.shutdown.done", shutdown, computers.size() ), false ); + context.getSource().sendSuccess( translate( "commands.computercraft.shutdown.done", shutdown, computers.size() ), false ); return shutdown; } ) ) @@ -159,7 +159,7 @@ public final class CommandComputerCraft if( !computer.isOn() ) on++; computer.turnOn(); } - context.getSource().sendFeedback( translate( "commands.computercraft.turn_on.done", on, computers.size() ), false ); + context.getSource().sendSuccess( translate( "commands.computercraft.turn_on.done", on, computers.size() ), false ); return on; } ) ) @@ -173,20 +173,20 @@ public final class CommandComputerCraft if( world == null || pos == null ) throw TP_NOT_THERE.create(); - Entity entity = context.getSource().assertIsEntity(); + Entity entity = context.getSource().getEntityOrException(); if( !(entity instanceof ServerPlayerEntity) ) throw TP_NOT_PLAYER.create(); ServerPlayerEntity player = (ServerPlayerEntity) entity; - if( player.getEntityWorld() == world ) + if( player.getCommandSenderWorld() == world ) { - player.connection.setPlayerLocation( + player.connection.teleport( pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0, EnumSet.noneOf( SPlayerPositionLookPacket.Flags.class ) ); } else { - player.teleport( (ServerWorld) world, + player.teleportTo( (ServerWorld) world, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0 ); } @@ -219,7 +219,7 @@ public final class CommandComputerCraft .requires( UserLevel.OP ) .arg( "computer", oneComputer() ) .executes( context -> { - ServerPlayerEntity player = context.getSource().asPlayer(); + ServerPlayerEntity player = context.getSource().getPlayerOrException(); ServerComputer computer = getComputerArgument( context, "computer" ); new ViewComputerContainerData( computer ).open( player, new INamedContainerProvider() { @@ -247,7 +247,7 @@ public final class CommandComputerCraft getTimingContext( context.getSource() ).start(); String stopCommand = "/computercraft track stop"; - context.getSource().sendFeedback( translate( "commands.computercraft.track.start.stop", + context.getSource().sendSuccess( translate( "commands.computercraft.track.start.stop", link( text( stopCommand ), stopCommand, translate( "commands.computercraft.track.stop.action" ) ) ), false ); return 1; } ) ) @@ -288,11 +288,11 @@ public final class CommandComputerCraft // Append the computer instance if( serverComputer == null ) { - out.appendSibling( text( "?" ) ); + out.append( text( "?" ) ); } else { - out.appendSibling( link( + out.append( link( text( Integer.toString( serverComputer.getInstanceID() ) ), "/computercraft dump " + serverComputer.getInstanceID(), translate( "commands.computercraft.dump.action" ) @@ -300,20 +300,20 @@ public final class CommandComputerCraft } // And ID - out.appendText( " (id " + computerId + ")" ); + out.append( " (id " + computerId + ")" ); // And, if we're a player, some useful links if( serverComputer != null && UserLevel.OP.test( source ) && isPlayer( source ) ) { out - .appendText( " " ) - .appendSibling( link( + .append( " " ) + .append( link( text( "\u261b" ), "/computercraft tp " + serverComputer.getInstanceID(), translate( "commands.computercraft.tp.action" ) ) ) - .appendText( " " ) - .appendSibling( link( + .append( " " ) + .append( link( text( "\u20e2" ), "/computercraft view " + serverComputer.getInstanceID(), translate( "commands.computercraft.view.action" ) @@ -343,7 +343,7 @@ public final class CommandComputerCraft private static TrackingContext getTimingContext( CommandSource source ) { Entity entity = source.getEntity(); - return entity instanceof PlayerEntity ? Tracking.getContext( entity.getUniqueID() ) : Tracking.getContext( SYSTEM_UUID ); + return entity instanceof PlayerEntity ? Tracking.getContext( entity.getUUID() ) : Tracking.getContext( SYSTEM_UUID ); } private static final List DEFAULT_FIELDS = Arrays.asList( TrackingField.TASKS, TrackingField.TOTAL_TIME, TrackingField.AVERAGE_TIME, TrackingField.MAX_TIME ); diff --git a/src/main/java/dan200/computercraft/shared/command/CommandCopy.java b/src/main/java/dan200/computercraft/shared/command/CommandCopy.java index b5d1a9b80..435346c20 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandCopy.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandCopy.java @@ -38,7 +38,7 @@ public final class CommandCopy .then( literal( "copy" ) ) .then( argument( "message", StringArgumentType.greedyString() ) ) .executes( context -> { - Minecraft.getInstance().keyboardListener.setClipboardString( context.getArgument( "message", String.class ) ); + Minecraft.getInstance().keyboardHandler.setClipboard( context.getArgument( "message", String.class ) ); return 1; } ) ); @@ -50,7 +50,7 @@ public final class CommandCopy // Emulate the command on the client side if( event.getMessage().startsWith( PREFIX ) ) { - Minecraft.getInstance().keyboardListener.setClipboardString( event.getMessage().substring( PREFIX.length() ) ); + Minecraft.getInstance().keyboardHandler.setClipboard( event.getMessage().substring( PREFIX.length() ) ); event.setCanceled( true ); } } diff --git a/src/main/java/dan200/computercraft/shared/command/CommandUtils.java b/src/main/java/dan200/computercraft/shared/command/CommandUtils.java index 199ebb45a..85dc4d566 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandUtils.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandUtils.java @@ -45,7 +45,7 @@ public final class CommandUtils } else { - return ((ISuggestionProvider) source).getSuggestionsFromServer( (CommandContext) context, builder ); + return ((ISuggestionProvider) source).customSuggestion( (CommandContext) context, builder ); } } diff --git a/src/main/java/dan200/computercraft/shared/command/UserLevel.java b/src/main/java/dan200/computercraft/shared/command/UserLevel.java index 3d6885f2e..2492bd119 100644 --- a/src/main/java/dan200/computercraft/shared/command/UserLevel.java +++ b/src/main/java/dan200/computercraft/shared/command/UserLevel.java @@ -61,12 +61,12 @@ public enum UserLevel implements Predicate MinecraftServer server = source.getServer(); Entity sender = source.getEntity(); - if( server.isSinglePlayer() && sender instanceof PlayerEntity && + if( server.isSingleplayer() && sender instanceof PlayerEntity && ((PlayerEntity) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() ) ) { if( this == OWNER || this == OWNER_OP ) return true; } - return source.hasPermissionLevel( toLevel() ); + return source.hasPermission( toLevel() ); } } diff --git a/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java b/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java index 7bdef6342..2262871e3 100644 --- a/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java +++ b/src/main/java/dan200/computercraft/shared/command/arguments/ComputersArgumentType.java @@ -175,20 +175,20 @@ public final class ComputersArgumentType implements ArgumentType implements ArgumentType> public static class Serializer implements IArgumentSerializer> { @Override - public void write( @Nonnull RepeatArgumentType arg, @Nonnull PacketBuffer buf ) + public void serializeToNetwork( @Nonnull RepeatArgumentType arg, @Nonnull PacketBuffer buf ) { buf.writeBoolean( arg.flatten ); ArgumentTypes.serialize( buf, arg.child ); - buf.writeTextComponent( getMessage( arg ) ); + buf.writeComponent( getMessage( arg ) ); } @Nonnull @Override @SuppressWarnings( { "unchecked", "rawtypes" } ) - public RepeatArgumentType read( @Nonnull PacketBuffer buf ) + public RepeatArgumentType deserializeFromNetwork( @Nonnull PacketBuffer buf ) { boolean isList = buf.readBoolean(); ArgumentType child = ArgumentTypes.deserialize( buf ); - ITextComponent message = buf.readTextComponent(); + ITextComponent message = buf.readComponent(); BiConsumer, ?> appender = isList ? ( list, x ) -> list.addAll( (Collection) x ) : List::add; return new RepeatArgumentType( child, appender, isList, new SimpleCommandExceptionType( message ) ); } @Override - public void write( @Nonnull RepeatArgumentType arg, @Nonnull JsonObject json ) + public void serializeToJson( @Nonnull RepeatArgumentType arg, @Nonnull JsonObject json ) { json.addProperty( "flatten", arg.flatten ); json.addProperty( "child", "<>" ); // TODO: Potentially serialize this using reflection. diff --git a/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java b/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java index 793a75136..96f253f7e 100644 --- a/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java +++ b/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java @@ -151,7 +151,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder context ) { - context.getSource().sendFeedback( getHelp( context, node, id, command ), false ); + context.getSource().sendSuccess( getHelp( context, node, id, command ), false ); return 0; } } @@ -159,7 +159,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder helpForChild( CommandNode node, String id, String command ) { return context -> { - context.getSource().sendFeedback( getHelp( context, node, id + "." + node.getName().replace( '-', '_' ), command + " " + node.getName() ), false ); + context.getSource().sendSuccess( getHelp( context, node, id + "." + node.getName().replace( '-', '_' ), command + " " + node.getName() ), false ); return 0; }; } @@ -168,17 +168,17 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder dispatcher = context.getSource().getServer().getCommandManager().getDispatcher(); + CommandDispatcher dispatcher = context.getSource().getServer().getCommands().getDispatcher(); CommandNode temp = new LiteralCommandNode<>( "_", null, x -> true, null, null, false ); temp.addChild( node ); String usage = dispatcher.getSmartUsage( temp, context.getSource() ).get( node ).substring( node.getName().length() ); ITextComponent output = new StringTextComponent( "" ) - .appendSibling( coloured( "/" + command + usage, HEADER ) ) - .appendText( " " ) - .appendSibling( coloured( translate( "commands." + id + ".synopsis" ), SYNOPSIS ) ) - .appendText( "\n" ) - .appendSibling( translate( "commands." + id + ".desc" ) ); + .append( coloured( "/" + command + usage, HEADER ) ) + .append( " " ) + .append( coloured( translate( "commands." + id + ".synopsis" ), SYNOPSIS ) ) + .append( "\n" ) + .append( translate( "commands." + id + ".desc" ) ); for( CommandNode child : node.getChildren() ) { @@ -187,16 +187,16 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder> type; @@ -36,22 +38,22 @@ public abstract class BlockGeneric extends Block @Override @Deprecated - public final void onReplaced( @Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool ) + public final void onRemove( @Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool ) { if( block.getBlock() == replace.getBlock() ) return; - TileEntity tile = world.getTileEntity( pos ); - super.onReplaced( block, world, pos, replace, bool ); - world.removeTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); + super.onRemove( block, world, pos, replace, bool ); + world.removeBlockEntity( pos ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).destroy(); } @Nonnull @Override @Deprecated - public final ActionResultType onBlockActivated( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult hit ) + public final ActionResultType use( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult hit ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); return tile instanceof TileGeneric ? ((TileGeneric) tile).onActivate( player, hand, hit ) : ActionResultType.PASS; } @@ -59,14 +61,14 @@ public abstract class BlockGeneric extends Block @Deprecated public final void neighborChanged( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, @Nonnull Block neighbourBlock, @Nonnull BlockPos neighbourPos, boolean isMoving ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos ); } @Override public final void onNeighborChange( BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbour ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourTileEntityChange( neighbour ); } @@ -74,7 +76,7 @@ public abstract class BlockGeneric extends Block @Deprecated public void tick( @Nonnull BlockState state, ServerWorld world, @Nonnull BlockPos pos, @Nonnull Random rand ) { - TileEntity te = world.getTileEntity( pos ); + TileEntity te = world.getBlockEntity( pos ); if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick(); } diff --git a/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java index 25a1bf4a6..130767be9 100644 --- a/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java +++ b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java @@ -30,9 +30,9 @@ public final class ColourableRecipe extends SpecialRecipe { boolean hasColourable = false; boolean hasDye = false; - for( int i = 0; i < inv.getSizeInventory(); i++ ) + for( int i = 0; i < inv.getContainerSize(); i++ ) { - ItemStack stack = inv.getStackInSlot( i ); + ItemStack stack = inv.getItem( i ); if( stack.isEmpty() ) continue; if( stack.getItem() instanceof IColouredItem ) @@ -55,15 +55,15 @@ public final class ColourableRecipe extends SpecialRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inv ) + public ItemStack assemble( @Nonnull CraftingInventory inv ) { ItemStack colourable = ItemStack.EMPTY; ColourTracker tracker = new ColourTracker(); - for( int i = 0; i < inv.getSizeInventory(); i++ ) + for( int i = 0; i < inv.getContainerSize(); i++ ) { - ItemStack stack = inv.getStackInSlot( i ); + ItemStack stack = inv.getItem( i ); if( stack.isEmpty() ) continue; @@ -83,7 +83,7 @@ public final class ColourableRecipe extends SpecialRecipe } @Override - public boolean canFit( int x, int y ) + public boolean canCraftInDimensions( int x, int y ) { return x >= 2 && y >= 2; } diff --git a/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java b/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java index c9826a32a..6a7830b1a 100644 --- a/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java +++ b/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java @@ -29,7 +29,7 @@ public class ContainerHeldItem extends Container super( type, id ); this.hand = hand; - stack = player.getHeldItem( hand ).copy(); + stack = player.getItemInHand( hand ).copy(); } public static ContainerHeldItem createPrintout( int id, PlayerInventory inventory, HeldItemContainerData data ) @@ -44,11 +44,11 @@ public class ContainerHeldItem extends Container } @Override - public boolean canInteractWith( @Nonnull PlayerEntity player ) + public boolean stillValid( @Nonnull PlayerEntity player ) { if( !player.isAlive() ) return false; - ItemStack stack = player.getHeldItem( hand ); + ItemStack stack = player.getItemInHand( hand ); return stack == this.stack || !stack.isEmpty() && !this.stack.isEmpty() && stack.getItem() == this.stack.getItem(); } @@ -61,7 +61,7 @@ public class ContainerHeldItem extends Container public Factory( ContainerType type, ItemStack stack, Hand hand ) { this.type = type; - this.name = stack.getDisplayName(); + this.name = stack.getHoverName(); this.hand = hand; } diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index e787bdf13..ffb0685da 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -32,10 +32,10 @@ public abstract class TileGeneric extends TileEntity public final void updateBlock() { - markDirty(); - BlockPos pos = getPos(); + setChanged(); + BlockPos pos = getBlockPos(); BlockState state = getBlockState(); - getWorld().notifyBlockUpdate( pos, state, state, 3 ); + getLevel().sendBlockUpdated( pos, state, state, 3 ); } @Nonnull @@ -63,13 +63,13 @@ public abstract class TileGeneric extends TileEntity public boolean isUsable( PlayerEntity player, boolean ignoreRange ) { - if( player == null || !player.isAlive() || getWorld().getTileEntity( getPos() ) != this ) return false; + if( player == null || !player.isAlive() || getLevel().getBlockEntity( getBlockPos() ) != this ) return false; if( ignoreRange ) return true; double range = getInteractRange( player ); - BlockPos pos = getPos(); - return player.getEntityWorld() == getWorld() && - player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range; + BlockPos pos = getBlockPos(); + return player.getCommandSenderWorld() == getLevel() && + player.distanceToSqr( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range; } protected void writeDescription( @Nonnull CompoundNBT nbt ) @@ -86,13 +86,13 @@ public abstract class TileGeneric extends TileEntity { CompoundNBT nbt = new CompoundNBT(); writeDescription( nbt ); - return new SUpdateTileEntityPacket( pos, 0, nbt ); + return new SUpdateTileEntityPacket( worldPosition, 0, nbt ); } @Override public final void onDataPacket( NetworkManager net, SUpdateTileEntityPacket packet ) { - if( packet.getTileEntityType() == 0 ) readDescription( packet.getNbtCompound() ); + if( packet.getType() == 0 ) readDescription( packet.getTag() ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java index 2788e5368..16e2e839f 100644 --- a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java +++ b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java @@ -48,18 +48,18 @@ public class CommandAPI implements ILuaAPI private Object[] doCommand( String command ) { - MinecraftServer server = computer.getWorld().getServer(); + MinecraftServer server = computer.getLevel().getServer(); if( server == null || !server.isCommandBlockEnabled() ) { return new Object[] { false, createOutput( "Command blocks disabled by server" ) }; } - Commands commandManager = server.getCommandManager(); + Commands commandManager = server.getCommands(); TileCommandComputer.CommandReceiver receiver = computer.getReceiver(); try { receiver.clearOutput(); - int result = commandManager.handleCommand( computer.getSource(), command ); + int result = commandManager.performCommand( computer.getSource(), command ); return new Object[] { result > 0, receiver.copyOutput(), result }; } catch( Throwable t ) @@ -75,8 +75,8 @@ public class CommandAPI implements ILuaAPI BlockState state = world.getBlockState( pos ); Map table = BlockData.fill( new HashMap<>(), state ); - TileEntity tile = world.getTileEntity( pos ); - if( tile != null ) table.put( "nbt", NBTUtil.toLua( tile.write( new CompoundNBT() ) ) ); + TileEntity tile = world.getBlockEntity( pos ); + if( tile != null ) table.put( "nbt", NBTUtil.toLua( tile.save( new CompoundNBT() ) ) ); return table; } @@ -139,10 +139,10 @@ public class CommandAPI implements ILuaAPI @LuaFunction( mainThread = true ) public final List list( IArguments args ) throws LuaException { - MinecraftServer server = computer.getWorld().getServer(); + MinecraftServer server = computer.getLevel().getServer(); if( server == null ) return Collections.emptyList(); - CommandNode node = server.getCommandManager().getDispatcher().getRoot(); + CommandNode node = server.getCommands().getDispatcher().getRoot(); for( int j = 0; j < args.count(); j++ ) { String name = args.getString( j ); @@ -171,7 +171,7 @@ public class CommandAPI implements ILuaAPI public final Object[] getBlockPosition() { // This is probably safe to do on the Lua thread. Probably. - BlockPos pos = computer.getPos(); + BlockPos pos = computer.getBlockPos(); return new Object[] { pos.getX(), pos.getY(), pos.getZ() }; } @@ -198,7 +198,7 @@ public class CommandAPI implements ILuaAPI public final List> getBlockInfos( int minX, int minY, int minZ, int maxX, int maxY, int maxZ ) throws LuaException { // Get the details of the block - World world = computer.getWorld(); + World world = computer.getLevel(); BlockPos min = new BlockPos( Math.min( minX, maxX ), Math.min( minY, maxY ), @@ -209,7 +209,7 @@ public class CommandAPI implements ILuaAPI Math.max( minY, maxY ), Math.max( minZ, maxZ ) ); - if( !World.isValid( min ) || !World.isValid( max ) ) + if( !World.isInWorldBounds( min ) || !World.isInWorldBounds( max ) ) { throw new LuaException( "Co-ordinates out of range" ); } @@ -250,9 +250,9 @@ public class CommandAPI implements ILuaAPI public final Map getBlockInfo( int x, int y, int z ) throws LuaException { // Get the details of the block - World world = computer.getWorld(); + World world = computer.getLevel(); BlockPos position = new BlockPos( x, y, z ); - if( World.isValid( position ) ) + if( World.isInWorldBounds( position ) ) { return getBlockInfo( world, position ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java index 37e4a58af..e6daec420 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java @@ -23,6 +23,8 @@ import net.minecraftforge.fml.RegistryObject; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.block.Block.Properties; + public class BlockComputer extends BlockComputerBase { public static final EnumProperty STATE = EnumProperty.create( "state", ComputerState.class ); @@ -31,14 +33,14 @@ public class BlockComputer extends BlockComputerBase public BlockComputer( Properties settings, ComputerFamily family, RegistryObject> type ) { super( settings, family, type ); - setDefaultState( getDefaultState() - .with( FACING, Direction.NORTH ) - .with( STATE, ComputerState.OFF ) + registerDefaultState( defaultBlockState() + .setValue( FACING, Direction.NORTH ) + .setValue( STATE, ComputerState.OFF ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void createBlockStateDefinition( StateContainer.Builder builder ) { builder.add( FACING, STATE ); } @@ -47,7 +49,7 @@ public class BlockComputer extends BlockComputerBase @Override public BlockState getStateForPlacement( BlockItemUseContext placement ) { - return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); + return defaultBlockState().setValue( FACING, placement.getHorizontalDirection().getOpposite() ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java index ef1f29f82..75f3e3a08 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java @@ -34,6 +34,8 @@ import net.minecraftforge.fml.RegistryObject; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.block.Block.Properties; + public abstract class BlockComputerBase extends BlockGeneric implements IBundledRedstoneBlock { private static final ResourceLocation DROP = new ResourceLocation( ComputerCraft.MOD_ID, "computer" ); @@ -48,26 +50,26 @@ public abstract class BlockComputerBase extends Bloc @Override @Deprecated - public void onBlockAdded( @Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState oldState, boolean isMoving ) + public void onPlace( @Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState oldState, boolean isMoving ) { - super.onBlockAdded( state, world, pos, oldState, isMoving ); + super.onPlace( state, world, pos, oldState, isMoving ); - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileComputerBase ) ((TileComputerBase) tile).updateInput(); } @Override @Deprecated - public boolean canProvidePower( @Nonnull BlockState state ) + public boolean isSignalSource( @Nonnull BlockState state ) { return true; } @Override @Deprecated - public int getStrongPower( @Nonnull BlockState state, IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction incomingSide ) + public int getDirectSignal( @Nonnull BlockState state, IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction incomingSide ) { - TileEntity entity = world.getTileEntity( pos ); + TileEntity entity = world.getBlockEntity( pos ); if( !(entity instanceof TileComputerBase) ) return 0; TileComputerBase computerEntity = (TileComputerBase) entity; @@ -88,9 +90,9 @@ public abstract class BlockComputerBase extends Bloc @Override @Deprecated - public int getWeakPower( @Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction incomingSide ) + public int getSignal( @Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction incomingSide ) { - return getStrongPower( state, world, pos, incomingSide ); + return getDirectSignal( state, world, pos, incomingSide ); } @Override @@ -102,7 +104,7 @@ public abstract class BlockComputerBase extends Bloc @Override public int getBundledRedstoneOutput( World world, BlockPos pos, Direction side ) { - TileEntity entity = world.getTileEntity( pos ); + TileEntity entity = world.getBlockEntity( pos ); if( !(entity instanceof TileComputerBase) ) return 0; TileComputerBase computerEntity = (TileComputerBase) entity; @@ -117,7 +119,7 @@ public abstract class BlockComputerBase extends Bloc @Override public ItemStack getPickBlock( BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos, PlayerEntity player ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileComputerBase ) { ItemStack result = getItem( (TileComputerBase) tile ); @@ -128,48 +130,48 @@ public abstract class BlockComputerBase extends Bloc } @Override - public void harvestBlock( @Nonnull World world, PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity tile, @Nonnull ItemStack tool ) + public void playerDestroy( @Nonnull World world, PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity tile, @Nonnull ItemStack tool ) { // Don't drop blocks here - see onBlockHarvested. - player.addStat( Stats.BLOCK_MINED.get( this ) ); - player.addExhaustion( 0.005F ); + player.awardStat( Stats.BLOCK_MINED.get( this ) ); + player.causeFoodExhaustion( 0.005F ); } @Override - public void onBlockHarvested( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull PlayerEntity player ) + public void playerWillDestroy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull PlayerEntity player ) { if( !(world instanceof ServerWorld) ) return; // We drop the item here instead of doing it in the harvest method, as we should // drop computers for creative players too. - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileComputerBase ) { TileComputerBase computer = (TileComputerBase) tile; LootContext.Builder context = new LootContext.Builder( (ServerWorld) world ) - .withRandom( world.rand ) - .withParameter( LootParameters.POSITION, pos ) - .withParameter( LootParameters.TOOL, player.getHeldItemMainhand() ) + .withRandom( world.random ) + .withParameter( LootParameters.BLOCK_POS, pos ) + .withParameter( LootParameters.TOOL, player.getMainHandItem() ) .withParameter( LootParameters.THIS_ENTITY, player ) - .withNullableParameter( LootParameters.BLOCK_ENTITY, tile ) + .withOptionalParameter( LootParameters.BLOCK_ENTITY, tile ) .withDynamicDrop( DROP, ( ctx, out ) -> out.accept( getItem( computer ) ) ); for( ItemStack item : state.getDrops( context ) ) { - spawnAsEntity( world, pos, item ); + popResource( world, pos, item ); } - state.spawnAdditionalDrops( world, pos, player.getHeldItemMainhand() ); + state.spawnAfterBreak( world, pos, player.getMainHandItem() ); } } @Override - public void onBlockPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack ) + public void setPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack ) { - super.onBlockPlacedBy( world, pos, state, placer, stack ); + super.setPlacedBy( world, pos, state, placer, stack ); - TileEntity tile = world.getTileEntity( pos ); - if( !world.isRemote && tile instanceof IComputerTile && stack.getItem() instanceof IComputerItem ) + TileEntity tile = world.getBlockEntity( pos ); + if( !world.isClientSide && tile instanceof IComputerTile && stack.getItem() instanceof IComputerItem ) { IComputerTile computer = (IComputerTile) tile; IComputerItem item = (IComputerItem) stack.getItem(); diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java index 951dd6091..2dfabd43d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java @@ -54,21 +54,21 @@ public class TileCommandComputer extends TileComputer } @Override - public boolean shouldReceiveFeedback() + public boolean acceptsSuccess() { - return getWorld().getGameRules().getBoolean( GameRules.SEND_COMMAND_FEEDBACK ); + return getLevel().getGameRules().getBoolean( GameRules.RULE_SENDCOMMANDFEEDBACK ); } @Override - public boolean shouldReceiveErrors() + public boolean acceptsFailure() { return true; } @Override - public boolean allowLogging() + public boolean shouldInformAdmins() { - return getWorld().getGameRules().getBoolean( GameRules.COMMAND_BLOCK_OUTPUT ); + return getLevel().getGameRules().getBoolean( GameRules.RULE_COMMANDBLOCKOUTPUT ); } } @@ -96,10 +96,10 @@ public class TileCommandComputer extends TileComputer } return new CommandSource( receiver, - new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ), Vec2f.ZERO, - (ServerWorld) getWorld(), 2, + new Vec3d( worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5 ), Vec2f.ZERO, + (ServerWorld) getLevel(), 2, name, new StringTextComponent( name ), - getWorld().getServer(), null + getLevel().getServer(), null ); } @@ -122,12 +122,12 @@ public class TileCommandComputer extends TileComputer MinecraftServer server = player.getServer(); if( server == null || !server.isCommandBlockEnabled() ) { - player.sendStatusMessage( new TranslationTextComponent( "advMode.notEnabled" ), true ); + player.displayClientMessage( new TranslationTextComponent( "advMode.notEnabled" ), true ); return false; } - else if( ComputerCraft.commandRequireCreative ? !player.canUseCommandBlock() : !server.getPlayerList().canSendCommands( player.getGameProfile() ) ) + else if( ComputerCraft.commandRequireCreative ? !player.canUseGameMasterBlocks() : !server.getPlayerList().isOp( player.getGameProfile() ) ) { - player.sendStatusMessage( new TranslationTextComponent( "advMode.notAllowed" ), true ); + player.displayClientMessage( new TranslationTextComponent( "advMode.notAllowed" ), true ); return false; } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java index 03eea284e..23a4a7d6f 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java @@ -42,11 +42,11 @@ public class TileComputer extends TileComputerBase { ComputerFamily family = getFamily(); ServerComputer computer = new ServerComputer( - getWorld(), id, label, instanceID, family, + getLevel(), id, label, instanceID, family, ComputerCraft.computerTermWidth, ComputerCraft.computerTermHeight ); - computer.setPosition( getPos() ); + computer.setPosition( getBlockPos() ); return computer; } @@ -58,16 +58,16 @@ public class TileComputer extends TileComputerBase @Override public Direction getDirection() { - return getBlockState().get( BlockComputer.FACING ); + return getBlockState().getValue( BlockComputer.FACING ); } @Override protected void updateBlockState( ComputerState newState ) { BlockState existing = getBlockState(); - if( existing.get( BlockComputer.STATE ) != newState ) + if( existing.getValue( BlockComputer.STATE ) != newState ) { - getWorld().setBlockState( getPos(), existing.with( BlockComputer.STATE, newState ), 3 ); + getLevel().setBlock( getBlockPos(), existing.setValue( BlockComputer.STATE, newState ), 3 ); } } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java index 6179b5393..44b41d796 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -80,7 +80,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT { if( m_instanceID >= 0 ) { - if( !getWorld().isRemote ) ComputerCraft.serverComputerRegistry.remove( m_instanceID ); + if( !getLevel().isClientSide ) ComputerCraft.serverComputerRegistry.remove( m_instanceID ); m_instanceID = -1; } } @@ -91,7 +91,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT unload(); for( Direction dir : DirectionUtil.FACINGS ) { - RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); + RedstoneUtil.propagateRedstoneOutput( getLevel(), getBlockPos(), dir ); } } @@ -102,10 +102,10 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT } @Override - public void remove() + public void setRemoved() { unload(); - super.remove(); + super.setRemoved(); } protected boolean canNameWithTag( PlayerEntity player ) @@ -117,13 +117,13 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Override public ActionResultType onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { - ItemStack currentItem = player.getHeldItem( hand ); - if( !currentItem.isEmpty() && currentItem.getItem() == Items.NAME_TAG && canNameWithTag( player ) && currentItem.hasDisplayName() ) + ItemStack currentItem = player.getItemInHand( hand ); + if( !currentItem.isEmpty() && currentItem.getItem() == Items.NAME_TAG && canNameWithTag( player ) && currentItem.hasCustomHoverName() ) { // Label to rename computer - if( !getWorld().isRemote ) + if( !getLevel().isClientSide ) { - setLabel( currentItem.getDisplayName().getString() ); + setLabel( currentItem.getHoverName().getString() ); currentItem.shrink( 1 ); } return ActionResultType.SUCCESS; @@ -131,7 +131,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT else if( !player.isCrouching() ) { // Regular right click to activate computer - if( !getWorld().isRemote && isUsable( player, false ) ) + if( !getLevel().isClientSide && isUsable( player, false ) ) { createServerComputer().turnOn(); new ComputerContainerData( createServerComputer() ).open( player, this ); @@ -156,7 +156,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Override public void tick() { - if( !getWorld().isRemote ) + if( !getLevel().isClientSide ) { ServerComputer computer = createServerComputer(); if( computer == null ) return; @@ -189,20 +189,20 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Nonnull @Override - public CompoundNBT write( @Nonnull CompoundNBT nbt ) + public CompoundNBT save( @Nonnull CompoundNBT nbt ) { // Save ID, label and power state if( m_computerID >= 0 ) nbt.putInt( NBT_ID, m_computerID ); if( label != null ) nbt.putString( NBT_LABEL, label ); nbt.putBoolean( NBT_ON, m_on ); - return super.write( nbt ); + return super.save( nbt ); } @Override - public void read( @Nonnull CompoundNBT nbt ) + public void load( @Nonnull CompoundNBT nbt ) { - super.read( nbt ); + super.load( nbt ); // Load ID, label and power state m_computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; @@ -232,11 +232,11 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT Direction offsetSide = dir.getOpposite(); ComputerSide localDir = remapToLocalSide( dir ); - computer.setRedstoneInput( localDir, getRedstoneInput( world, offset, dir ) ); - computer.setBundledRedstoneInput( localDir, BundledRedstone.getOutput( getWorld(), offset, offsetSide ) ); + computer.setRedstoneInput( localDir, getRedstoneInput( level, offset, dir ) ); + computer.setBundledRedstoneInput( localDir, BundledRedstone.getOutput( getLevel(), offset, offsetSide ) ); if( !isPeripheralBlockedOnSide( localDir ) ) { - IPeripheral peripheral = Peripherals.getPeripheral( getWorld(), offset, offsetSide, invalidate[dir.ordinal()] ); + IPeripheral peripheral = Peripherals.getPeripheral( getLevel(), offset, offsetSide, invalidate[dir.ordinal()] ); computer.setPeripheral( localDir, peripheral ); } } @@ -252,18 +252,18 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT */ protected static int getRedstoneInput( World world, BlockPos pos, Direction side ) { - int power = world.getRedstonePower( pos, side ); + int power = world.getSignal( pos, side ); if( power >= 15 ) return power; BlockState neighbour = world.getBlockState( pos ); return neighbour.getBlock() == Blocks.REDSTONE_WIRE - ? Math.max( power, neighbour.get( RedstoneWireBlock.POWER ) ) + ? Math.max( power, neighbour.getValue( RedstoneWireBlock.POWER ) ) : power; } public void updateInput() { - if( getWorld() == null || getWorld().isRemote ) return; + if( getLevel() == null || getLevel().isClientSide ) return; // Update all sides ServerComputer computer = getServerComputer(); @@ -272,20 +272,20 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT BlockPos pos = computer.getPosition(); for( Direction dir : DirectionUtil.FACINGS ) { - updateSideInput( computer, dir, pos.offset( dir ) ); + updateSideInput( computer, dir, pos.relative( dir ) ); } } private void updateInput( BlockPos neighbour ) { - if( getWorld() == null || getWorld().isRemote ) return; + if( getLevel() == null || getLevel().isClientSide ) return; ServerComputer computer = getServerComputer(); if( computer == null ) return; for( Direction dir : DirectionUtil.FACINGS ) { - BlockPos offset = pos.offset( dir ); + BlockPos offset = worldPosition.relative( dir ); if( offset.equals( neighbour ) ) { updateSideInput( computer, dir, offset ); @@ -299,12 +299,12 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT private void updateInput( Direction dir ) { - if( getWorld() == null || getWorld().isRemote ) return; + if( getLevel() == null || getLevel().isClientSide ) return; ServerComputer computer = getServerComputer(); if( computer == null ) return; - updateSideInput( computer, dir, pos.offset( dir ) ); + updateSideInput( computer, dir, worldPosition.relative( dir ) ); } public void updateOutput() @@ -313,7 +313,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT updateBlock(); for( Direction dir : DirectionUtil.FACINGS ) { - RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); + RedstoneUtil.propagateRedstoneOutput( getLevel(), getBlockPos(), dir ); } } @@ -334,23 +334,23 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Override public final void setComputerID( int id ) { - if( getWorld().isRemote || m_computerID == id ) return; + if( getLevel().isClientSide || m_computerID == id ) return; m_computerID = id; ServerComputer computer = getServerComputer(); if( computer != null ) computer.setID( m_computerID ); - markDirty(); + setChanged(); } @Override public final void setLabel( String label ) { - if( getWorld().isRemote || Objects.equals( this.label, label ) ) return; + if( getLevel().isClientSide || Objects.equals( this.label, label ) ) return; this.label = label; ServerComputer computer = getServerComputer(); if( computer != null ) computer.setLabel( label ); - markDirty(); + setChanged(); } @Override @@ -361,7 +361,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT public ServerComputer createServerComputer() { - if( getWorld().isRemote ) return null; + if( getLevel().isClientSide ) return null; boolean changed = false; if( m_instanceID < 0 ) @@ -386,7 +386,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT public ServerComputer getServerComputer() { - return getWorld().isRemote ? null : ComputerCraft.serverComputerRegistry.get( m_instanceID ); + return getLevel().isClientSide ? null : ComputerCraft.serverComputerRegistry.get( m_instanceID ); } // Networking stuff @@ -428,7 +428,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT { return hasCustomName() ? new StringTextComponent( label ) - : new TranslationTextComponent( getBlockState().getBlock().getTranslationKey() ); + : new TranslationTextComponent( getBlockState().getBlock().getDescriptionId() ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java b/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java index 2b6ccc039..46a382c78 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ComputerState.java @@ -24,7 +24,7 @@ public enum ComputerState implements IStringSerializable @Nonnull @Override - public String getName() + public String getSerializedName() { return name; } diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java index 4d1db3f23..a54893384 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java @@ -368,7 +368,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput { if( player == null ) return null; - Container container = player.openContainer; + Container container = player.containerMenu; if( !(container instanceof IContainerComputer) ) return null; IContainerComputer computerContainer = (IContainerComputer) container; diff --git a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputerBase.java index a84f1a4fc..492aafab7 100644 --- a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputerBase.java @@ -40,7 +40,7 @@ public class ContainerComputerBase extends Container implements IContainerComput protected static IComputer getComputer( PlayerInventory player, ComputerContainerData data ) { int id = data.getInstanceId(); - if( !player.player.world.isRemote ) return ComputerCraft.serverComputerRegistry.get( id ); + if( !player.player.level.isClientSide ) return ComputerCraft.serverComputerRegistry.get( id ); ClientComputer computer = ComputerCraft.clientComputerRegistry.get( id ); if( computer == null ) ComputerCraft.clientComputerRegistry.add( id, computer = new ClientComputer( id ) ); @@ -48,7 +48,7 @@ public class ContainerComputerBase extends Container implements IContainerComput } @Override - public boolean canInteractWith( @Nonnull PlayerEntity player ) + public boolean stillValid( @Nonnull PlayerEntity player ) { return canUse.test( player ); } @@ -74,9 +74,9 @@ public class ContainerComputerBase extends Container implements IContainerComput } @Override - public void onContainerClosed( @Nonnull PlayerEntity player ) + public void removed( @Nonnull PlayerEntity player ) { - super.onContainerClosed( player ); + super.removed( player ); input.close(); } } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java b/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java index 3f4f03de3..26a74bd6b 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java @@ -23,7 +23,7 @@ public interface IComputerItem default String getLabel( @Nonnull ItemStack stack ) { - return stack.hasDisplayName() ? stack.getDisplayName().getString() : null; + return stack.hasCustomHoverName() ? stack.getHoverName().getString() : null; } ComputerFamily getFamily(); diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java index 1dd01ea2b..caab0cbaf 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java @@ -12,6 +12,8 @@ import net.minecraft.util.text.StringTextComponent; import javax.annotation.Nonnull; +import net.minecraft.item.Item.Properties; + public class ItemComputer extends ItemComputerBase { public ItemComputer( BlockComputer block, Properties settings ) @@ -23,7 +25,7 @@ public class ItemComputer extends ItemComputerBase { ItemStack result = new ItemStack( this ); if( id >= 0 ) result.getOrCreateTag().putInt( NBT_ID, id ); - if( label != null ) result.setDisplayName( new StringTextComponent( label ) ); + if( label != null ) result.setHoverName( new StringTextComponent( label ) ); return result; } @@ -31,7 +33,7 @@ public class ItemComputer extends ItemComputerBase public ItemStack withFamily( @Nonnull ItemStack stack, @Nonnull ComputerFamily family ) { ItemStack result = ComputerItemFactory.create( getComputerID( stack ), null, family ); - if( stack.hasDisplayName() ) result.setDisplayName( stack.getDisplayName() ); + if( stack.hasCustomHoverName() ) result.setHoverName( stack.getHoverName() ); return result; } } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java index 501ae9826..e2ed053a5 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java @@ -24,6 +24,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; +import net.minecraft.item.Item.Properties; + public abstract class ItemComputerBase extends BlockItem implements IComputerItem, IMedia { private final ComputerFamily family; @@ -35,7 +37,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte } @Override - public void addInformation( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, @Nonnull ITooltipFlag options ) + public void appendHoverText( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, @Nonnull ITooltipFlag options ) { if( options.isAdvanced() || getLabel( stack ) == null ) { @@ -43,7 +45,7 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte if( id >= 0 ) { list.add( new TranslationTextComponent( "gui.computercraft.tooltip.computer_id", id ) - .applyTextStyle( TextFormatting.GRAY ) ); + .withStyle( TextFormatting.GRAY ) ); } } } @@ -67,11 +69,11 @@ public abstract class ItemComputerBase extends BlockItem implements IComputerIte { if( label != null ) { - stack.setDisplayName( new StringTextComponent( label ) ); + stack.setHoverName( new StringTextComponent( label ) ); } else { - stack.clearCustomName(); + stack.resetHoverName(); } return true; } diff --git a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerConvertRecipe.java b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerConvertRecipe.java index 830efb4f7..7a5d6e4e3 100644 --- a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerConvertRecipe.java +++ b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerConvertRecipe.java @@ -37,9 +37,9 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe { if( !super.matches( inventory, world ) ) return false; - for( int i = 0; i < inventory.getSizeInventory(); i++ ) + for( int i = 0; i < inventory.getContainerSize(); i++ ) { - if( inventory.getStackInSlot( i ).getItem() instanceof IComputerItem ) return true; + if( inventory.getItem( i ).getItem() instanceof IComputerItem ) return true; } return false; @@ -47,12 +47,12 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) + public ItemStack assemble( @Nonnull CraftingInventory inventory ) { // Find our computer item and convert it. - for( int i = 0; i < inventory.getSizeInventory(); i++ ) + for( int i = 0; i < inventory.getContainerSize(); i++ ) { - ItemStack stack = inventory.getStackInSlot( i ); + ItemStack stack = inventory.getItem( i ); if( stack.getItem() instanceof IComputerItem ) return convert( (IComputerItem) stack.getItem(), stack ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerFamilyRecipe.java b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerFamilyRecipe.java index b82869dfa..2f7562c4b 100644 --- a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerFamilyRecipe.java +++ b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerFamilyRecipe.java @@ -39,42 +39,42 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe @Nonnull @Override - public T read( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json ) + public T fromJson( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json ) { - String group = JSONUtils.getString( json, "group", "" ); + String group = JSONUtils.getAsString( json, "group", "" ); ComputerFamily family = RecipeUtil.getFamily( json, "family" ); RecipeUtil.ShapedTemplate template = RecipeUtil.getTemplate( json ); - ItemStack result = deserializeItem( JSONUtils.getJsonObject( json, "result" ) ); + ItemStack result = itemFromJson( JSONUtils.getAsJsonObject( json, "result" ) ); return create( identifier, group, template.width, template.height, template.ingredients, result, family ); } @Nonnull @Override - public T read( @Nonnull ResourceLocation identifier, @Nonnull PacketBuffer buf ) + public T fromNetwork( @Nonnull ResourceLocation identifier, @Nonnull PacketBuffer buf ) { int width = buf.readVarInt(); int height = buf.readVarInt(); - String group = buf.readString( Short.MAX_VALUE ); + String group = buf.readUtf( Short.MAX_VALUE ); NonNullList ingredients = NonNullList.withSize( width * height, Ingredient.EMPTY ); - for( int i = 0; i < ingredients.size(); i++ ) ingredients.set( i, Ingredient.read( buf ) ); + for( int i = 0; i < ingredients.size(); i++ ) ingredients.set( i, Ingredient.fromNetwork( buf ) ); - ItemStack result = buf.readItemStack(); - ComputerFamily family = buf.readEnumValue( ComputerFamily.class ); + ItemStack result = buf.readItem(); + ComputerFamily family = buf.readEnum( ComputerFamily.class ); return create( identifier, group, width, height, ingredients, result, family ); } @Override - public void write( @Nonnull PacketBuffer buf, @Nonnull T recipe ) + public void toNetwork( @Nonnull PacketBuffer buf, @Nonnull T recipe ) { buf.writeVarInt( recipe.getWidth() ); buf.writeVarInt( recipe.getHeight() ); - buf.writeString( recipe.getGroup() ); - for( Ingredient ingredient : recipe.getIngredients() ) ingredient.write( buf ); - buf.writeItemStack( recipe.getRecipeOutput() ); - buf.writeEnumValue( recipe.getFamily() ); + buf.writeUtf( recipe.getGroup() ); + for( Ingredient ingredient : recipe.getIngredients() ) ingredient.toNetwork( buf ); + buf.writeItem( recipe.getResultItem() ); + buf.writeEnum( recipe.getFamily() ); } } } diff --git a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java index cd50542ff..35d7d8c7a 100644 --- a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java @@ -15,6 +15,8 @@ import net.minecraft.util.ResourceLocation; import javax.annotation.Nonnull; +import dan200.computercraft.shared.computer.recipe.ComputerFamilyRecipe.Serializer; + public class ComputerUpgradeRecipe extends ComputerFamilyRecipe { public ComputerUpgradeRecipe( ResourceLocation identifier, String group, int width, int height, NonNullList ingredients, ItemStack result, ComputerFamily family ) diff --git a/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java b/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java index 27e4cae7f..8597b7eae 100644 --- a/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java +++ b/src/main/java/dan200/computercraft/shared/data/BlockNamedEntityLootCondition.java @@ -16,6 +16,8 @@ import javax.annotation.Nonnull; import java.util.Collections; import java.util.Set; +import net.minecraft.world.storage.loot.conditions.ILootCondition.IBuilder; + /** * A loot condition which checks if the tile entity has a name. */ @@ -30,13 +32,13 @@ public final class BlockNamedEntityLootCondition implements ILootCondition @Override public boolean test( LootContext lootContext ) { - TileEntity tile = lootContext.get( LootParameters.BLOCK_ENTITY ); + TileEntity tile = lootContext.getParamOrNull( LootParameters.BLOCK_ENTITY ); return tile instanceof INameable && ((INameable) tile).hasCustomName(); } @Nonnull @Override - public Set> getRequiredParameters() + public Set> getReferencedContextParams() { return Collections.singleton( LootParameters.BLOCK_ENTITY ); } diff --git a/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java b/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java index 1f16abec0..e734bf836 100644 --- a/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java +++ b/src/main/java/dan200/computercraft/shared/data/HasComputerIdLootCondition.java @@ -16,6 +16,8 @@ import javax.annotation.Nonnull; import java.util.Collections; import java.util.Set; +import net.minecraft.world.storage.loot.conditions.ILootCondition.IBuilder; + /** * A loot condition which checks if the tile entity has has a non-0 ID. */ @@ -30,13 +32,13 @@ public final class HasComputerIdLootCondition implements ILootCondition @Override public boolean test( LootContext lootContext ) { - TileEntity tile = lootContext.get( LootParameters.BLOCK_ENTITY ); + TileEntity tile = lootContext.getParamOrNull( LootParameters.BLOCK_ENTITY ); return tile instanceof IComputerTile && ((IComputerTile) tile).getComputerID() >= 0; } @Nonnull @Override - public Set> getRequiredParameters() + public Set> getReferencedContextParams() { return Collections.singleton( LootParameters.BLOCK_ENTITY ); } diff --git a/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java b/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java index e777cfb26..346634b6e 100644 --- a/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java +++ b/src/main/java/dan200/computercraft/shared/data/PlayerCreativeLootCondition.java @@ -16,6 +16,8 @@ import javax.annotation.Nonnull; import java.util.Collections; import java.util.Set; +import net.minecraft.world.storage.loot.conditions.ILootCondition.IBuilder; + /** * A loot condition which checks if the entity is in creative mode. */ @@ -30,13 +32,13 @@ public final class PlayerCreativeLootCondition implements ILootCondition @Override public boolean test( LootContext lootContext ) { - Entity entity = lootContext.get( LootParameters.THIS_ENTITY ); - return entity instanceof PlayerEntity && ((PlayerEntity) entity).abilities.isCreativeMode; + Entity entity = lootContext.getParamOrNull( LootParameters.THIS_ENTITY ); + return entity instanceof PlayerEntity && ((PlayerEntity) entity).abilities.instabuild; } @Nonnull @Override - public Set> getRequiredParameters() + public Set> getReferencedContextParams() { return Collections.singleton( LootParameters.THIS_ENTITY ); } diff --git a/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java b/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java index 0bed3e75c..a3a4810d6 100644 --- a/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java +++ b/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java @@ -32,8 +32,8 @@ import net.minecraft.util.ResourceLocation; import javax.annotation.Nonnull; import java.util.*; -import static net.minecraft.item.crafting.Ingredient.fromStacks; -import static net.minecraft.util.NonNullList.from; +import static net.minecraft.item.crafting.Ingredient.of; +import static net.minecraft.util.NonNullList.of; class RecipeResolver implements IRecipeManagerPlugin { @@ -158,18 +158,18 @@ class RecipeResolver implements IRecipeManagerPlugin if( left != null && right != null ) return Collections.emptyList(); List recipes = new ArrayList<>(); - Ingredient ingredient = fromStacks( stack ); + Ingredient ingredient = of( stack ); for( UpgradeInfo upgrade : turtleUpgrades ) { // The turtle is facing towards us, so upgrades on the left are actually crafted on the right. if( left == null ) { - recipes.add( horizontal( from( Ingredient.EMPTY, ingredient, upgrade.ingredient ), turtleWith( stack, upgrade.turtle, right ) ) ); + recipes.add( horizontal( of( Ingredient.EMPTY, ingredient, upgrade.ingredient ), turtleWith( stack, upgrade.turtle, right ) ) ); } if( right == null ) { - recipes.add( horizontal( from( Ingredient.EMPTY, upgrade.ingredient, ingredient ), turtleWith( stack, left, upgrade.turtle ) ) ); + recipes.add( horizontal( of( Ingredient.EMPTY, upgrade.ingredient, ingredient ), turtleWith( stack, left, upgrade.turtle ) ) ); } } @@ -182,10 +182,10 @@ class RecipeResolver implements IRecipeManagerPlugin if( back != null ) return Collections.emptyList(); List recipes = new ArrayList<>(); - Ingredient ingredient = fromStacks( stack ); + Ingredient ingredient = of( stack ); for( UpgradeInfo upgrade : pocketUpgrades ) { - recipes.add( vertical( from( Ingredient.EMPTY, ingredient, upgrade.ingredient ), pocketWith( stack, upgrade.pocket ) ) ); + recipes.add( vertical( of( Ingredient.EMPTY, ingredient, upgrade.ingredient ), pocketWith( stack, upgrade.pocket ) ) ); } return recipes; @@ -240,7 +240,7 @@ class RecipeResolver implements IRecipeManagerPlugin if( left != null ) { recipes.add( horizontal( - from( Ingredient.EMPTY, fromStacks( turtleWith( stack, null, right ) ), fromStacks( left.getCraftingItem() ) ), + of( Ingredient.EMPTY, of( turtleWith( stack, null, right ) ), of( left.getCraftingItem() ) ), stack ) ); } @@ -248,7 +248,7 @@ class RecipeResolver implements IRecipeManagerPlugin if( right != null ) { recipes.add( horizontal( - from( Ingredient.EMPTY, fromStacks( right.getCraftingItem() ), fromStacks( turtleWith( stack, left, null ) ) ), + of( Ingredient.EMPTY, of( right.getCraftingItem() ), of( turtleWith( stack, left, null ) ) ), stack ) ); } @@ -263,7 +263,7 @@ class RecipeResolver implements IRecipeManagerPlugin if( back != null ) { recipes.add( vertical( - from( Ingredient.EMPTY, fromStacks( back.getCraftingItem() ), fromStacks( pocketWith( stack, null ) ) ), + of( Ingredient.EMPTY, of( back.getCraftingItem() ), of( pocketWith( stack, null ) ) ), stack ) ); } @@ -346,7 +346,7 @@ class RecipeResolver implements IRecipeManagerPlugin UpgradeInfo( ItemStack stack, ITurtleUpgrade turtle ) { this.stack = stack; - this.ingredient = fromStacks( stack ); + this.ingredient = of( stack ); this.upgrade = this.turtle = turtle; this.pocket = null; } @@ -354,7 +354,7 @@ class RecipeResolver implements IRecipeManagerPlugin UpgradeInfo( ItemStack stack, IPocketUpgrade pocket ) { this.stack = stack; - this.ingredient = fromStacks( stack ); + this.ingredient = of( stack ); this.turtle = null; this.upgrade = this.pocket = pocket; } @@ -370,7 +370,7 @@ class RecipeResolver implements IRecipeManagerPlugin if( turtle != null && TurtleUpgrades.suitableForFamily( family, turtle ) ) { recipes.add( horizontal( - from( Ingredient.EMPTY, ingredient, fromStacks( TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null ) ) ), + of( Ingredient.EMPTY, ingredient, of( TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null ) ) ), TurtleItemFactory.create( -1, null, -1, family, null, turtle, 0, null ) ) ); } @@ -378,7 +378,7 @@ class RecipeResolver implements IRecipeManagerPlugin if( pocket != null ) { recipes.add( vertical( - from( Ingredient.EMPTY, ingredient, fromStacks( PocketComputerItemFactory.create( -1, null, -1, family, null ) ) ), + of( Ingredient.EMPTY, ingredient, of( PocketComputerItemFactory.create( -1, null, -1, family, null ) ) ), PocketComputerItemFactory.create( -1, null, -1, family, pocket ) ) ); } diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java b/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java index 2394b3e1b..b62396e3d 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java @@ -31,6 +31,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; +import net.minecraft.item.Item.Properties; + public class ItemDisk extends Item implements IMedia, IColouredItem { private static final String NBT_ID = "DiskId"; @@ -51,9 +53,9 @@ public class ItemDisk extends Item implements IMedia, IColouredItem } @Override - public void fillItemGroup( @Nonnull ItemGroup tabs, @Nonnull NonNullList list ) + public void fillItemCategory( @Nonnull ItemGroup tabs, @Nonnull NonNullList list ) { - if( !isInGroup( tabs ) ) return; + if( !allowdedIn( tabs ) ) return; for( int colour = 0; colour < 16; colour++ ) { list.add( createFromIDAndColour( -1, null, Colour.VALUES[colour].getHex() ) ); @@ -61,7 +63,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem } @Override - public void addInformation( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, ITooltipFlag options ) + public void appendHoverText( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, ITooltipFlag options ) { if( options.isAdvanced() ) { @@ -69,7 +71,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem if( id >= 0 ) { list.add( new TranslationTextComponent( "gui.computercraft.tooltip.disk_id", id ) - .applyTextStyle( TextFormatting.GRAY ) ); + .withStyle( TextFormatting.GRAY ) ); } } } @@ -83,7 +85,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem @Override public String getLabel( @Nonnull ItemStack stack ) { - return stack.hasDisplayName() ? stack.getDisplayName().getString() : null; + return stack.hasCustomHoverName() ? stack.getHoverName().getString() : null; } @Override @@ -91,11 +93,11 @@ public class ItemDisk extends Item implements IMedia, IColouredItem { if( label != null ) { - stack.setDisplayName( new StringTextComponent( label ) ); + stack.setHoverName( new StringTextComponent( label ) ); } else { - stack.clearCustomName(); + stack.resetHoverName(); } return true; } diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java index c54efc754..52be0cfe4 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java @@ -23,6 +23,8 @@ import net.minecraft.world.World; import javax.annotation.Nonnull; import java.util.List; +import net.minecraft.item.Item.Properties; + public class ItemPrintout extends Item { private static final String NBT_TITLE = "Title"; @@ -50,7 +52,7 @@ public class ItemPrintout extends Item } @Override - public void addInformation( @Nonnull ItemStack stack, World world, @Nonnull List list, @Nonnull ITooltipFlag options ) + public void appendHoverText( @Nonnull ItemStack stack, World world, @Nonnull List list, @Nonnull ITooltipFlag options ) { String title = getTitle( stack ); if( title != null && !title.isEmpty() ) list.add( new StringTextComponent( title ) ); @@ -58,14 +60,14 @@ public class ItemPrintout extends Item @Nonnull @Override - public ActionResult onItemRightClick( World world, @Nonnull PlayerEntity player, @Nonnull Hand hand ) + public ActionResult use( World world, @Nonnull PlayerEntity player, @Nonnull Hand hand ) { - if( !world.isRemote ) + if( !world.isClientSide ) { new HeldItemContainerData( hand ) - .open( player, new ContainerHeldItem.Factory( Registry.ModContainers.PRINTOUT.get(), player.getHeldItem( hand ), hand ) ); + .open( player, new ContainerHeldItem.Factory( Registry.ModContainers.PRINTOUT.get(), player.getItemInHand( hand ), hand ) ); } - return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) ); + return new ActionResult<>( ActionResultType.SUCCESS, player.getItemInHand( hand ) ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java index 5e7d63187..49cc07dc9 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java @@ -29,6 +29,8 @@ import javax.annotation.Nullable; import java.io.IOException; import java.util.List; +import net.minecraft.item.Item.Properties; + public class ItemTreasureDisk extends Item implements IMedia { private static final String NBT_TITLE = "Title"; @@ -41,12 +43,12 @@ public class ItemTreasureDisk extends Item implements IMedia } @Override - public void fillItemGroup( @Nonnull ItemGroup group, @Nonnull NonNullList stacks ) + public void fillItemCategory( @Nonnull ItemGroup group, @Nonnull NonNullList stacks ) { } @Override - public void addInformation( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, @Nonnull ITooltipFlag tooltipOptions ) + public void appendHoverText( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, @Nonnull ITooltipFlag tooltipOptions ) { String label = getTitle( stack ); if( !label.isEmpty() ) list.add( new StringTextComponent( label ) ); diff --git a/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java b/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java index 32db93c43..2fc56df0b 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java +++ b/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java @@ -41,7 +41,7 @@ public final class RecordMedia implements IMedia Item item = stack.getItem(); if( !(item instanceof MusicDiscItem) ) return null; - return new TranslationTextComponent( item.getTranslationKey() + ".desc" ).getString(); + return new TranslationTextComponent( item.getDescriptionId() + ".desc" ).getString(); } @Override @@ -52,7 +52,7 @@ public final class RecordMedia implements IMedia try { - return ObfuscationReflectionHelper.getPrivateValue( MusicDiscItem.class, (MusicDiscItem) item, "field_185076_b" ); + return ObfuscationReflectionHelper.getPrivateValue( MusicDiscItem.class, (MusicDiscItem) item, "sound" ); } catch( UnableToAccessFieldException | UnableToFindFieldException e ) { diff --git a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java index 6580f3a3c..c3cda6a7a 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java @@ -25,8 +25,8 @@ import javax.annotation.Nonnull; public class DiskRecipe extends SpecialRecipe { - private final Ingredient paper = Ingredient.fromItems( Items.PAPER ); - private final Ingredient redstone = Ingredient.fromTag( Tags.Items.DUSTS_REDSTONE ); + private final Ingredient paper = Ingredient.of( Items.PAPER ); + private final Ingredient redstone = Ingredient.of( Tags.Items.DUSTS_REDSTONE ); public DiskRecipe( ResourceLocation id ) { @@ -39,9 +39,9 @@ public class DiskRecipe extends SpecialRecipe boolean paperFound = false; boolean redstoneFound = false; - for( int i = 0; i < inv.getSizeInventory(); i++ ) + for( int i = 0; i < inv.getContainerSize(); i++ ) { - ItemStack stack = inv.getStackInSlot( i ); + ItemStack stack = inv.getItem( i ); if( !stack.isEmpty() ) { @@ -67,13 +67,13 @@ public class DiskRecipe extends SpecialRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inv ) + public ItemStack assemble( @Nonnull CraftingInventory inv ) { ColourTracker tracker = new ColourTracker(); - for( int i = 0; i < inv.getSizeInventory(); i++ ) + for( int i = 0; i < inv.getContainerSize(); i++ ) { - ItemStack stack = inv.getStackInSlot( i ); + ItemStack stack = inv.getItem( i ); if( stack.isEmpty() ) continue; @@ -88,14 +88,14 @@ public class DiskRecipe extends SpecialRecipe } @Override - public boolean canFit( int x, int y ) + public boolean canCraftInDimensions( int x, int y ) { return x >= 2 && y >= 2; } @Nonnull @Override - public ItemStack getRecipeOutput() + public ItemStack getResultItem() { return ItemDisk.createFromIDAndColour( -1, null, Colour.BLUE.getHex() ); } diff --git a/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java b/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java index 12fec72e2..b71bbaef3 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java @@ -20,9 +20,9 @@ import javax.annotation.Nonnull; public final class PrintoutRecipe extends SpecialRecipe { - private final Ingredient paper = Ingredient.fromItems( net.minecraft.item.Items.PAPER ); - private final Ingredient leather = Ingredient.fromItems( net.minecraft.item.Items.LEATHER ); - private final Ingredient string = Ingredient.fromItems( Items.STRING ); + private final Ingredient paper = Ingredient.of( net.minecraft.item.Items.PAPER ); + private final Ingredient leather = Ingredient.of( net.minecraft.item.Items.LEATHER ); + private final Ingredient string = Ingredient.of( Items.STRING ); private PrintoutRecipe( ResourceLocation id ) { @@ -30,14 +30,14 @@ public final class PrintoutRecipe extends SpecialRecipe } @Override - public boolean canFit( int x, int y ) + public boolean canCraftInDimensions( int x, int y ) { return x >= 3 && y >= 3; } @Nonnull @Override - public ItemStack getRecipeOutput() + public ItemStack getResultItem() { return ItemPrintout.createMultipleFromTitleAndText( null, null, null ); } @@ -45,12 +45,12 @@ public final class PrintoutRecipe extends SpecialRecipe @Override public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world ) { - return !getCraftingResult( inventory ).isEmpty(); + return !assemble( inventory ).isEmpty(); } @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) + public ItemStack assemble( @Nonnull CraftingInventory inventory ) { // See if we match the recipe, and extract the input disk ID and dye colour int numPages = 0; @@ -63,7 +63,7 @@ public final class PrintoutRecipe extends SpecialRecipe { for( int x = 0; x < inventory.getWidth(); x++ ) { - ItemStack stack = inventory.getStackInSlot( x + y * inventory.getWidth() ); + ItemStack stack = inventory.getItem( x + y * inventory.getWidth() ); if( !stack.isEmpty() ) { if( stack.getItem() instanceof ItemPrintout && ((ItemPrintout) stack.getItem()).getType() != ItemPrintout.Type.BOOK ) diff --git a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java index 79e49949c..d78dd991b 100644 --- a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java +++ b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java @@ -60,7 +60,7 @@ public final class NetworkHandler public static void sendToPlayer( PlayerEntity player, NetworkMessage packet ) { - network.sendTo( packet, ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT ); + network.sendTo( packet, ((ServerPlayerEntity) player).connection.connection, NetworkDirection.PLAY_TO_CLIENT ); } public static void sendToAllPlayers( NetworkMessage packet ) diff --git a/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java b/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java index bad9f3e1d..0e48dad40 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/ChatTableClientMessage.java @@ -38,13 +38,13 @@ public class ChatTableClientMessage implements NetworkMessage buf.writeBoolean( table.getHeaders() != null ); if( table.getHeaders() != null ) { - for( ITextComponent header : table.getHeaders() ) buf.writeTextComponent( header ); + for( ITextComponent header : table.getHeaders() ) buf.writeComponent( header ); } buf.writeVarInt( table.getRows().size() ); for( ITextComponent[] row : table.getRows() ) { - for( ITextComponent column : row ) buf.writeTextComponent( column ); + for( ITextComponent column : row ) buf.writeComponent( column ); } buf.writeVarInt( table.getAdditional() ); @@ -59,7 +59,7 @@ public class ChatTableClientMessage implements NetworkMessage if( buf.readBoolean() ) { ITextComponent[] headers = new ITextComponent[columns]; - for( int i = 0; i < columns; i++ ) headers[i] = buf.readTextComponent(); + for( int i = 0; i < columns; i++ ) headers[i] = buf.readComponent(); table = new TableBuilder( id, headers ); } else @@ -71,7 +71,7 @@ public class ChatTableClientMessage implements NetworkMessage for( int i = 0; i < rows; i++ ) { ITextComponent[] row = new ITextComponent[columns]; - for( int j = 0; j < columns; j++ ) row[j] = buf.readTextComponent(); + for( int j = 0; j < columns; j++ ) row[j] = buf.readComponent(); table.row( row ); } diff --git a/src/main/java/dan200/computercraft/shared/network/client/ComputerDataClientMessage.java b/src/main/java/dan200/computercraft/shared/network/client/ComputerDataClientMessage.java index 60e517f4a..d2ec44e87 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/ComputerDataClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/ComputerDataClientMessage.java @@ -36,16 +36,16 @@ public class ComputerDataClientMessage extends ComputerClientMessage public void toBytes( @Nonnull PacketBuffer buf ) { super.toBytes( buf ); - buf.writeEnumValue( state ); - buf.writeCompoundTag( userData ); + buf.writeEnum( state ); + buf.writeNbt( userData ); } @Override public void fromBytes( @Nonnull PacketBuffer buf ) { super.fromBytes( buf ); - state = buf.readEnumValue( ComputerState.class ); - userData = buf.readCompoundTag(); + state = buf.readEnum( ComputerState.class ); + userData = buf.readNbt(); } @Override diff --git a/src/main/java/dan200/computercraft/shared/network/client/MonitorClientMessage.java b/src/main/java/dan200/computercraft/shared/network/client/MonitorClientMessage.java index 512bad7f7..ca11a15ca 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/MonitorClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/MonitorClientMessage.java @@ -44,9 +44,9 @@ public class MonitorClientMessage implements NetworkMessage public void handle( NetworkEvent.Context context ) { ClientPlayerEntity player = Minecraft.getInstance().player; - if( player == null || player.world == null ) return; + if( player == null || player.level == null ) return; - TileEntity te = player.world.getTileEntity( pos ); + TileEntity te = player.level.getBlockEntity( pos ); if( !(te instanceof TileMonitor) ) return; ((TileMonitor) te).read( state ); diff --git a/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java b/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java index 3f10e09f4..89dbf2b0c 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java @@ -48,7 +48,7 @@ public class PlayRecordClientMessage implements NetworkMessage pos = buf.readBlockPos(); if( buf.readBoolean() ) { - name = buf.readString( Short.MAX_VALUE ); + name = buf.readUtf( Short.MAX_VALUE ); soundEvent = buf.readRegistryIdSafe( SoundEvent.class ); } else @@ -69,7 +69,7 @@ public class PlayRecordClientMessage implements NetworkMessage else { buf.writeBoolean( true ); - buf.writeString( name ); + buf.writeUtf( name ); buf.writeRegistryId( soundEvent ); } } @@ -79,7 +79,7 @@ public class PlayRecordClientMessage implements NetworkMessage public void handle( NetworkEvent.Context context ) { Minecraft mc = Minecraft.getInstance(); - mc.worldRenderer.playRecord( soundEvent, pos ); - if( name != null ) mc.ingameGUI.setRecordPlayingMessage( name ); + mc.levelRenderer.playStreamingMusic( soundEvent, pos ); + if( name != null ) mc.gui.setNowPlaying( name ); } } diff --git a/src/main/java/dan200/computercraft/shared/network/container/ComputerContainerData.java b/src/main/java/dan200/computercraft/shared/network/container/ComputerContainerData.java index 88f7a2042..ed67433da 100644 --- a/src/main/java/dan200/computercraft/shared/network/container/ComputerContainerData.java +++ b/src/main/java/dan200/computercraft/shared/network/container/ComputerContainerData.java @@ -23,14 +23,14 @@ public class ComputerContainerData implements ContainerData public ComputerContainerData( PacketBuffer buf ) { this.id = buf.readInt(); - this.family = buf.readEnumValue( ComputerFamily.class ); + this.family = buf.readEnum( ComputerFamily.class ); } @Override public void toBytes( PacketBuffer buf ) { buf.writeInt( id ); - buf.writeEnumValue( family ); + buf.writeEnum( family ); } public int getInstanceId() diff --git a/src/main/java/dan200/computercraft/shared/network/container/HeldItemContainerData.java b/src/main/java/dan200/computercraft/shared/network/container/HeldItemContainerData.java index 1bef2de56..ba1e8ae68 100644 --- a/src/main/java/dan200/computercraft/shared/network/container/HeldItemContainerData.java +++ b/src/main/java/dan200/computercraft/shared/network/container/HeldItemContainerData.java @@ -28,13 +28,13 @@ public class HeldItemContainerData implements ContainerData public HeldItemContainerData( PacketBuffer buffer ) { - hand = buffer.readEnumValue( Hand.class ); + hand = buffer.readEnum( Hand.class ); } @Override public void toBytes( PacketBuffer buf ) { - buf.writeEnumValue( hand ); + buf.writeEnum( hand ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/network/server/ComputerActionServerMessage.java b/src/main/java/dan200/computercraft/shared/network/server/ComputerActionServerMessage.java index 688262a21..2590e33b7 100644 --- a/src/main/java/dan200/computercraft/shared/network/server/ComputerActionServerMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/server/ComputerActionServerMessage.java @@ -29,14 +29,14 @@ public class ComputerActionServerMessage extends ComputerServerMessage public void toBytes( @Nonnull PacketBuffer buf ) { super.toBytes( buf ); - buf.writeEnumValue( action ); + buf.writeEnum( action ); } @Override public void fromBytes( @Nonnull PacketBuffer buf ) { super.fromBytes( buf ); - action = buf.readEnumValue( Action.class ); + action = buf.readEnum( Action.class ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/network/server/QueueEventServerMessage.java b/src/main/java/dan200/computercraft/shared/network/server/QueueEventServerMessage.java index 792fc4a26..a0ca4c06e 100644 --- a/src/main/java/dan200/computercraft/shared/network/server/QueueEventServerMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/server/QueueEventServerMessage.java @@ -40,17 +40,17 @@ public class QueueEventServerMessage extends ComputerServerMessage public void toBytes( @Nonnull PacketBuffer buf ) { super.toBytes( buf ); - buf.writeString( event ); - buf.writeCompoundTag( args == null ? null : NBTUtil.encodeObjects( args ) ); + buf.writeUtf( event ); + buf.writeNbt( args == null ? null : NBTUtil.encodeObjects( args ) ); } @Override public void fromBytes( @Nonnull PacketBuffer buf ) { super.fromBytes( buf ); - event = buf.readString( Short.MAX_VALUE ); + event = buf.readUtf( Short.MAX_VALUE ); - CompoundNBT args = buf.readCompoundTag(); + CompoundNBT args = buf.readNbt(); this.args = args == null ? null : NBTUtil.decodeObjects( args ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java index 0dbf2d709..350a60119 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/commandblock/CommandBlockPeripheral.java @@ -64,7 +64,7 @@ public class CommandBlockPeripheral implements IPeripheral, ICapabilityProvider @LuaFunction( mainThread = true ) public final String getCommand() { - return commandBlock.getCommandBlockLogic().getCommand(); + return commandBlock.getCommandBlock().getCommand(); } /** @@ -75,8 +75,8 @@ public class CommandBlockPeripheral implements IPeripheral, ICapabilityProvider @LuaFunction( mainThread = true ) public final void setCommand( String command ) { - commandBlock.getCommandBlockLogic().setCommand( command ); - commandBlock.getCommandBlockLogic().updateCommand(); + commandBlock.getCommandBlock().setCommand( command ); + commandBlock.getCommandBlock().onUpdated(); } /** @@ -89,8 +89,8 @@ public class CommandBlockPeripheral implements IPeripheral, ICapabilityProvider @LuaFunction( mainThread = true ) public final Object[] runCommand() { - commandBlock.getCommandBlockLogic().trigger( commandBlock.getWorld() ); - int result = commandBlock.getCommandBlockLogic().getSuccessCount(); + commandBlock.getCommandBlock().performCommand( commandBlock.getLevel() ); + int result = commandBlock.getCommandBlock().getSuccessCount(); return result > 0 ? new Object[] { true } : new Object[] { false, "Command failed" }; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java index cf3e5fa24..fc8cb0162 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/BlockDiskDrive.java @@ -27,6 +27,8 @@ import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.block.Block.Properties; + public class BlockDiskDrive extends BlockGeneric { static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; @@ -35,14 +37,14 @@ public class BlockDiskDrive extends BlockGeneric public BlockDiskDrive( Properties settings ) { super( settings, Registry.ModTiles.DISK_DRIVE ); - setDefaultState( getStateContainer().getBaseState() - .with( FACING, Direction.NORTH ) - .with( STATE, DiskDriveState.EMPTY ) ); + registerDefaultState( getStateDefinition().any() + .setValue( FACING, Direction.NORTH ) + .setValue( STATE, DiskDriveState.EMPTY ) ); } @Override - protected void fillStateContainer( StateContainer.Builder properties ) + protected void createBlockStateDefinition( StateContainer.Builder properties ) { properties.add( FACING, STATE ); } @@ -51,34 +53,34 @@ public class BlockDiskDrive extends BlockGeneric @Override public BlockState getStateForPlacement( BlockItemUseContext placement ) { - return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); + return defaultBlockState().setValue( FACING, placement.getHorizontalDirection().getOpposite() ); } @Override - public void harvestBlock( @Nonnull World world, @Nonnull PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, @Nonnull ItemStack stack ) + public void playerDestroy( @Nonnull World world, @Nonnull PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, @Nonnull ItemStack stack ) { if( te instanceof INameable && ((INameable) te).hasCustomName() ) { - player.addStat( Stats.BLOCK_MINED.get( this ) ); - player.addExhaustion( 0.005F ); + player.awardStat( Stats.BLOCK_MINED.get( this ) ); + player.causeFoodExhaustion( 0.005F ); ItemStack result = new ItemStack( this ); - result.setDisplayName( ((INameable) te).getCustomName() ); - spawnAsEntity( world, pos, result ); + result.setHoverName( ((INameable) te).getCustomName() ); + popResource( world, pos, result ); } else { - super.harvestBlock( world, player, pos, state, te, stack ); + super.playerDestroy( world, player, pos, state, te, stack ); } } @Override - public void onBlockPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack ) + public void setPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack ) { - if( stack.hasDisplayName() ) + if( stack.hasCustomHoverName() ) { - TileEntity tileentity = world.getTileEntity( pos ); - if( tileentity instanceof TileDiskDrive ) ((TileDiskDrive) tileentity).customName = stack.getDisplayName(); + TileEntity tileentity = world.getBlockEntity( pos ); + if( tileentity instanceof TileDiskDrive ) ((TileDiskDrive) tileentity).customName = stack.getHoverName(); } } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java index 5fe4542af..c258a348e 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java @@ -48,38 +48,38 @@ public class ContainerDiskDrive extends Container } @Override - public boolean canInteractWith( @Nonnull PlayerEntity player ) + public boolean stillValid( @Nonnull PlayerEntity player ) { - return inventory.isUsableByPlayer( player ); + return inventory.stillValid( player ); } @Nonnull @Override - public ItemStack transferStackInSlot( @Nonnull PlayerEntity player, int slotIndex ) + public ItemStack quickMoveStack( @Nonnull PlayerEntity player, int slotIndex ) { - Slot slot = inventorySlots.get( slotIndex ); - if( slot == null || !slot.getHasStack() ) return ItemStack.EMPTY; + Slot slot = slots.get( slotIndex ); + if( slot == null || !slot.hasItem() ) return ItemStack.EMPTY; - ItemStack existing = slot.getStack().copy(); + ItemStack existing = slot.getItem().copy(); ItemStack result = existing.copy(); if( slotIndex == 0 ) { // Insert into player inventory - if( !mergeItemStack( existing, 1, 37, true ) ) return ItemStack.EMPTY; + if( !moveItemStackTo( existing, 1, 37, true ) ) return ItemStack.EMPTY; } else { // Insert into drive inventory - if( !mergeItemStack( existing, 0, 1, false ) ) return ItemStack.EMPTY; + if( !moveItemStackTo( existing, 0, 1, false ) ) return ItemStack.EMPTY; } if( existing.isEmpty() ) { - slot.putStack( ItemStack.EMPTY ); + slot.set( ItemStack.EMPTY ); } else { - slot.onSlotChanged(); + slot.setChanged(); } if( existing.getCount() == result.getCount() ) return ItemStack.EMPTY; diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java index a82201bb8..c48326310 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveState.java @@ -24,7 +24,7 @@ public enum DiskDriveState implements IStringSerializable @Override @Nonnull - public String getName() + public String getSerializedName() { return name; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java index 1797a02a2..f2136367c 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java @@ -99,54 +99,54 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory if( player.isCrouching() ) { // Try to put a disk into the drive - ItemStack disk = player.getHeldItem( hand ); + ItemStack disk = player.getItemInHand( hand ); if( disk.isEmpty() ) return ActionResultType.PASS; - if( !getWorld().isRemote && getStackInSlot( 0 ).isEmpty() && MediaProviders.get( disk ) != null ) + if( !getLevel().isClientSide && getItem( 0 ).isEmpty() && MediaProviders.get( disk ) != null ) { setDiskStack( disk ); - player.setHeldItem( hand, ItemStack.EMPTY ); + player.setItemInHand( hand, ItemStack.EMPTY ); } return ActionResultType.SUCCESS; } else { // Open the GUI - if( !getWorld().isRemote ) NetworkHooks.openGui( (ServerPlayerEntity) player, this ); + if( !getLevel().isClientSide ) NetworkHooks.openGui( (ServerPlayerEntity) player, this ); return ActionResultType.SUCCESS; } } public Direction getDirection() { - return getBlockState().get( BlockDiskDrive.FACING ); + return getBlockState().getValue( BlockDiskDrive.FACING ); } @Override - public void read( @Nonnull CompoundNBT nbt ) + public void load( @Nonnull CompoundNBT nbt ) { - super.read( nbt ); + super.load( nbt ); customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; if( nbt.contains( NBT_ITEM ) ) { CompoundNBT item = nbt.getCompound( NBT_ITEM ); - m_diskStack = ItemStack.read( item ); + m_diskStack = ItemStack.of( item ); m_diskMount = null; } } @Nonnull @Override - public CompoundNBT write( @Nonnull CompoundNBT nbt ) + public CompoundNBT save( @Nonnull CompoundNBT nbt ) { if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); if( !m_diskStack.isEmpty() ) { CompoundNBT item = new CompoundNBT(); - m_diskStack.write( item ); + m_diskStack.save( item ); nbt.put( NBT_ITEM, item ); } - return super.write( nbt ); + return super.save( nbt ); } @Override @@ -162,7 +162,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory // Music synchronized( this ) { - if( !world.isRemote && m_recordPlaying != m_recordQueued || m_restartRecord ) + if( !level.isClientSide && m_recordPlaying != m_recordQueued || m_restartRecord ) { m_restartRecord = false; if( m_recordQueued ) @@ -191,7 +191,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory // IInventory implementation @Override - public int getSizeInventory() + public int getContainerSize() { return 1; } @@ -204,14 +204,14 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory @Nonnull @Override - public ItemStack getStackInSlot( int slot ) + public ItemStack getItem( int slot ) { return m_diskStack; } @Nonnull @Override - public ItemStack removeStackFromSlot( int slot ) + public ItemStack removeItemNoUpdate( int slot ) { ItemStack result = m_diskStack; m_diskStack = ItemStack.EMPTY; @@ -222,30 +222,30 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory @Nonnull @Override - public ItemStack decrStackSize( int slot, int count ) + public ItemStack removeItem( int slot, int count ) { if( m_diskStack.isEmpty() ) return ItemStack.EMPTY; if( m_diskStack.getCount() <= count ) { ItemStack disk = m_diskStack; - setInventorySlotContents( slot, ItemStack.EMPTY ); + setItem( slot, ItemStack.EMPTY ); return disk; } ItemStack part = m_diskStack.split( count ); - setInventorySlotContents( slot, m_diskStack.isEmpty() ? ItemStack.EMPTY : m_diskStack ); + setItem( slot, m_diskStack.isEmpty() ? ItemStack.EMPTY : m_diskStack ); return part; } @Override - public void setInventorySlotContents( int slot, @Nonnull ItemStack stack ) + public void setItem( int slot, @Nonnull ItemStack stack ) { - if( getWorld().isRemote ) + if( getLevel().isClientSide ) { m_diskStack = stack; m_diskMount = null; - markDirty(); + setChanged(); return; } @@ -276,7 +276,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory // Swap disk over m_diskStack = stack; m_diskMount = null; - markDirty(); + setChanged(); // Mount new disk if( !m_diskStack.isEmpty() ) @@ -288,33 +288,33 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory } @Override - public void markDirty() + public void setChanged() { - if( !world.isRemote ) updateBlockState(); - super.markDirty(); + if( !level.isClientSide ) updateBlockState(); + super.setChanged(); } @Override - public boolean isUsableByPlayer( @Nonnull PlayerEntity player ) + public boolean stillValid( @Nonnull PlayerEntity player ) { return isUsable( player, false ); } @Override - public void clear() + public void clearContent() { - setInventorySlotContents( 0, ItemStack.EMPTY ); + setItem( 0, ItemStack.EMPTY ); } @Nonnull ItemStack getDiskStack() { - return getStackInSlot( 0 ); + return getItem( 0 ); } void setDiskStack( @Nonnull ItemStack stack ) { - setInventorySlotContents( 0, stack ); + setItem( 0, stack ); } private IMedia getDiskMedia() @@ -391,7 +391,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory { if( m_diskMount == null ) { - m_diskMount = contents.createDataMount( m_diskStack, getWorld() ); + m_diskMount = contents.createDataMount( m_diskStack, getLevel() ); } if( m_diskMount != null ) { @@ -442,7 +442,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory private void updateBlockState() { - if( removed ) return; + if( remove ) return; if( !m_diskStack.isEmpty() ) { @@ -458,14 +458,14 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory private void updateBlockState( DiskDriveState state ) { BlockState blockState = getBlockState(); - if( blockState.get( BlockDiskDrive.STATE ) == state ) return; + if( blockState.getValue( BlockDiskDrive.STATE ) == state ) return; - getWorld().setBlockState( getPos(), blockState.with( BlockDiskDrive.STATE, state ) ); + getLevel().setBlockAndUpdate( getBlockPos(), blockState.setValue( BlockDiskDrive.STATE, state ) ); } private synchronized void ejectContents( boolean destroyed ) { - if( getWorld().isRemote || m_diskStack.isEmpty() ) return; + if( getLevel().isClientSide || m_diskStack.isEmpty() ) return; // Remove the disks from the inventory ItemStack disks = m_diskStack; @@ -477,19 +477,19 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory if( !destroyed ) { Direction dir = getDirection(); - xOff = dir.getXOffset(); - zOff = dir.getZOffset(); + xOff = dir.getStepX(); + zOff = dir.getStepZ(); } - BlockPos pos = getPos(); + BlockPos pos = getBlockPos(); double x = pos.getX() + 0.5 + xOff * 0.5; double y = pos.getY() + 0.75; double z = pos.getZ() + 0.5 + zOff * 0.5; - ItemEntity entityitem = new ItemEntity( getWorld(), x, y, z, disks ); - entityitem.setMotion( xOff * 0.15, 0, zOff * 0.15 ); + ItemEntity entityitem = new ItemEntity( getLevel(), x, y, z, disks ); + entityitem.setDeltaMovement( xOff * 0.15, 0, zOff * 0.15 ); - getWorld().addEntity( entityitem ); - if( !destroyed ) getWorld().playBroadcastSound( 1000, getPos(), 0 ); + getLevel().addFreshEntity( entityitem ); + if( !destroyed ) getLevel().globalLevelEvent( 1000, getBlockPos(), 0 ); } // Private methods @@ -500,17 +500,17 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory SoundEvent record = contents != null ? contents.getAudio( m_diskStack ) : null; if( record != null ) { - RecordUtil.playRecord( record, contents.getAudioTitle( m_diskStack ), getWorld(), getPos() ); + RecordUtil.playRecord( record, contents.getAudioTitle( m_diskStack ), getLevel(), getBlockPos() ); } else { - RecordUtil.playRecord( null, null, getWorld(), getPos() ); + RecordUtil.playRecord( null, null, getLevel(), getBlockPos() ); } } private void stopRecord() { - RecordUtil.playRecord( null, null, getWorld(), getPos() ); + RecordUtil.playRecord( null, null, getLevel(), getBlockPos() ); } @Nonnull @@ -549,7 +549,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory @Override public ITextComponent getName() { - return customName != null ? customName : new TranslationTextComponent( getBlockState().getBlock().getTranslationKey() ); + return customName != null ? customName : new TranslationTextComponent( getBlockState().getBlock().getDescriptionId() ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/peripheral/generic/GenericPeripheralProvider.java b/src/main/java/dan200/computercraft/shared/peripheral/generic/GenericPeripheralProvider.java index 6bb25f1b8..7f81033d0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/generic/GenericPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/generic/GenericPeripheralProvider.java @@ -35,7 +35,7 @@ public class GenericPeripheralProvider @Nullable public static IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side, NonNullConsumer> invalidate ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile == null ) return null; ArrayList saturated = new ArrayList<>( 0 ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/generic/data/BlockData.java b/src/main/java/dan200/computercraft/shared/peripheral/generic/data/BlockData.java index ec07302f9..3947487fd 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/generic/data/BlockData.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/generic/data/BlockData.java @@ -5,7 +5,6 @@ */ package dan200.computercraft.shared.peripheral.generic.data; -import com.google.common.collect.ImmutableMap; import net.minecraft.block.BlockState; import net.minecraft.state.IProperty; @@ -21,7 +20,7 @@ public class BlockData data.put( "name", DataHelpers.getId( state.getBlock() ) ); Map stateTable = new HashMap<>(); - for( ImmutableMap.Entry, ? extends Comparable> entry : state.getValues().entrySet() ) + for( Map.Entry, ? extends Comparable> entry : state.getValues().entrySet() ) { IProperty property = entry.getKey(); stateTable.put( property.getName(), getPropertyValue( property, entry.getValue() ) ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/generic/data/ItemData.java b/src/main/java/dan200/computercraft/shared/peripheral/generic/data/ItemData.java index 2622d654a..84486335a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/generic/data/ItemData.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/generic/data/ItemData.java @@ -52,12 +52,12 @@ public class ItemData fillBasic( data, stack ); - data.put( "displayName", stack.getDisplayName().getString() ); + data.put( "displayName", stack.getHoverName().getString() ); data.put( "maxCount", stack.getMaxStackSize() ); - if( stack.isDamageable() ) + if( stack.isDamageableItem() ) { - data.put( "damage", stack.getDamage() ); + data.put( "damage", stack.getDamageValue() ); data.put( "maxDamage", stack.getMaxDamage() ); } @@ -106,7 +106,7 @@ public class ItemData { try { - return ITextComponent.Serializer.fromJson( x.getString() ); + return ITextComponent.Serializer.fromJson( x.getAsString() ); } catch( JsonParseException e ) { @@ -138,7 +138,7 @@ public class ItemData * I'll do that to have the same data than ones displayed in tooltip. * @see EnchantmentHelper.getEnchantments(ItemStack stack) */ - addEnchantments( stack.getEnchantmentTagList(), enchants ); + addEnchantments( stack.getEnchantmentTags(), enchants ); } return enchants; @@ -157,14 +157,14 @@ public class ItemData enchants.ensureCapacity( enchants.size() + rawEnchants.size() ); - for( Map.Entry entry : EnchantmentHelper.func_226652_a_( rawEnchants ).entrySet() ) + for( Map.Entry entry : EnchantmentHelper.deserializeEnchantments( rawEnchants ).entrySet() ) { Enchantment enchantment = entry.getKey(); Integer level = entry.getValue(); HashMap enchant = new HashMap<>( 3 ); enchant.put( "name", DataHelpers.getId( enchantment ) ); enchant.put( "level", level ); - enchant.put( "displayName", enchantment.getDisplayName( level ).getString() ); + enchant.put( "displayName", enchantment.getFullname( level ).getString() ); enchants.add( enchant ); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemShapes.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemShapes.java index c213e961d..0e57d9abb 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemShapes.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemShapes.java @@ -14,18 +14,18 @@ import javax.annotation.Nonnull; public final class ModemShapes { private static final VoxelShape[] BOXES = new VoxelShape[] { - VoxelShapes.create( 0.125, 0.0, 0.125, 0.875, 0.1875, 0.875 ), // Down - VoxelShapes.create( 0.125, 0.8125, 0.125, 0.875, 1.0, 0.875 ), // Up - VoxelShapes.create( 0.125, 0.125, 0.0, 0.875, 0.875, 0.1875 ), // North - VoxelShapes.create( 0.125, 0.125, 0.8125, 0.875, 0.875, 1.0 ), // South - VoxelShapes.create( 0.0, 0.125, 0.125, 0.1875, 0.875, 0.875 ), // West - VoxelShapes.create( 0.8125, 0.125, 0.125, 1.0, 0.875, 0.875 ), // East + VoxelShapes.box( 0.125, 0.0, 0.125, 0.875, 0.1875, 0.875 ), // Down + VoxelShapes.box( 0.125, 0.8125, 0.125, 0.875, 1.0, 0.875 ), // Up + VoxelShapes.box( 0.125, 0.125, 0.0, 0.875, 0.875, 0.1875 ), // North + VoxelShapes.box( 0.125, 0.125, 0.8125, 0.875, 0.875, 1.0 ), // South + VoxelShapes.box( 0.0, 0.125, 0.125, 0.1875, 0.875, 0.875 ), // West + VoxelShapes.box( 0.8125, 0.125, 0.125, 1.0, 0.875, 0.875 ), // East }; @Nonnull public static VoxelShape getBounds( Direction facing ) { int direction = facing.ordinal(); - return direction < BOXES.length ? BOXES[direction] : VoxelShapes.fullCube(); + return direction < BOXES.length ? BOXES[direction] : VoxelShapes.block(); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java index 2660dac95..8c5f6ec03 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java @@ -40,6 +40,8 @@ import java.util.EnumMap; import static dan200.computercraft.shared.util.WaterloggableHelpers.*; +import net.minecraft.block.Block.Properties; + public class BlockCable extends BlockGeneric implements IWaterLoggable { public static final EnumProperty MODEM = EnumProperty.create( "modem", CableModemVariant.class ); @@ -63,32 +65,32 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable { super( settings, Registry.ModTiles.CABLE ); - setDefaultState( getStateContainer().getBaseState() - .with( MODEM, CableModemVariant.None ) - .with( CABLE, false ) - .with( NORTH, false ).with( SOUTH, false ) - .with( EAST, false ).with( WEST, false ) - .with( UP, false ).with( DOWN, false ) - .with( WATERLOGGED, false ) + registerDefaultState( getStateDefinition().any() + .setValue( MODEM, CableModemVariant.None ) + .setValue( CABLE, false ) + .setValue( NORTH, false ).setValue( SOUTH, false ) + .setValue( EAST, false ).setValue( WEST, false ) + .setValue( UP, false ).setValue( DOWN, false ) + .setValue( WATERLOGGED, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void createBlockStateDefinition( StateContainer.Builder builder ) { builder.add( MODEM, CABLE, NORTH, SOUTH, EAST, WEST, UP, DOWN, WATERLOGGED ); } public static boolean canConnectIn( BlockState state, Direction direction ) { - return state.get( BlockCable.CABLE ) && state.get( BlockCable.MODEM ).getFacing() != direction; + return state.getValue( BlockCable.CABLE ) && state.getValue( BlockCable.MODEM ).getFacing() != direction; } public static boolean doesConnectVisually( BlockState state, IBlockReader world, BlockPos pos, Direction direction ) { - if( !state.get( CABLE ) ) return false; - if( state.get( MODEM ).getFacing() == direction ) return true; - return ComputerCraftAPI.getWiredElementAt( world, pos.offset( direction ), direction.getOpposite() ).isPresent(); + if( !state.getValue( CABLE ) ) return false; + if( state.getValue( MODEM ).getFacing() == direction ) return true; + return ComputerCraftAPI.getWiredElementAt( world, pos.relative( direction ), direction.getOpposite() ).isPresent(); } @Nonnull @@ -102,40 +104,40 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable @Override public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid ) { - if( state.get( CABLE ) && state.get( MODEM ).getFacing() != null ) + if( state.getValue( CABLE ) && state.getValue( MODEM ).getFacing() != null ) { - BlockRayTraceResult hit = world.rayTraceBlocks( new RayTraceContext( + BlockRayTraceResult hit = world.clip( new RayTraceContext( WorldUtil.getRayStart( player ), WorldUtil.getRayEnd( player ), RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player ) ); if( hit.getType() == RayTraceResult.Type.BLOCK ) { - TileEntity tile = world.getTileEntity( pos ); - if( tile instanceof TileCable && tile.hasWorld() ) + TileEntity tile = world.getBlockEntity( pos ); + if( tile instanceof TileCable && tile.hasLevel() ) { TileCable cable = (TileCable) tile; ItemStack item; BlockState newState; - if( WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ) + if( WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getLocation().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ) { - newState = state.with( MODEM, CableModemVariant.None ); + newState = state.setValue( MODEM, CableModemVariant.None ); item = new ItemStack( Registry.ModItems.WIRED_MODEM.get() ); } else { - newState = state.with( CABLE, false ); + newState = state.setValue( CABLE, false ); item = new ItemStack( Registry.ModItems.CABLE.get() ); } - world.setBlockState( pos, correctConnections( world, pos, newState ), 3 ); + world.setBlock( pos, correctConnections( world, pos, newState ), 3 ); cable.modemChanged(); cable.connectionsChanged(); - if( !world.isRemote && !player.abilities.isCreativeMode ) + if( !world.isClientSide && !player.abilities.instabuild ) { - Block.spawnAsEntity( world, pos, item ); + Block.popResource( world, pos, item ); } return false; @@ -150,31 +152,31 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable @Override public ItemStack getPickBlock( BlockState state, RayTraceResult hit, IBlockReader world, BlockPos pos, PlayerEntity player ) { - Direction modem = state.get( MODEM ).getFacing(); - boolean cable = state.get( CABLE ); + Direction modem = state.getValue( MODEM ).getFacing(); + boolean cable = state.getValue( CABLE ); // If we've only got one, just use that. if( !cable ) return new ItemStack( Registry.ModItems.WIRED_MODEM.get() ); if( modem == null ) return new ItemStack( Registry.ModItems.CABLE.get() ); // We've a modem and cable, so try to work out which one we're interacting with - return hit != null && WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) + return hit != null && WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getLocation().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ? new ItemStack( Registry.ModItems.WIRED_MODEM.get() ) : new ItemStack( Registry.ModItems.CABLE.get() ); } @Override - public void onBlockPlacedBy( World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack ) + public void setPlacedBy( World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileCable ) { TileCable cable = (TileCable) tile; if( cable.hasCable() ) cable.connectionsChanged(); } - super.onBlockPlacedBy( world, pos, state, placer, stack ); + super.setPlacedBy( world, pos, state, placer, stack ); } @Nonnull @@ -188,66 +190,66 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable @Nonnull @Override @Deprecated - public BlockState updatePostPlacement( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos ) + public BlockState updateShape( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos ) { updateWaterloggedPostPlacement( state, world, pos ); // Should never happen, but handle the case where we've no modem or cable. - if( !state.get( CABLE ) && state.get( MODEM ) == CableModemVariant.None ) + if( !state.getValue( CABLE ) && state.getValue( MODEM ) == CableModemVariant.None ) { - return getFluidState( state ).getBlockState(); + return getFluidState( state ).createLegacyBlock(); } - return state.with( CONNECTIONS.get( side ), doesConnectVisually( state, world, pos, side ) ); + return state.setValue( CONNECTIONS.get( side ), doesConnectVisually( state, world, pos, side ) ); } @Override @Deprecated - public boolean isValidPosition( BlockState state, @Nonnull IWorldReader world, @Nonnull BlockPos pos ) + public boolean canSurvive( BlockState state, @Nonnull IWorldReader world, @Nonnull BlockPos pos ) { - Direction facing = state.get( MODEM ).getFacing(); + Direction facing = state.getValue( MODEM ).getFacing(); if( facing == null ) return true; - BlockPos offsetPos = pos.offset( facing ); + BlockPos offsetPos = pos.relative( facing ); BlockState offsetState = world.getBlockState( offsetPos ); - return hasSolidSide( offsetState, world, offsetPos, facing.getOpposite() ); + return isFaceSturdy( offsetState, world, offsetPos, facing.getOpposite() ); } @Nullable @Override public BlockState getStateForPlacement( @Nonnull BlockItemUseContext context ) { - BlockState state = getDefaultState() - .with( WATERLOGGED, getWaterloggedStateForPlacement( context ) ); + BlockState state = defaultBlockState() + .setValue( WATERLOGGED, getWaterloggedStateForPlacement( context ) ); - if( context.getItem().getItem() instanceof ItemBlockCable.Cable ) + if( context.getItemInHand().getItem() instanceof ItemBlockCable.Cable ) { - World world = context.getWorld(); - BlockPos pos = context.getPos(); - return correctConnections( world, pos, state.with( CABLE, true ) ); + World world = context.getLevel(); + BlockPos pos = context.getClickedPos(); + return correctConnections( world, pos, state.setValue( CABLE, true ) ); } else { - return state.with( MODEM, CableModemVariant.from( context.getFace().getOpposite() ) ); + return state.setValue( MODEM, CableModemVariant.from( context.getClickedFace().getOpposite() ) ); } } public static BlockState correctConnections( World world, BlockPos pos, BlockState state ) { - if( state.get( CABLE ) ) + if( state.getValue( CABLE ) ) { return state - .with( NORTH, doesConnectVisually( state, world, pos, Direction.NORTH ) ) - .with( SOUTH, doesConnectVisually( state, world, pos, Direction.SOUTH ) ) - .with( EAST, doesConnectVisually( state, world, pos, Direction.EAST ) ) - .with( WEST, doesConnectVisually( state, world, pos, Direction.WEST ) ) - .with( UP, doesConnectVisually( state, world, pos, Direction.UP ) ) - .with( DOWN, doesConnectVisually( state, world, pos, Direction.DOWN ) ); + .setValue( NORTH, doesConnectVisually( state, world, pos, Direction.NORTH ) ) + .setValue( SOUTH, doesConnectVisually( state, world, pos, Direction.SOUTH ) ) + .setValue( EAST, doesConnectVisually( state, world, pos, Direction.EAST ) ) + .setValue( WEST, doesConnectVisually( state, world, pos, Direction.WEST ) ) + .setValue( UP, doesConnectVisually( state, world, pos, Direction.UP ) ) + .setValue( DOWN, doesConnectVisually( state, world, pos, Direction.DOWN ) ); } else { return state - .with( NORTH, false ).with( SOUTH, false ).with( EAST, false ) - .with( WEST, false ).with( UP, false ).with( DOWN, false ); + .setValue( NORTH, false ).setValue( SOUTH, false ).setValue( EAST, false ) + .setValue( WEST, false ).setValue( UP, false ).setValue( DOWN, false ); } } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java index 80cbdc4d3..a56282d4f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockWiredModemFull.java @@ -12,6 +12,8 @@ import net.minecraft.block.BlockState; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; +import net.minecraft.block.Block.Properties; + public class BlockWiredModemFull extends BlockGeneric { public static final BooleanProperty MODEM_ON = BooleanProperty.create( "modem" ); @@ -20,14 +22,14 @@ public class BlockWiredModemFull extends BlockGeneric public BlockWiredModemFull( Properties settings ) { super( settings, Registry.ModTiles.WIRED_MODEM_FULL ); - setDefaultState( getStateContainer().getBaseState() - .with( MODEM_ON, false ) - .with( PERIPHERAL_ON, false ) + registerDefaultState( getStateDefinition().any() + .setValue( MODEM_ON, false ) + .setValue( PERIPHERAL_ON, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void createBlockStateDefinition( StateContainer.Builder builder ) { builder.add( MODEM_ON, PERIPHERAL_ON ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java index 9e5521bb2..2f5482edd 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableModemVariant.java @@ -53,19 +53,19 @@ public enum CableModemVariant implements IStringSerializable @Nonnull public static CableModemVariant from( Direction facing ) { - return facing == null ? None : VALUES[1 + facing.getIndex()]; + return facing == null ? None : VALUES[1 + facing.get3DDataValue()]; } @Nonnull public static CableModemVariant from( Direction facing, boolean modem, boolean peripheral ) { int state = (modem ? 2 : 0) + (peripheral ? 1 : 0); - return facing == null ? None : VALUES[1 + 6 * state + facing.getIndex()]; + return facing == null ? None : VALUES[1 + 6 * state + facing.get3DDataValue()]; } @Nonnull @Override - public String getName() + public String getSerializedName() { return name; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java index 01ed76966..e3867522a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableShapes.java @@ -22,15 +22,15 @@ public final class CableShapes private static final double MIN = 0.375; private static final double MAX = 1 - MIN; - private static final VoxelShape SHAPE_CABLE_CORE = VoxelShapes.create( MIN, MIN, MIN, MAX, MAX, MAX ); + private static final VoxelShape SHAPE_CABLE_CORE = VoxelShapes.box( MIN, MIN, MIN, MAX, MAX, MAX ); private static final EnumMap SHAPE_CABLE_ARM = new EnumMap<>( new ImmutableMap.Builder() - .put( Direction.DOWN, VoxelShapes.create( MIN, 0, MIN, MAX, MIN, MAX ) ) - .put( Direction.UP, VoxelShapes.create( MIN, MAX, MIN, MAX, 1, MAX ) ) - .put( Direction.NORTH, VoxelShapes.create( MIN, MIN, 0, MAX, MAX, MIN ) ) - .put( Direction.SOUTH, VoxelShapes.create( MIN, MIN, MAX, MAX, MAX, 1 ) ) - .put( Direction.WEST, VoxelShapes.create( 0, MIN, MIN, MIN, MAX, MAX ) ) - .put( Direction.EAST, VoxelShapes.create( MAX, MIN, MIN, 1, MAX, MAX ) ) + .put( Direction.DOWN, VoxelShapes.box( MIN, 0, MIN, MAX, MIN, MAX ) ) + .put( Direction.UP, VoxelShapes.box( MIN, MAX, MIN, MAX, 1, MAX ) ) + .put( Direction.NORTH, VoxelShapes.box( MIN, MIN, 0, MAX, MAX, MIN ) ) + .put( Direction.SOUTH, VoxelShapes.box( MIN, MIN, MAX, MAX, MAX, 1 ) ) + .put( Direction.WEST, VoxelShapes.box( 0, MIN, MIN, MIN, MAX, MAX ) ) + .put( Direction.EAST, VoxelShapes.box( MAX, MIN, MIN, 1, MAX, MAX ) ) .build() ); @@ -46,7 +46,7 @@ public final class CableShapes int index = 0; for( Direction facing : DirectionUtil.FACINGS ) { - if( state.get( CONNECTIONS.get( facing ) ) ) index |= 1 << facing.ordinal(); + if( state.getValue( CONNECTIONS.get( facing ) ) ) index |= 1 << facing.ordinal(); } return index; @@ -71,20 +71,20 @@ public final class CableShapes public static VoxelShape getCableShape( BlockState state ) { - if( !state.get( CABLE ) ) return VoxelShapes.empty(); + if( !state.getValue( CABLE ) ) return VoxelShapes.empty(); return getCableShape( getCableIndex( state ) ); } public static VoxelShape getModemShape( BlockState state ) { - Direction facing = state.get( MODEM ).getFacing(); + Direction facing = state.getValue( MODEM ).getFacing(); return facing == null ? VoxelShapes.empty() : ModemShapes.getBounds( facing ); } public static VoxelShape getShape( BlockState state ) { - Direction facing = state.get( MODEM ).getFacing(); - if( !state.get( CABLE ) ) return getModemShape( state ); + Direction facing = state.getValue( MODEM ).getFacing(); + if( !state.getValue( CABLE ) ) return getModemShape( state ); int cableIndex = getCableIndex( state ); int index = cableIndex + ((facing == null ? 0 : facing.ordinal() + 1) << 6); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java index cf44fc4eb..ca7ca69a5 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java @@ -23,6 +23,8 @@ import javax.annotation.Nonnull; import static dan200.computercraft.shared.peripheral.modem.wired.BlockCable.*; +import net.minecraft.item.Item.Properties; + public abstract class ItemBlockCable extends BlockItem { private String translationKey; @@ -35,13 +37,13 @@ public abstract class ItemBlockCable extends BlockItem boolean placeAt( World world, BlockPos pos, BlockState state, PlayerEntity player ) { // TODO: Check entity collision. - if( !state.isValidPosition( world, pos ) ) return false; + if( !state.canSurvive( world, pos ) ) return false; - world.setBlockState( pos, state, 3 ); + world.setBlock( pos, state, 3 ); SoundType soundType = state.getBlock().getSoundType( state, world, pos, player ); world.playSound( null, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F ); - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( tile instanceof TileCable ) { TileCable cable = (TileCable) tile; @@ -58,18 +60,18 @@ public abstract class ItemBlockCable extends BlockItem } @Override - public void fillItemGroup( @Nonnull ItemGroup group, @Nonnull NonNullList list ) + public void fillItemCategory( @Nonnull ItemGroup group, @Nonnull NonNullList list ) { - if( isInGroup( group ) ) list.add( new ItemStack( this ) ); + if( allowdedIn( group ) ) list.add( new ItemStack( this ) ); } @Nonnull @Override - public String getTranslationKey() + public String getDescriptionId() { if( translationKey == null ) { - translationKey = Util.makeTranslationKey( "block", ForgeRegistries.ITEMS.getKey( this ) ); + translationKey = Util.makeDescriptionId( "block", ForgeRegistries.ITEMS.getKey( this ) ); } return translationKey; } @@ -83,22 +85,22 @@ public abstract class ItemBlockCable extends BlockItem @Nonnull @Override - public ActionResultType tryPlace( BlockItemUseContext context ) + public ActionResultType place( BlockItemUseContext context ) { - ItemStack stack = context.getItem(); + ItemStack stack = context.getItemInHand(); if( stack.isEmpty() ) return ActionResultType.FAIL; - World world = context.getWorld(); - BlockPos pos = context.getPos(); + World world = context.getLevel(); + BlockPos pos = context.getClickedPos(); BlockState existingState = world.getBlockState( pos ); // Try to add a modem to a cable - if( existingState.getBlock() == Registry.ModBlocks.CABLE.get() && existingState.get( MODEM ) == CableModemVariant.None ) + if( existingState.getBlock() == Registry.ModBlocks.CABLE.get() && existingState.getValue( MODEM ) == CableModemVariant.None ) { - Direction side = context.getFace().getOpposite(); + Direction side = context.getClickedFace().getOpposite(); BlockState newState = existingState - .with( MODEM, CableModemVariant.from( side ) ) - .with( CONNECTIONS.get( side ), existingState.get( CABLE ) ); + .setValue( MODEM, CableModemVariant.from( side ) ) + .setValue( CONNECTIONS.get( side ), existingState.getValue( CABLE ) ); if( placeAt( world, pos, newState, context.getPlayer() ) ) { stack.shrink( 1 ); @@ -106,7 +108,7 @@ public abstract class ItemBlockCable extends BlockItem } } - return super.tryPlace( context ); + return super.place( context ); } } @@ -119,19 +121,19 @@ public abstract class ItemBlockCable extends BlockItem @Nonnull @Override - public ActionResultType tryPlace( BlockItemUseContext context ) + public ActionResultType place( BlockItemUseContext context ) { - ItemStack stack = context.getItem(); + ItemStack stack = context.getItemInHand(); if( stack.isEmpty() ) return ActionResultType.FAIL; - World world = context.getWorld(); - BlockPos pos = context.getPos(); + World world = context.getLevel(); + BlockPos pos = context.getClickedPos(); // Try to add a cable to a modem inside the block we're clicking on. - BlockPos insidePos = pos.offset( context.getFace().getOpposite() ); + BlockPos insidePos = pos.relative( context.getClickedFace().getOpposite() ); BlockState insideState = world.getBlockState( insidePos ); - if( insideState.getBlock() == Registry.ModBlocks.CABLE.get() && !insideState.get( BlockCable.CABLE ) - && placeAtCorrected( world, insidePos, insideState.with( BlockCable.CABLE, true ) ) ) + if( insideState.getBlock() == Registry.ModBlocks.CABLE.get() && !insideState.getValue( BlockCable.CABLE ) + && placeAtCorrected( world, insidePos, insideState.setValue( BlockCable.CABLE, true ) ) ) { stack.shrink( 1 ); return ActionResultType.SUCCESS; @@ -139,14 +141,14 @@ public abstract class ItemBlockCable extends BlockItem // Try to add a cable to a modem adjacent to this block BlockState existingState = world.getBlockState( pos ); - if( existingState.getBlock() == Registry.ModBlocks.CABLE.get() && !existingState.get( BlockCable.CABLE ) - && placeAtCorrected( world, pos, existingState.with( BlockCable.CABLE, true ) ) ) + if( existingState.getBlock() == Registry.ModBlocks.CABLE.get() && !existingState.getValue( BlockCable.CABLE ) + && placeAtCorrected( world, pos, existingState.setValue( BlockCable.CABLE, true ) ) ) { stack.shrink( 1 ); return ActionResultType.SUCCESS; } - return super.tryPlace( context ); + return super.place( context ); } } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java index 6756f6e3e..7c587f7bb 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java @@ -53,14 +53,14 @@ public class TileCable extends TileGeneric @Override public World getWorld() { - return TileCable.this.getWorld(); + return TileCable.this.getLevel(); } @Nonnull @Override public Vec3d getPosition() { - BlockPos pos = getPos(); + BlockPos pos = getBlockPos(); return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); } @@ -105,7 +105,7 @@ public class TileCable extends TileGeneric @Override public Vec3d getPosition() { - BlockPos pos = getPos().offset( modemDirection ); + BlockPos pos = getBlockPos().relative( modemDirection ); return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); } @@ -127,7 +127,7 @@ public class TileCable extends TileGeneric private void onRemove() { - if( world == null || !world.isRemote ) + if( level == null || !level.isClientSide ) { m_node.remove(); m_connectionsFormed = false; @@ -153,9 +153,9 @@ public class TileCable extends TileGeneric } @Override - public void remove() + public void setRemoved() { - super.remove(); + super.setRemoved(); onRemove(); } @@ -175,11 +175,11 @@ public class TileCable extends TileGeneric } @Override - public void updateContainingBlockInfo() + public void clearCache() { - super.updateContainingBlockInfo(); + super.clearCache(); hasModemDirection = false; - if( !world.isRemote ) world.getPendingBlockTicks().scheduleTick( pos, getBlockState().getBlock(), 0 ); + if( !level.isClientSide ) level.getBlockTicks().scheduleTick( worldPosition, getBlockState().getBlock(), 0 ); } private void refreshDirection() @@ -187,7 +187,7 @@ public class TileCable extends TileGeneric if( hasModemDirection ) return; hasModemDirection = true; - modemDirection = getBlockState().get( BlockCable.MODEM ).getFacing(); + modemDirection = getBlockState().getValue( BlockCable.MODEM ).getFacing(); } @Nullable @@ -208,21 +208,21 @@ public class TileCable extends TileGeneric public void onNeighbourChange( @Nonnull BlockPos neighbour ) { Direction dir = getDirection(); - if( neighbour.equals( getPos().offset( dir ) ) && hasModem() && !getBlockState().isValidPosition( getWorld(), getPos() ) ) + if( neighbour.equals( getBlockPos().relative( dir ) ) && hasModem() && !getBlockState().canSurvive( getLevel(), getBlockPos() ) ) { if( hasCable() ) { // Drop the modem and convert to cable - Block.spawnAsEntity( getWorld(), getPos(), new ItemStack( Registry.ModItems.WIRED_MODEM.get() ) ); - getWorld().setBlockState( getPos(), getBlockState().with( BlockCable.MODEM, CableModemVariant.None ) ); + Block.popResource( getLevel(), getBlockPos(), new ItemStack( Registry.ModItems.WIRED_MODEM.get() ) ); + getLevel().setBlockAndUpdate( getBlockPos(), getBlockState().setValue( BlockCable.MODEM, CableModemVariant.None ) ); modemChanged(); connectionsChanged(); } else { // Drop everything and remove block - Block.spawnAsEntity( getWorld(), getPos(), new ItemStack( Registry.ModItems.WIRED_MODEM.get() ) ); - getWorld().removeBlock( getPos(), false ); + Block.popResource( getLevel(), getBlockPos(), new ItemStack( Registry.ModItems.WIRED_MODEM.get() ) ); + getLevel().removeBlock( getBlockPos(), false ); // This'll call #destroy(), so we don't need to reset the network here. } @@ -236,16 +236,16 @@ public class TileCable extends TileGeneric public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) { super.onNeighbourTileEntityChange( neighbour ); - if( !world.isRemote && m_peripheralAccessAllowed ) + if( !level.isClientSide && m_peripheralAccessAllowed ) { Direction facing = getDirection(); - if( getPos().offset( facing ).equals( neighbour ) ) refreshPeripheral(); + if( getBlockPos().relative( facing ).equals( neighbour ) ) refreshPeripheral(); } } private void refreshPeripheral() { - if( world != null && !isRemoved() && m_peripheral.attach( world, getPos(), getDirection() ) ) + if( level != null && !isRemoved() && m_peripheral.attach( level, getBlockPos(), getDirection() ) ) { updateConnectedPeripherals(); } @@ -258,7 +258,7 @@ public class TileCable extends TileGeneric if( player.isCrouching() ) return ActionResultType.PASS; if( !canAttachPeripheral() ) return ActionResultType.FAIL; - if( getWorld().isRemote ) return ActionResultType.SUCCESS; + if( getLevel().isClientSide ) return ActionResultType.SUCCESS; String oldName = m_peripheral.getConnectedName(); togglePeripheralAccess(); @@ -267,12 +267,12 @@ public class TileCable extends TileGeneric { if( oldName != null ) { - player.sendStatusMessage( new TranslationTextComponent( "chat.computercraft.wired_modem.peripheral_disconnected", + player.displayClientMessage( new TranslationTextComponent( "chat.computercraft.wired_modem.peripheral_disconnected", CommandCopy.createCopyText( oldName ) ), false ); } if( newName != null ) { - player.sendStatusMessage( new TranslationTextComponent( "chat.computercraft.wired_modem.peripheral_connected", + player.displayClientMessage( new TranslationTextComponent( "chat.computercraft.wired_modem.peripheral_connected", CommandCopy.createCopyText( newName ) ), false ); } } @@ -281,39 +281,39 @@ public class TileCable extends TileGeneric } @Override - public void read( @Nonnull CompoundNBT nbt ) + public void load( @Nonnull CompoundNBT nbt ) { - super.read( nbt ); + super.load( nbt ); m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); m_peripheral.read( nbt, "" ); } @Nonnull @Override - public CompoundNBT write( CompoundNBT nbt ) + public CompoundNBT save( CompoundNBT nbt ) { nbt.putBoolean( NBT_PERIPHERAL_ENABLED, m_peripheralAccessAllowed ); m_peripheral.write( nbt, "" ); - return super.write( nbt ); + return super.save( nbt ); } private void updateBlockState() { BlockState state = getBlockState(); - CableModemVariant oldVariant = state.get( BlockCable.MODEM ); + CableModemVariant oldVariant = state.getValue( BlockCable.MODEM ); CableModemVariant newVariant = CableModemVariant .from( oldVariant.getFacing(), m_modem.getModemState().isOpen(), m_peripheralAccessAllowed ); if( oldVariant != newVariant ) { - world.setBlockState( getPos(), state.with( BlockCable.MODEM, newVariant ) ); + level.setBlockAndUpdate( getBlockPos(), state.setValue( BlockCable.MODEM, newVariant ) ); } } @Override public void blockTick() { - if( getWorld().isRemote ) return; + if( getLevel().isClientSide ) return; Direction oldDirection = modemDirection; refreshDirection(); @@ -333,7 +333,7 @@ public class TileCable extends TileGeneric connectionsChanged(); if( m_peripheralAccessAllowed ) { - m_peripheral.attach( world, pos, modemDirection ); + m_peripheral.attach( level, worldPosition, modemDirection ); updateConnectedPeripherals(); } } @@ -341,14 +341,14 @@ public class TileCable extends TileGeneric void connectionsChanged() { - if( getWorld().isRemote ) return; + if( getLevel().isClientSide ) return; BlockState state = getBlockState(); - World world = getWorld(); - BlockPos current = getPos(); + World world = getLevel(); + BlockPos current = getBlockPos(); for( Direction facing : DirectionUtil.FACINGS ) { - BlockPos offset = current.offset( facing ); + BlockPos offset = current.relative( facing ); if( !world.isAreaLoaded( offset, 0 ) ) continue; LazyOptional element = ComputerCraftAPI.getWiredElementAt( world, offset, facing.getOpposite() ); @@ -374,7 +374,7 @@ public class TileCable extends TileGeneric // Tell anyone who cares that the connection state has changed elementCap = CapabilityUtil.invalidate( elementCap ); - if( getWorld().isRemote ) return; + if( getLevel().isClientSide ) return; // If we can no longer attach peripherals, then detach any // which may have existed @@ -383,7 +383,7 @@ public class TileCable extends TileGeneric m_peripheralAccessAllowed = false; m_peripheral.detach(); m_node.updatePeripherals( Collections.emptyMap() ); - markDirty(); + setChanged(); updateBlockState(); } } @@ -392,7 +392,7 @@ public class TileCable extends TileGeneric { if( !m_peripheralAccessAllowed ) { - m_peripheral.attach( world, getPos(), getDirection() ); + m_peripheral.attach( level, getBlockPos(), getDirection() ); if( !m_peripheral.hasPeripheral() ) return; m_peripheralAccessAllowed = true; @@ -452,12 +452,12 @@ public class TileCable extends TileGeneric boolean hasCable() { - return getBlockState().get( BlockCable.CABLE ); + return getBlockState().getValue( BlockCable.CABLE ); } public boolean hasModem() { - return getBlockState().get( BlockCable.MODEM ) != CableModemVariant.None; + return getBlockState().getValue( BlockCable.MODEM ) != CableModemVariant.None; } private boolean canAttachPeripheral() diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java index b6e0d7029..98e63377f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileWiredModemFull.java @@ -80,14 +80,14 @@ public class TileWiredModemFull extends TileGeneric @Override public World getWorld() { - return m_entity.getWorld(); + return m_entity.getLevel(); } @Nonnull @Override public Vec3d getPosition() { - BlockPos pos = m_entity.getPos(); + BlockPos pos = m_entity.getBlockPos(); return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); } } @@ -113,14 +113,14 @@ public class TileWiredModemFull extends TileGeneric super( type ); for( int i = 0; i < m_peripherals.length; i++ ) { - Direction facing = Direction.byIndex( i ); + Direction facing = Direction.from3DDataValue( i ); m_peripherals[i] = new WiredModemLocalPeripheral( () -> refreshPeripheral( facing ) ); } } private void doRemove() { - if( world == null || !world.isRemote ) + if( level == null || !level.isClientSide ) { m_node.remove(); m_connectionsFormed = false; @@ -154,9 +154,9 @@ public class TileWiredModemFull extends TileGeneric } @Override - public void remove() + public void setRemoved() { - super.remove(); + super.setRemoved(); doRemove(); } @@ -169,11 +169,11 @@ public class TileWiredModemFull extends TileGeneric @Override public void onNeighbourTileEntityChange( @Nonnull BlockPos neighbour ) { - if( !world.isRemote && m_peripheralAccessAllowed ) + if( !level.isClientSide && m_peripheralAccessAllowed ) { for( Direction facing : DirectionUtil.FACINGS ) { - if( getPos().offset( facing ).equals( neighbour ) ) refreshPeripheral( facing ); + if( getBlockPos().relative( facing ).equals( neighbour ) ) refreshPeripheral( facing ); } } } @@ -181,7 +181,7 @@ public class TileWiredModemFull extends TileGeneric private void refreshPeripheral( @Nonnull Direction facing ) { WiredModemLocalPeripheral peripheral = m_peripherals[facing.ordinal()]; - if( world != null && !isRemoved() && peripheral.attach( world, getPos(), facing ) ) + if( level != null && !isRemoved() && peripheral.attach( level, getBlockPos(), facing ) ) { updateConnectedPeripherals(); } @@ -191,7 +191,7 @@ public class TileWiredModemFull extends TileGeneric @Override public ActionResultType onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { - if( getWorld().isRemote ) return ActionResultType.SUCCESS; + if( getLevel().isClientSide ) return ActionResultType.SUCCESS; // On server, we interacted if a peripheral was found Set oldPeriphNames = getConnectedPeripheralNames(); @@ -217,37 +217,37 @@ public class TileWiredModemFull extends TileGeneric StringTextComponent base = new StringTextComponent( "" ); for( int i = 0; i < names.size(); i++ ) { - if( i > 0 ) base.appendText( ", " ); - base.appendSibling( CommandCopy.createCopyText( names.get( i ) ) ); + if( i > 0 ) base.append( ", " ); + base.append( CommandCopy.createCopyText( names.get( i ) ) ); } - player.sendStatusMessage( new TranslationTextComponent( kind, base ), false ); + player.displayClientMessage( new TranslationTextComponent( kind, base ), false ); } @Override - public void read( @Nonnull CompoundNBT nbt ) + public void load( @Nonnull CompoundNBT nbt ) { - super.read( nbt ); + super.load( nbt ); m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); for( int i = 0; i < m_peripherals.length; i++ ) m_peripherals[i].read( nbt, Integer.toString( i ) ); } @Nonnull @Override - public CompoundNBT write( CompoundNBT nbt ) + public CompoundNBT save( CompoundNBT nbt ) { nbt.putBoolean( NBT_PERIPHERAL_ENABLED, m_peripheralAccessAllowed ); for( int i = 0; i < m_peripherals.length; i++ ) m_peripherals[i].write( nbt, Integer.toString( i ) ); - return super.write( nbt ); + return super.save( nbt ); } private void updateBlockState() { BlockState state = getBlockState(); boolean modemOn = m_modemState.isOpen(), peripheralOn = m_peripheralAccessAllowed; - if( state.get( MODEM_ON ) == modemOn && state.get( PERIPHERAL_ON ) == peripheralOn ) return; + if( state.getValue( MODEM_ON ) == modemOn && state.getValue( PERIPHERAL_ON ) == peripheralOn ) return; - getWorld().setBlockState( getPos(), state.with( MODEM_ON, modemOn ).with( PERIPHERAL_ON, peripheralOn ) ); + getLevel().setBlockAndUpdate( getBlockPos(), state.setValue( MODEM_ON, modemOn ).setValue( PERIPHERAL_ON, peripheralOn ) ); } @Override @@ -260,7 +260,7 @@ public class TileWiredModemFull extends TileGeneric @Override public void blockTick() { - if( getWorld().isRemote ) return; + if( getLevel().isClientSide ) return; if( m_modemState.pollChanged() ) updateBlockState(); @@ -273,7 +273,7 @@ public class TileWiredModemFull extends TileGeneric { for( Direction facing : DirectionUtil.FACINGS ) { - m_peripherals[facing.ordinal()].attach( world, getPos(), facing ); + m_peripherals[facing.ordinal()].attach( level, getBlockPos(), facing ); } updateConnectedPeripherals(); } @@ -282,13 +282,13 @@ public class TileWiredModemFull extends TileGeneric private void connectionsChanged() { - if( getWorld().isRemote ) return; + if( getLevel().isClientSide ) return; - World world = getWorld(); - BlockPos current = getPos(); + World world = getLevel(); + BlockPos current = getBlockPos(); for( Direction facing : DirectionUtil.FACINGS ) { - BlockPos offset = current.offset( facing ); + BlockPos offset = current.relative( facing ); if( !world.isAreaLoaded( offset, 0 ) ) continue; LazyOptional element = ComputerCraftAPI.getWiredElementAt( world, offset, facing.getOpposite() ); @@ -307,7 +307,7 @@ public class TileWiredModemFull extends TileGeneric for( Direction facing : DirectionUtil.FACINGS ) { WiredModemLocalPeripheral peripheral = m_peripherals[facing.ordinal()]; - peripheral.attach( world, getPos(), facing ); + peripheral.attach( level, getBlockPos(), facing ); hasAny |= peripheral.hasPeripheral(); } @@ -401,7 +401,7 @@ public class TileWiredModemFull extends TileGeneric @Override public Vec3d getPosition() { - BlockPos pos = getPos().offset( side ); + BlockPos pos = getBlockPos().relative( side ); return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java index 190a99930..f93e593b9 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemLocalPeripheral.java @@ -141,7 +141,7 @@ public final class WiredModemLocalPeripheral @Nullable private IPeripheral getPeripheralFrom( World world, BlockPos pos, Direction direction ) { - BlockPos offset = pos.offset( direction ); + BlockPos offset = pos.relative( direction ); Block block = world.getBlockState( offset ).getBlock(); if( block == Registry.ModBlocks.WIRED_MODEM_FULL.get() || block == Registry.ModBlocks.CABLE.get() ) return null; diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java index 8a6fd22d2..7655d15a3 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/BlockWirelessModem.java @@ -31,6 +31,8 @@ import javax.annotation.Nullable; import static dan200.computercraft.shared.util.WaterloggableHelpers.*; +import net.minecraft.block.Block.Properties; + public class BlockWirelessModem extends BlockGeneric implements IWaterLoggable { public static final DirectionProperty FACING = BlockStateProperties.FACING; @@ -39,14 +41,14 @@ public class BlockWirelessModem extends BlockGeneric implements IWaterLoggable public BlockWirelessModem( Properties settings, RegistryObject> type ) { super( settings, type ); - setDefaultState( getStateContainer().getBaseState() - .with( FACING, Direction.NORTH ) - .with( ON, false ) - .with( WATERLOGGED, false ) ); + registerDefaultState( getStateDefinition().any() + .setValue( FACING, Direction.NORTH ) + .setValue( ON, false ) + .setValue( WATERLOGGED, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void createBlockStateDefinition( StateContainer.Builder builder ) { builder.add( FACING, ON, WATERLOGGED ); } @@ -56,7 +58,7 @@ public class BlockWirelessModem extends BlockGeneric implements IWaterLoggable @Deprecated public VoxelShape getShape( BlockState blockState, @Nonnull IBlockReader blockView, @Nonnull BlockPos blockPos, @Nonnull ISelectionContext context ) { - return ModemShapes.getBounds( blockState.get( FACING ) ); + return ModemShapes.getBounds( blockState.getValue( FACING ) ); } @Nonnull @@ -70,30 +72,30 @@ public class BlockWirelessModem extends BlockGeneric implements IWaterLoggable @Nonnull @Override @Deprecated - public BlockState updatePostPlacement( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos ) + public BlockState updateShape( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos ) { updateWaterloggedPostPlacement( state, world, pos ); - return side == state.get( FACING ) && !state.isValidPosition( world, pos ) - ? state.getFluidState().getBlockState() + return side == state.getValue( FACING ) && !state.canSurvive( world, pos ) + ? state.getFluidState().createLegacyBlock() : state; } @Override @Deprecated - public boolean isValidPosition( BlockState state, IWorldReader world, BlockPos pos ) + public boolean canSurvive( BlockState state, IWorldReader world, BlockPos pos ) { - Direction facing = state.get( FACING ); - BlockPos offsetPos = pos.offset( facing ); + Direction facing = state.getValue( FACING ); + BlockPos offsetPos = pos.relative( facing ); BlockState offsetState = world.getBlockState( offsetPos ); - return hasSolidSide( offsetState, world, offsetPos, facing.getOpposite() ); + return isFaceSturdy( offsetState, world, offsetPos, facing.getOpposite() ); } @Nullable @Override public BlockState getStateForPlacement( BlockItemUseContext placement ) { - return getDefaultState() - .with( FACING, placement.getFace().getOpposite() ) - .with( WATERLOGGED, getWaterloggedStateForPlacement( placement ) ); + return defaultBlockState() + .setValue( FACING, placement.getClickedFace().getOpposite() ) + .setValue( WATERLOGGED, getWaterloggedStateForPlacement( placement ) ); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java index bf187d494..066b0cbf8 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/TileWirelessModem.java @@ -41,14 +41,14 @@ public class TileWirelessModem extends TileGeneric @Override public World getWorld() { - return entity.getWorld(); + return entity.getLevel(); } @Nonnull @Override public Vec3d getPosition() { - BlockPos pos = entity.getPos().offset( entity.modemDirection ); + BlockPos pos = entity.getBlockPos().relative( entity.modemDirection ); return new Vec3d( pos.getX(), pos.getY(), pos.getZ() ); } @@ -99,11 +99,11 @@ public class TileWirelessModem extends TileGeneric } @Override - public void updateContainingBlockInfo() + public void clearCache() { - super.updateContainingBlockInfo(); + super.clearCache(); hasModemDirection = false; - world.getPendingBlockTicks().scheduleTick( getPos(), getBlockState().getBlock(), 0 ); + level.getBlockTicks().scheduleTick( getBlockPos(), getBlockState().getBlock(), 0 ); } @Override @@ -124,16 +124,16 @@ public class TileWirelessModem extends TileGeneric if( hasModemDirection ) return; hasModemDirection = true; - modemDirection = getBlockState().get( BlockWirelessModem.FACING ); + modemDirection = getBlockState().getValue( BlockWirelessModem.FACING ); } private void updateBlockState() { boolean on = modem.getModemState().isOpen(); BlockState state = getBlockState(); - if( state.get( BlockWirelessModem.ON ) != on ) + if( state.getValue( BlockWirelessModem.ON ) != on ) { - getWorld().setBlockState( getPos(), state.with( BlockWirelessModem.ON, on ) ); + getLevel().setBlockAndUpdate( getBlockPos(), state.setValue( BlockWirelessModem.ON, on ) ); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessModemPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessModemPeripheral.java index 2008a4bec..dc2296e8c 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessModemPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessModemPeripheral.java @@ -50,7 +50,7 @@ public abstract class WirelessModemPeripheral extends ModemPeripheral } if( position.y > 96.0 && maxRange > minRange ) { - return minRange + (position.y - 96.0) * ((maxRange - minRange) / ((world.getHeight() - 1) - 96.0)); + return minRange + (position.y - 96.0) * ((maxRange - minRange) / ((world.getMaxBuildHeight() - 1) - 96.0)); } return minRange; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java index 0fd216b61..72adfb42e 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java @@ -70,7 +70,7 @@ public class WirelessNetwork implements IPacketNetwork if( receiver.getWorld() == sender.getWorld() ) { double receiveRange = Math.max( range, receiver.getRange() ); // Ensure range is symmetrical - double distanceSq = receiver.getPosition().squareDistanceTo( sender.getPosition() ); + double distanceSq = receiver.getPosition().distanceToSqr( sender.getPosition() ); if( interdimensional || receiver.isInterdimensional() || distanceSq <= receiveRange * receiveRange ) { receiver.receiveSameDimension( packet, Math.sqrt( distanceSq ) ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java index caa4146b6..b863f9e89 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java @@ -25,6 +25,8 @@ import net.minecraftforge.fml.RegistryObject; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.block.Block.Properties; + public class BlockMonitor extends BlockGeneric { public static final DirectionProperty ORIENTATION = DirectionProperty.create( "orientation", @@ -38,14 +40,14 @@ public class BlockMonitor extends BlockGeneric { super( settings, type ); // TODO: Test underwater - do we need isSolid at all? - setDefaultState( getStateContainer().getBaseState() - .with( ORIENTATION, Direction.NORTH ) - .with( FACING, Direction.NORTH ) - .with( STATE, MonitorEdgeState.NONE ) ); + registerDefaultState( getStateDefinition().any() + .setValue( ORIENTATION, Direction.NORTH ) + .setValue( FACING, Direction.NORTH ) + .setValue( STATE, MonitorEdgeState.NONE ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void createBlockStateDefinition( StateContainer.Builder builder ) { builder.add( ORIENTATION, FACING, STATE ); } @@ -54,7 +56,7 @@ public class BlockMonitor extends BlockGeneric @Nullable public BlockState getStateForPlacement( BlockItemUseContext context ) { - float pitch = context.getPlayer() == null ? 0 : context.getPlayer().rotationPitch; + float pitch = context.getPlayer() == null ? 0 : context.getPlayer().xRot; Direction orientation; if( pitch > 66.5f ) { @@ -71,18 +73,18 @@ public class BlockMonitor extends BlockGeneric orientation = Direction.NORTH; } - return getDefaultState() - .with( FACING, context.getPlacementHorizontalFacing().getOpposite() ) - .with( ORIENTATION, orientation ); + return defaultBlockState() + .setValue( FACING, context.getHorizontalDirection().getOpposite() ) + .setValue( ORIENTATION, orientation ); } @Override - public void onBlockPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState blockState, @Nullable LivingEntity livingEntity, @Nonnull ItemStack itemStack ) + public void setPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState blockState, @Nullable LivingEntity livingEntity, @Nonnull ItemStack itemStack ) { - super.onBlockPlacedBy( world, pos, blockState, livingEntity, itemStack ); + super.setPlacedBy( world, pos, blockState, livingEntity, itemStack ); - TileEntity entity = world.getTileEntity( pos ); - if( entity instanceof TileMonitor && !world.isRemote ) + TileEntity entity = world.getBlockEntity( pos ); + if( entity instanceof TileMonitor && !world.isClientSide ) { TileMonitor monitor = (TileMonitor) entity; monitor.contractNeighbours(); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/ClientMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/ClientMonitor.java index 935e1a12e..5cda81809 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/ClientMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/ClientMonitor.java @@ -64,15 +64,15 @@ public final class ClientMonitor extends ClientTerminal deleteBuffers(); - tboBuffer = GlStateManager.genBuffers(); - GlStateManager.bindBuffer( 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.genTexture(); + 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.bindBuffer( GL31.GL_TEXTURE_BUFFER, 0 ); + GlStateManager._glBindBuffer( GL31.GL_TEXTURE_BUFFER, 0 ); addMonitor(); return true; @@ -82,7 +82,7 @@ public final class ClientMonitor extends ClientTerminal if( buffer != null ) return false; deleteBuffers(); - buffer = new VertexBuffer( FixedWidthFontRenderer.TYPE.getVertexFormat() ); + buffer = new VertexBuffer( FixedWidthFontRenderer.TYPE.format() ); addMonitor(); return true; @@ -110,7 +110,7 @@ public final class ClientMonitor extends ClientTerminal if( tboTexture != 0 ) { - GlStateManager.deleteTexture( tboTexture ); + GlStateManager._deleteTexture( tboTexture ); tboTexture = 0; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java index 30203974c..9fc07e130 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorEdgeState.java @@ -60,12 +60,12 @@ public enum MonitorEdgeState implements IStringSerializable @Override public String toString() { - return getName(); + return getSerializedName(); } @Nonnull @Override - public String getName() + public String getSerializedName() { return name; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java index f05a46c55..13f4a71f2 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorWatcher.java @@ -49,7 +49,7 @@ public final class MonitorWatcher Chunk chunk = (Chunk) event.getWorld().getChunk( chunkPos.x, chunkPos.z, ChunkStatus.FULL, false ); if( chunk == null ) return; - for( TileEntity te : chunk.getTileEntityMap().values() ) + for( TileEntity te : chunk.getBlockEntities().values() ) { // Find all origin monitors who are not already on the queue. if( !(te instanceof TileMonitor) ) continue; @@ -61,7 +61,7 @@ public final class MonitorWatcher // We use the cached terminal state if available - this is guaranteed to TerminalState state = monitor.cached; if( state == null ) state = monitor.cached = serverMonitor.write(); - NetworkHandler.sendToPlayer( event.getPlayer(), new MonitorClientMessage( monitor.getPos(), state ) ); + NetworkHandler.sendToPlayer( event.getPlayer(), new MonitorClientMessage( monitor.getBlockPos(), state ) ); } } @@ -80,12 +80,12 @@ public final class MonitorWatcher ServerMonitor monitor = getMonitor( tile ); if( monitor == null ) continue; - BlockPos pos = tile.getPos(); - World world = tile.getWorld(); + BlockPos pos = tile.getBlockPos(); + World world = tile.getLevel(); if( !(world instanceof ServerWorld) ) continue; Chunk chunk = world.getChunkAt( pos ); - if( !((ServerWorld) world).getChunkProvider().chunkManager.getTrackingPlayers( chunk.getPos(), false ).findAny().isPresent() ) + if( !((ServerWorld) world).getChunkSource().chunkMap.getPlayers( chunk.getPos(), false ).findAny().isPresent() ) { continue; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java index 49ce409a5..7456c7ba0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -86,13 +86,13 @@ public class TileMonitor extends TileGeneric // TODO: Call this before using the block if( m_destroyed ) return; m_destroyed = true; - if( !getWorld().isRemote ) contractNeighbours(); + if( !getLevel().isClientSide ) contractNeighbours(); } @Override - public void remove() + public void setRemoved() { - super.remove(); + super.setRemoved(); if( m_clientMonitor != null && m_xIndex == 0 && m_yIndex == 0 ) m_clientMonitor.destroy(); } @@ -107,14 +107,14 @@ public class TileMonitor extends TileGeneric @Override public ActionResultType onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { - if( !player.isCrouching() && getFront() == hit.getFace() ) + if( !player.isCrouching() && getFront() == hit.getDirection() ) { - if( !getWorld().isRemote ) + if( !getLevel().isClientSide ) { monitorTouched( - (float) (hit.getHitVec().x - hit.getPos().getX()), - (float) (hit.getHitVec().y - hit.getPos().getY()), - (float) (hit.getHitVec().z - hit.getPos().getZ()) + (float) (hit.getLocation().x - hit.getBlockPos().getX()), + (float) (hit.getLocation().y - hit.getBlockPos().getY()), + (float) (hit.getLocation().z - hit.getBlockPos().getZ()) ); } return ActionResultType.SUCCESS; @@ -125,19 +125,19 @@ public class TileMonitor extends TileGeneric @Nonnull @Override - public CompoundNBT write( CompoundNBT tag ) + public CompoundNBT save( CompoundNBT tag ) { tag.putInt( NBT_X, m_xIndex ); tag.putInt( NBT_Y, m_yIndex ); tag.putInt( NBT_WIDTH, m_width ); tag.putInt( NBT_HEIGHT, m_height ); - return super.write( tag ); + return super.save( tag ); } @Override - public void read( @Nonnull CompoundNBT tag ) + public void load( @Nonnull CompoundNBT tag ) { - super.read( tag ); + super.load( tag ); m_xIndex = tag.getInt( NBT_X ); m_yIndex = tag.getInt( NBT_Y ); m_width = tag.getInt( NBT_WIDTH ); @@ -233,8 +233,8 @@ public class TileMonitor extends TileGeneric { // Otherwise fetch the origin and attempt to get its monitor // Note this may load chunks, but we don't really have a choice here. - BlockPos pos = getPos(); - TileEntity te = world.getTileEntity( pos.offset( getRight(), -m_xIndex ).offset( getDown(), -m_yIndex ) ); + BlockPos pos = getBlockPos(); + TileEntity te = level.getBlockEntity( pos.relative( getRight(), -m_xIndex ).relative( getDown(), -m_yIndex ) ); if( !(te instanceof TileMonitor) ) return null; return m_serverMonitor = ((TileMonitor) te).createServerMonitor(); @@ -245,8 +245,8 @@ public class TileMonitor extends TileGeneric { if( m_clientMonitor != null ) return m_clientMonitor; - BlockPos pos = getPos(); - TileEntity te = world.getTileEntity( pos.offset( getRight(), -m_xIndex ).offset( getDown(), -m_yIndex ) ); + BlockPos pos = getBlockPos(); + TileEntity te = level.getBlockEntity( pos.relative( getRight(), -m_xIndex ).relative( getDown(), -m_yIndex ) ); if( !(te instanceof TileMonitor) ) return null; return m_clientMonitor = ((TileMonitor) te).m_clientMonitor; @@ -305,7 +305,7 @@ public class TileMonitor extends TileGeneric { if( m_xIndex != 0 || m_yIndex != 0 ) { - ComputerCraft.log.warn( "Receiving monitor state for non-origin terminal at {}", getPos() ); + ComputerCraft.log.warn( "Receiving monitor state for non-origin terminal at {}", getBlockPos() ); return; } @@ -317,8 +317,8 @@ public class TileMonitor extends TileGeneric private void updateBlockState() { - getWorld().setBlockState( getPos(), getBlockState() - .with( BlockMonitor.STATE, MonitorEdgeState.fromConnections( + getLevel().setBlock( getBlockPos(), getBlockState() + .setValue( BlockMonitor.STATE, MonitorEdgeState.fromConnections( m_yIndex < m_height - 1, m_yIndex > 0, m_xIndex > 0, m_xIndex < m_width - 1 ) ), 2 ); } @@ -329,13 +329,13 @@ public class TileMonitor extends TileGeneric // Ensure we're actually a monitor block. This _should_ always be the case, but sometimes there's // fun problems with the block being missing on the client. BlockState state = getBlockState(); - return state.has( BlockMonitor.FACING ) ? state.get( BlockMonitor.FACING ) : Direction.NORTH; + return state.hasProperty( BlockMonitor.FACING ) ? state.getValue( BlockMonitor.FACING ) : Direction.NORTH; } public Direction getOrientation() { BlockState state = getBlockState(); - return state.has( BlockMonitor.ORIENTATION ) ? state.get( BlockMonitor.ORIENTATION ) : Direction.NORTH; + return state.hasProperty( BlockMonitor.ORIENTATION ) ? state.getValue( BlockMonitor.ORIENTATION ) : Direction.NORTH; } public Direction getFront() @@ -346,7 +346,7 @@ public class TileMonitor extends TileGeneric public Direction getRight() { - return getDirection().rotateYCCW(); + return getDirection().getCounterClockWise(); } public Direction getDown() @@ -378,13 +378,13 @@ public class TileMonitor extends TileGeneric private TileMonitor getSimilarMonitorAt( BlockPos pos ) { - if( pos.equals( getPos() ) ) return this; + if( pos.equals( getBlockPos() ) ) return this; int y = pos.getY(); - World world = getWorld(); + World world = getLevel(); if( world == null || !world.isAreaLoaded( pos, 0 ) ) return null; - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); if( !(tile instanceof TileMonitor) ) return null; TileMonitor monitor = (TileMonitor) tile; @@ -395,12 +395,12 @@ public class TileMonitor extends TileGeneric private TileMonitor getNeighbour( int x, int y ) { - BlockPos pos = getPos(); + BlockPos pos = getBlockPos(); Direction right = getRight(); Direction down = getDown(); int xOffset = -m_xIndex + x; int yOffset = -m_yIndex + y; - return getSimilarMonitorAt( pos.offset( right, xOffset ).offset( down, yOffset ) ); + return getSimilarMonitorAt( pos.relative( right, xOffset ).relative( down, yOffset ) ); } private TileMonitor getOrigin() @@ -677,8 +677,8 @@ public class TileMonitor extends TileGeneric TileMonitor end = getNeighbour( m_width - 1, m_height - 1 ); if( start != null && end != null ) { - BlockPos startPos = start.getPos(); - BlockPos endPos = end.getPos(); + BlockPos startPos = start.getBlockPos(); + BlockPos endPos = end.getBlockPos(); int minX = Math.min( startPos.getX(), endPos.getX() ); int minY = Math.min( startPos.getY(), endPos.getY() ); int minZ = Math.min( startPos.getZ(), endPos.getZ() ); @@ -689,13 +689,13 @@ public class TileMonitor extends TileGeneric } else { - BlockPos pos = getPos(); + BlockPos pos = getBlockPos(); return new AxisAlignedBB( pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1 ); } } @Override - public double getMaxRenderDistanceSquared() + public double getViewDistance() { return ComputerCraft.monitorDistanceSq; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java index bdc5bed57..9dde86617 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java @@ -27,6 +27,8 @@ import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.block.Block.Properties; + public class BlockPrinter extends BlockGeneric { private static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; @@ -36,14 +38,14 @@ public class BlockPrinter extends BlockGeneric public BlockPrinter( Properties settings ) { super( settings, Registry.ModTiles.PRINTER ); - setDefaultState( getStateContainer().getBaseState() - .with( FACING, Direction.NORTH ) - .with( TOP, false ) - .with( BOTTOM, false ) ); + registerDefaultState( getStateDefinition().any() + .setValue( FACING, Direction.NORTH ) + .setValue( TOP, false ) + .setValue( BOTTOM, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder properties ) + protected void createBlockStateDefinition( StateContainer.Builder properties ) { properties.add( FACING, TOP, BOTTOM ); } @@ -52,34 +54,34 @@ public class BlockPrinter extends BlockGeneric @Override public BlockState getStateForPlacement( BlockItemUseContext placement ) { - return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); + return defaultBlockState().setValue( FACING, placement.getHorizontalDirection().getOpposite() ); } @Override - public void harvestBlock( @Nonnull World world, @Nonnull PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, @Nonnull ItemStack stack ) + public void playerDestroy( @Nonnull World world, @Nonnull PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, @Nonnull ItemStack stack ) { if( te instanceof INameable && ((INameable) te).hasCustomName() ) { - player.addStat( Stats.BLOCK_MINED.get( this ) ); - player.addExhaustion( 0.005F ); + player.awardStat( Stats.BLOCK_MINED.get( this ) ); + player.causeFoodExhaustion( 0.005F ); ItemStack result = new ItemStack( this ); - result.setDisplayName( ((INameable) te).getCustomName() ); - spawnAsEntity( world, pos, result ); + result.setHoverName( ((INameable) te).getCustomName() ); + popResource( world, pos, result ); } else { - super.harvestBlock( world, player, pos, state, te, stack ); + super.playerDestroy( world, player, pos, state, te, stack ); } } @Override - public void onBlockPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack ) + public void setPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, ItemStack stack ) { - if( stack.hasDisplayName() ) + if( stack.hasCustomHoverName() ) { - TileEntity tileentity = world.getTileEntity( pos ); - if( tileentity instanceof TilePrinter ) ((TilePrinter) tileentity).customName = stack.getDisplayName(); + TileEntity tileentity = world.getBlockEntity( pos ); + if( tileentity instanceof TilePrinter ) ((TilePrinter) tileentity).customName = stack.getHoverName(); } } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java index deb5f09d5..50bda22f4 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java @@ -30,7 +30,7 @@ public class ContainerPrinter extends Container this.properties = properties; this.inventory = inventory; - trackIntArray( properties ); + addDataSlots( properties ); // Ink slot addSlot( new Slot( inventory, 0, 13, 35 ) ); @@ -73,44 +73,44 @@ public class ContainerPrinter extends Container } @Override - public boolean canInteractWith( @Nonnull PlayerEntity player ) + public boolean stillValid( @Nonnull PlayerEntity player ) { - return inventory.isUsableByPlayer( player ); + return inventory.stillValid( player ); } @Nonnull @Override - public ItemStack transferStackInSlot( @Nonnull PlayerEntity player, int index ) + public ItemStack quickMoveStack( @Nonnull PlayerEntity player, int index ) { - Slot slot = inventorySlots.get( index ); - if( slot == null || !slot.getHasStack() ) return ItemStack.EMPTY; - ItemStack stack = slot.getStack(); + Slot slot = slots.get( index ); + if( slot == null || !slot.hasItem() ) return ItemStack.EMPTY; + ItemStack stack = slot.getItem(); ItemStack result = stack.copy(); if( index < 13 ) { // Transfer from printer to inventory - if( !mergeItemStack( stack, 13, 49, true ) ) return ItemStack.EMPTY; + if( !moveItemStackTo( stack, 13, 49, true ) ) return ItemStack.EMPTY; } else { // Transfer from inventory to printer if( TilePrinter.isInk( stack ) ) { - if( !mergeItemStack( stack, 0, 1, false ) ) return ItemStack.EMPTY; + if( !moveItemStackTo( stack, 0, 1, false ) ) return ItemStack.EMPTY; } else //if is paper { - if( !mergeItemStack( stack, 1, 13, false ) ) return ItemStack.EMPTY; + if( !moveItemStackTo( stack, 1, 13, false ) ) return ItemStack.EMPTY; } } if( stack.isEmpty() ) { - slot.putStack( ItemStack.EMPTY ); + slot.set( ItemStack.EMPTY ); } else { - slot.onSlotChanged(); + slot.setChanged(); } if( stack.getCount() == result.getCount() ) return ItemStack.EMPTY; diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java index 8e63d3ae5..17ad232da 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java @@ -86,14 +86,14 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent { if( player.isCrouching() ) return ActionResultType.PASS; - if( !getWorld().isRemote ) NetworkHooks.openGui( (ServerPlayerEntity) player, this ); + if( !getLevel().isClientSide ) NetworkHooks.openGui( (ServerPlayerEntity) player, this ); return ActionResultType.SUCCESS; } @Override - public void read( @Nonnull CompoundNBT nbt ) + public void load( @Nonnull CompoundNBT nbt ) { - super.read( nbt ); + super.load( nbt ); customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; @@ -111,7 +111,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent @Nonnull @Override - public CompoundNBT write( @Nonnull CompoundNBT nbt ) + public CompoundNBT save( @Nonnull CompoundNBT nbt ) { if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); @@ -126,7 +126,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent // Write inventory ItemStackHelper.saveAllItems( nbt, m_inventory ); - return super.write( nbt ); + return super.save( nbt ); } boolean isPrinting() @@ -136,7 +136,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent // IInventory implementation @Override - public int getSizeInventory() + public int getContainerSize() { return m_inventory.size(); } @@ -153,32 +153,32 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent @Nonnull @Override - public ItemStack getStackInSlot( int slot ) + public ItemStack getItem( int slot ) { return m_inventory.get( slot ); } @Nonnull @Override - public ItemStack removeStackFromSlot( int slot ) + public ItemStack removeItemNoUpdate( int slot ) { ItemStack result = m_inventory.get( slot ); m_inventory.set( slot, ItemStack.EMPTY ); - markDirty(); + setChanged(); updateBlockState(); return result; } @Nonnull @Override - public ItemStack decrStackSize( int slot, int count ) + public ItemStack removeItem( int slot, int count ) { ItemStack stack = m_inventory.get( slot ); if( stack.isEmpty() ) return ItemStack.EMPTY; if( stack.getCount() <= count ) { - setInventorySlotContents( slot, ItemStack.EMPTY ); + setItem( slot, ItemStack.EMPTY ); return stack; } @@ -188,28 +188,28 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent m_inventory.set( slot, ItemStack.EMPTY ); updateBlockState(); } - markDirty(); + setChanged(); return part; } @Override - public void setInventorySlotContents( int slot, @Nonnull ItemStack stack ) + public void setItem( int slot, @Nonnull ItemStack stack ) { m_inventory.set( slot, stack ); - markDirty(); + setChanged(); updateBlockState(); } @Override - public void clear() + public void clearContent() { for( int i = 0; i < m_inventory.size(); i++ ) m_inventory.set( i, ItemStack.EMPTY ); - markDirty(); + setChanged(); updateBlockState(); } @Override - public boolean isItemValidForSlot( int slot, @Nonnull ItemStack stack ) + public boolean canPlaceItem( int slot, @Nonnull ItemStack stack ) { if( slot == 0 ) { @@ -226,7 +226,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent } @Override - public boolean isUsableByPlayer( @Nonnull PlayerEntity playerEntity ) + public boolean stillValid( @Nonnull PlayerEntity playerEntity ) { return isUsable( playerEntity, false ); } @@ -361,7 +361,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent updateBlockState(); } - markDirty(); + setChanged(); m_printing = true; return true; } @@ -384,7 +384,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent { if( m_inventory.get( slot ).isEmpty() ) { - setInventorySlotContents( slot, stack ); + setItem( slot, stack ); m_printing = false; return true; } @@ -400,10 +400,10 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent if( !stack.isEmpty() ) { // Remove the stack from the inventory - setInventorySlotContents( i, ItemStack.EMPTY ); + setItem( i, ItemStack.EMPTY ); // Spawn the item in the world - WorldUtil.dropItemStack( stack, getWorld(), new Vec3d( getPos() ).add( 0.5, 0.75, 0.5 ) ); + WorldUtil.dropItemStack( stack, getLevel(), new Vec3d( getBlockPos() ).add( 0.5, 0.75, 0.5 ) ); } } } @@ -435,12 +435,12 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent private void updateBlockState( boolean top, boolean bottom ) { - if( removed ) return; + if( remove ) return; BlockState state = getBlockState(); - if( state.get( BlockPrinter.TOP ) == top & state.get( BlockPrinter.BOTTOM ) == bottom ) return; + if( state.getValue( BlockPrinter.TOP ) == top & state.getValue( BlockPrinter.BOTTOM ) == bottom ) return; - getWorld().setBlockState( getPos(), state.with( BlockPrinter.TOP, top ).with( BlockPrinter.BOTTOM, bottom ) ); + getLevel().setBlockAndUpdate( getBlockPos(), state.setValue( BlockPrinter.TOP, top ).setValue( BlockPrinter.BOTTOM, bottom ) ); } @Nonnull @@ -474,7 +474,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent @Override public ITextComponent getName() { - return customName != null ? customName : new TranslationTextComponent( getBlockState().getBlock().getTranslationKey() ); + return customName != null ? customName : new TranslationTextComponent( getBlockState().getBlock().getDescriptionId() ); } @Override diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java index 8e8cfdd08..1aa81c6a6 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java @@ -17,6 +17,8 @@ import net.minecraft.util.Direction; import javax.annotation.Nullable; +import net.minecraft.block.Block.Properties; + public class BlockSpeaker extends BlockGeneric { private static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; @@ -24,12 +26,12 @@ public class BlockSpeaker extends BlockGeneric public BlockSpeaker( Properties settings ) { super( settings, Registry.ModTiles.SPEAKER ); - setDefaultState( getStateContainer().getBaseState() - .with( FACING, Direction.NORTH ) ); + registerDefaultState( getStateDefinition().any() + .setValue( FACING, Direction.NORTH ) ); } @Override - protected void fillStateContainer( StateContainer.Builder properties ) + protected void createBlockStateDefinition( StateContainer.Builder properties ) { properties.add( FACING ); } @@ -38,6 +40,6 @@ public class BlockSpeaker extends BlockGeneric @Override public BlockState getStateForPlacement( BlockItemUseContext placement ) { - return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); + return defaultBlockState().setValue( FACING, placement.getHorizontalDirection().getOpposite() ); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java index 59316a669..9ebf8c10a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java @@ -117,7 +117,7 @@ public abstract class SpeakerPeripheral implements IPeripheral NoteBlockInstrument instrument = null; for( NoteBlockInstrument testInstrument : NoteBlockInstrument.values() ) { - if( testInstrument.getName().equalsIgnoreCase( name ) ) + if( testInstrument.getSerializedName().equalsIgnoreCase( name ) ) { instrument = testInstrument; break; @@ -128,7 +128,7 @@ public abstract class SpeakerPeripheral implements IPeripheral if( instrument == null ) throw new LuaException( "Invalid instrument, \"" + name + "\"!" ); // If the resource location for note block notes changes, this method call will need to be updated - boolean success = playSound( context, instrument.getSound().getRegistryName(), volume, (float) Math.pow( 2.0, (pitch - 12.0) / 12.0 ), true ); + boolean success = playSound( context, instrument.getSoundEvent().getRegistryName(), volume, (float) Math.pow( 2.0, (pitch - 12.0) / 12.0 ), true ); if( success ) m_notesThisTick.incrementAndGet(); return success; } @@ -151,7 +151,7 @@ public abstract class SpeakerPeripheral implements IPeripheral if( server == null ) return null; float adjVolume = Math.min( volume, 3.0f ); - server.getPlayerList().sendToAllNearExcept( + server.getPlayerList().broadcast( null, pos.x, pos.y, pos.z, adjVolume > 1.0f ? 16 * adjVolume : 16.0, world.dimension.getType(), new SPlaySoundPacket( name, SoundCategory.RECORDS, pos, adjVolume, pitch ) ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java index e0d792284..e06edc73e 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java @@ -73,13 +73,13 @@ public class TileSpeaker extends TileGeneric implements ITickableTileEntity @Override public World getWorld() { - return speaker.getWorld(); + return speaker.getLevel(); } @Override public Vec3d getPosition() { - BlockPos pos = speaker.getPos(); + BlockPos pos = speaker.getBlockPos(); return new Vec3d( pos.getX(), pos.getY(), pos.getZ() ); } diff --git a/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java b/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java index 2dd3ed61d..575f487d9 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java +++ b/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java @@ -70,10 +70,10 @@ public class PocketAPI implements ILuaAPI // Attempt to find the upgrade, starting in the main segment, and then looking in the opposite // one. We start from the position the item is currently in and loop round to the start. - IPocketUpgrade newUpgrade = findUpgrade( inventory.mainInventory, inventory.currentItem, previousUpgrade ); + IPocketUpgrade newUpgrade = findUpgrade( inventory.items, inventory.selected, previousUpgrade ); if( newUpgrade == null ) { - newUpgrade = findUpgrade( inventory.offHandInventory, 0, previousUpgrade ); + newUpgrade = findUpgrade( inventory.offhand, 0, previousUpgrade ); } if( newUpgrade == null ) return new Object[] { false, "Cannot find a valid upgrade" }; @@ -83,10 +83,10 @@ public class PocketAPI implements ILuaAPI ItemStack stack = previousUpgrade.getCraftingItem(); if( !stack.isEmpty() ) { - stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.currentItem ); + stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.selected ); if( !stack.isEmpty() ) { - WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.getPositionVec() ); + WorldUtil.dropItemStack( stack, player.getCommandSenderWorld(), player.position() ); } } } @@ -120,10 +120,10 @@ public class PocketAPI implements ILuaAPI ItemStack stack = previousUpgrade.getCraftingItem(); if( !stack.isEmpty() ) { - stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.currentItem ); + stack = InventoryUtil.storeItems( stack, new PlayerMainInvWrapper( inventory ), inventory.selected ); if( stack.isEmpty() ) { - WorldUtil.dropItemStack( stack, player.getEntityWorld(), player.getPositionVec() ); + WorldUtil.dropItemStack( stack, player.getCommandSenderWorld(), player.position() ); } } diff --git a/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java b/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java index f9dcb00e5..c098c0cd9 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java @@ -54,12 +54,12 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces if( entity instanceof PlayerEntity ) { PlayerInventory inventory = ((PlayerEntity) entity).inventory; - return inventory.mainInventory.contains( m_stack ) || inventory.offHandInventory.contains( m_stack ) ? entity : null; + return inventory.items.contains( m_stack ) || inventory.offhand.contains( m_stack ) ? entity : null; } else if( entity instanceof LivingEntity ) { LivingEntity living = (LivingEntity) entity; - return living.getHeldItemMainhand() == m_stack || living.getHeldItemOffhand() == m_stack ? entity : null; + return living.getMainHandItem() == m_stack || living.getOffhandItem() == m_stack ? entity : null; } else { @@ -116,7 +116,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces @Override public void updateUpgradeNBTData() { - if( m_entity instanceof PlayerEntity ) ((PlayerEntity) m_entity).inventory.markDirty(); + if( m_entity instanceof PlayerEntity ) ((PlayerEntity) m_entity).inventory.setChanged(); } @Override @@ -162,8 +162,8 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces { if( entity != null ) { - setWorld( entity.getEntityWorld() ); - setPosition( entity.getPosition() ); + setWorld( entity.getCommandSenderWorld() ); + setPosition( entity.getCommandSenderBlockPosition() ); } // If a new entity has picked it up then rebroadcast the terminal to them diff --git a/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java index a762936d1..e49aa6b97 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java @@ -26,7 +26,7 @@ public final class ContainerPocketComputer extends ContainerComputerBase private ContainerPocketComputer( int id, ServerComputer computer, ItemPocketComputer item, Hand hand ) { super( Registry.ModContainers.POCKET_COMPUTER.get(), id, p -> { - ItemStack stack = p.getHeldItem( hand ); + ItemStack stack = p.getItemInHand( hand ); return stack.getItem() == item && ItemPocketComputer.getServerComputer( stack ) == computer; }, computer, item.getFamily() ); } @@ -46,7 +46,7 @@ public final class ContainerPocketComputer extends ContainerComputerBase public Factory( ServerComputer computer, ItemStack stack, ItemPocketComputer item, Hand hand ) { this.computer = computer; - this.name = stack.getDisplayName(); + this.name = stack.getHoverName(); this.item = item; this.hand = hand; } diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java index e969d7cd7..12c3228ee 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -45,6 +45,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; +import net.minecraft.item.Item.Properties; + public class ItemPocketComputer extends Item implements IComputerItem, IMedia, IColouredItem { private static final String NBT_UPGRADE = "Upgrade"; @@ -60,24 +62,24 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I { super( settings ); this.family = family; - addPropertyOverride( new ResourceLocation( ComputerCraft.MOD_ID, "state" ), COMPUTER_STATE ); - addPropertyOverride( new ResourceLocation( ComputerCraft.MOD_ID, "coloured" ), COMPUTER_COLOURED ); + addProperty( new ResourceLocation( ComputerCraft.MOD_ID, "state" ), COMPUTER_STATE ); + addProperty( new ResourceLocation( ComputerCraft.MOD_ID, "coloured" ), COMPUTER_COLOURED ); } public ItemStack create( int id, String label, int colour, IPocketUpgrade upgrade ) { ItemStack result = new ItemStack( this ); if( id >= 0 ) result.getOrCreateTag().putInt( NBT_ID, id ); - if( label != null ) result.setDisplayName( new StringTextComponent( label ) ); + if( label != null ) result.setHoverName( new StringTextComponent( label ) ); if( upgrade != null ) result.getOrCreateTag().putString( NBT_UPGRADE, upgrade.getUpgradeID().toString() ); if( colour != -1 ) result.getOrCreateTag().putInt( NBT_COLOUR, colour ); return result; } @Override - public void fillItemGroup( @Nonnull ItemGroup group, @Nonnull NonNullList stacks ) + public void fillItemCategory( @Nonnull ItemGroup group, @Nonnull NonNullList stacks ) { - if( !isInGroup( group ) ) return; + if( !allowdedIn( group ) ) return; stacks.add( create( -1, null, -1, null ) ); for( IPocketUpgrade upgrade : PocketUpgrades.getVanillaUpgrades() ) { @@ -88,7 +90,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I @Override public void inventoryTick( @Nonnull ItemStack stack, World world, @Nonnull Entity entity, int slotNum, boolean selected ) { - if( !world.isRemote ) + if( !world.isClientSide ) { // Server side IInventory inventory = entity instanceof PlayerEntity ? ((PlayerEntity) entity).inventory : null; @@ -107,7 +109,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I if( id != getComputerID( stack ) ) { setComputerID( stack, id ); - if( inventory != null ) inventory.markDirty(); + if( inventory != null ) inventory.setChanged(); } // Sync label @@ -115,7 +117,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I if( !Objects.equal( label, getLabel( stack ) ) ) { setLabel( stack, label ); - if( inventory != null ) inventory.markDirty(); + if( inventory != null ) inventory.setChanged(); } // Update pocket upgrade @@ -134,10 +136,10 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I @Nonnull @Override - public ActionResult onItemRightClick( World world, PlayerEntity player, @Nonnull Hand hand ) + public ActionResult use( World world, PlayerEntity player, @Nonnull Hand hand ) { - ItemStack stack = player.getHeldItem( hand ); - if( !world.isRemote ) + ItemStack stack = player.getItemInHand( hand ); + if( !world.isClientSide ) { PocketServerComputer computer = createServerComputer( world, player.inventory, player, stack ); @@ -164,9 +166,9 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I @Nonnull @Override - public ITextComponent getDisplayName( @Nonnull ItemStack stack ) + public ITextComponent getName( @Nonnull ItemStack stack ) { - String baseString = getTranslationKey( stack ); + String baseString = getDescriptionId( stack ); IPocketUpgrade upgrade = getUpgrade( stack ); if( upgrade != null ) { @@ -176,13 +178,13 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I } else { - return super.getDisplayName( stack ); + return super.getName( stack ); } } @Override - public void addInformation( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, ITooltipFlag flag ) + public void appendHoverText( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, ITooltipFlag flag ) { if( flag.isAdvanced() || getLabel( stack ) == null ) { @@ -190,7 +192,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I if( id >= 0 ) { list.add( new TranslationTextComponent( "gui.computercraft.tooltip.computer_id", id ) - .applyTextStyle( TextFormatting.GRAY ) ); + .withStyle( TextFormatting.GRAY ) ); } } } @@ -213,7 +215,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I public PocketServerComputer createServerComputer( final World world, IInventory inventory, Entity entity, @Nonnull ItemStack stack ) { - if( world.isRemote ) return null; + if( world.isClientSide ) return null; PocketServerComputer computer; int instanceID = getInstanceID( stack ); @@ -249,7 +251,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I computer.updateValues( entity, stack, getUpgrade( stack ) ); computer.addAPI( new PocketAPI( computer ) ); ComputerCraft.serverComputerRegistry.add( instanceID, computer ); - if( inventory != null ) inventory.markDirty(); + if( inventory != null ) inventory.setChanged(); } computer.setWorld( world ); return computer; @@ -319,11 +321,11 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I { if( label != null ) { - stack.setDisplayName( new StringTextComponent( label ) ); + stack.setHoverName( new StringTextComponent( label ) ); } else { - stack.clearCustomName(); + stack.resetHoverName(); } return true; } @@ -409,7 +411,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I public static CompoundNBT getUpgradeInfo( @Nonnull ItemStack stack ) { - return stack.getOrCreateChildTag( NBT_UPGRADE_INFO ); + return stack.getOrCreateTagElement( NBT_UPGRADE_INFO ); } private static final IItemPropertyGetter COMPUTER_STATE = ( stack, world, player ) -> getState( stack ).ordinal(); diff --git a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java index ea84a3042..47c8bdaf3 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java +++ b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketModem.java @@ -47,7 +47,7 @@ public class PocketModem extends AbstractPocketUpgrade PocketModemPeripheral modem = (PocketModemPeripheral) peripheral; - if( entity != null ) modem.setLocation( entity.getEntityWorld(), entity.getEyePosition( 1 ) ); + if( entity != null ) modem.setLocation( entity.getCommandSenderWorld(), entity.getEyePosition( 1 ) ); ModemState state = modem.getModemState(); if( state.pollChanged() ) access.setLight( state.isOpen() ? 0xBA0000 : -1 ); diff --git a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketSpeaker.java b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketSpeaker.java index 4bba1b47c..e0cb29e99 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/pocket/peripherals/PocketSpeaker.java @@ -39,7 +39,7 @@ public class PocketSpeaker extends AbstractPocketUpgrade Entity entity = access.getEntity(); if( entity != null ) { - speaker.setLocation( entity.getEntityWorld(), entity.getEyePosition( 1 ) ); + speaker.setLocation( entity.getCommandSenderWorld(), entity.getEyePosition( 1 ) ); } speaker.update(); diff --git a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java index 17bad137e..0a331a567 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java @@ -28,14 +28,14 @@ public final class PocketComputerUpgradeRecipe extends SpecialRecipe } @Override - public boolean canFit( int x, int y ) + public boolean canCraftInDimensions( int x, int y ) { return x >= 2 && y >= 2; } @Nonnull @Override - public ItemStack getRecipeOutput() + public ItemStack getResultItem() { return PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.NORMAL, null ); } @@ -43,12 +43,12 @@ public final class PocketComputerUpgradeRecipe extends SpecialRecipe @Override public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world ) { - return !getCraftingResult( inventory ).isEmpty(); + return !assemble( inventory ).isEmpty(); } @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) + public ItemStack assemble( @Nonnull CraftingInventory inventory ) { // Scan the grid for a pocket computer ItemStack computer = ItemStack.EMPTY; @@ -59,7 +59,7 @@ public final class PocketComputerUpgradeRecipe extends SpecialRecipe { for( int x = 0; x < inventory.getWidth(); x++ ) { - ItemStack item = inventory.getStackInSlot( x + y * inventory.getWidth() ); + ItemStack item = inventory.getItem( x + y * inventory.getWidth() ); if( !item.isEmpty() && item.getItem() instanceof ItemPocketComputer ) { computer = item; @@ -81,7 +81,7 @@ public final class PocketComputerUpgradeRecipe extends SpecialRecipe { for( int x = 0; x < inventory.getWidth(); x++ ) { - ItemStack item = inventory.getStackInSlot( x + y * inventory.getWidth() ); + ItemStack item = inventory.getItem( x + y * inventory.getWidth() ); if( x == computerX && y == computerY ) continue; if( x == computerX && y == computerY - 1 ) diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 4c5727bfd..38eb89930 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -68,19 +68,19 @@ public final class ComputerCraftProxyCommon public static void registerLoot() { - LootConditionManager.registerCondition( ConstantLootConditionSerializer.of( + LootConditionManager.register( ConstantLootConditionSerializer.of( new ResourceLocation( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.class, BlockNamedEntityLootCondition.INSTANCE ) ); - LootConditionManager.registerCondition( ConstantLootConditionSerializer.of( + LootConditionManager.register( ConstantLootConditionSerializer.of( new ResourceLocation( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.class, PlayerCreativeLootCondition.INSTANCE ) ); - LootConditionManager.registerCondition( ConstantLootConditionSerializer.of( + LootConditionManager.register( ConstantLootConditionSerializer.of( new ResourceLocation( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.class, HasComputerIdLootCondition.INSTANCE @@ -176,16 +176,16 @@ public final class ComputerCraftProxyCommon public static final ResourceLocation LOOT_TREASURE_DISK = new ResourceLocation( ComputerCraft.MOD_ID, "treasure_disk" ); private static final Set TABLES = new HashSet<>( Arrays.asList( - LootTables.CHESTS_SIMPLE_DUNGEON, - LootTables.CHESTS_ABANDONED_MINESHAFT, - LootTables.CHESTS_STRONGHOLD_CORRIDOR, - LootTables.CHESTS_STRONGHOLD_CROSSING, - LootTables.CHESTS_STRONGHOLD_LIBRARY, - LootTables.CHESTS_DESERT_PYRAMID, - LootTables.CHESTS_JUNGLE_TEMPLE, - LootTables.CHESTS_IGLOO_CHEST, - LootTables.CHESTS_WOODLAND_MANSION, - LootTables.CHESTS_VILLAGE_VILLAGE_CARTOGRAPHER + LootTables.SIMPLE_DUNGEON, + LootTables.ABANDONED_MINESHAFT, + LootTables.STRONGHOLD_CORRIDOR, + LootTables.STRONGHOLD_CROSSING, + LootTables.STRONGHOLD_LIBRARY, + LootTables.DESERT_PYRAMID, + LootTables.JUNGLE_TEMPLE, + LootTables.IGLOO_CHEST, + LootTables.WOODLAND_MANSION, + LootTables.VILLAGE_CARTOGRAPHER ) ); @SubscribeEvent @@ -194,9 +194,9 @@ public final class ComputerCraftProxyCommon ResourceLocation name = event.getName(); if( !name.getNamespace().equals( "minecraft" ) || !TABLES.contains( name ) ) return; - event.getTable().addPool( LootPool.builder() - .addEntry( TableLootEntry.builder( LOOT_TREASURE_DISK ) ) - .rolls( ConstantRange.of( 1 ) ) + event.getTable().addPool( LootPool.lootPool() + .add( TableLootEntry.lootTableReference( LOOT_TREASURE_DISK ) ) + .setRolls( ConstantRange.exactly( 1 ) ) .name( "computercraft_treasure" ) .build() ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java index b09bdc4f9..e1d35ce49 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java +++ b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java @@ -308,7 +308,7 @@ public class TurtleAPI implements ILuaAPI public final int getItemCount( Optional slot ) throws LuaException { int actualSlot = checkSlot( slot ).orElse( turtle.getSelectedSlot() ); - return turtle.getInventory().getStackInSlot( actualSlot ).getCount(); + return turtle.getInventory().getItem( actualSlot ).getCount(); } /** @@ -324,7 +324,7 @@ public class TurtleAPI implements ILuaAPI public final int getItemSpace( Optional slot ) throws LuaException { int actualSlot = checkSlot( slot ).orElse( turtle.getSelectedSlot() ); - ItemStack stack = turtle.getInventory().getStackInSlot( actualSlot ); + ItemStack stack = turtle.getInventory().getItem( actualSlot ); return stack.isEmpty() ? 64 : Math.min( stack.getMaxStackSize(), 64 ) - stack.getCount(); } @@ -600,7 +600,7 @@ public class TurtleAPI implements ILuaAPI private Object[] getItemDetail( int slot, boolean detailed ) { - ItemStack stack = turtle.getInventory().getStackInSlot( slot ); + ItemStack stack = turtle.getInventory().getItem( slot ); if( stack.isEmpty() ) return new Object[] { null }; Map table = detailed diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java index 7efc6ceb8..81a42d134 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java @@ -44,11 +44,13 @@ import javax.annotation.Nullable; import static dan200.computercraft.shared.util.WaterloggableHelpers.*; import static net.minecraft.state.properties.BlockStateProperties.WATERLOGGED; +import net.minecraft.block.Block.Properties; + public class BlockTurtle extends BlockComputerBase implements IWaterLoggable { public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; - private static final VoxelShape DEFAULT_SHAPE = VoxelShapes.create( + private static final VoxelShape DEFAULT_SHAPE = VoxelShapes.box( 0.125, 0.125, 0.125, 0.875, 0.875, 0.875 ); @@ -56,14 +58,14 @@ public class BlockTurtle extends BlockComputerBase implements IWater public BlockTurtle( Properties settings, ComputerFamily family, RegistryObject> type ) { super( settings, family, type ); - setDefaultState( getStateContainer().getBaseState() - .with( FACING, Direction.NORTH ) - .with( WATERLOGGED, false ) + registerDefaultState( getStateDefinition().any() + .setValue( FACING, Direction.NORTH ) + .setValue( WATERLOGGED, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void createBlockStateDefinition( StateContainer.Builder builder ) { builder.add( FACING, WATERLOGGED ); } @@ -71,7 +73,7 @@ public class BlockTurtle extends BlockComputerBase implements IWater @Nonnull @Override @Deprecated - public BlockRenderType getRenderType( @Nonnull BlockState state ) + public BlockRenderType getRenderShape( @Nonnull BlockState state ) { return BlockRenderType.ENTITYBLOCK_ANIMATED; } @@ -81,18 +83,18 @@ public class BlockTurtle extends BlockComputerBase implements IWater @Deprecated public VoxelShape getShape( @Nonnull BlockState state, IBlockReader world, @Nonnull BlockPos pos, @Nonnull ISelectionContext context ) { - TileEntity tile = world.getTileEntity( pos ); + TileEntity tile = world.getBlockEntity( pos ); Vec3d offset = tile instanceof TileTurtle ? ((TileTurtle) tile).getRenderOffset( 1.0f ) : Vec3d.ZERO; - return offset.equals( Vec3d.ZERO ) ? DEFAULT_SHAPE : DEFAULT_SHAPE.withOffset( offset.x, offset.y, offset.z ); + return offset.equals( Vec3d.ZERO ) ? DEFAULT_SHAPE : DEFAULT_SHAPE.move( offset.x, offset.y, offset.z ); } @Nullable @Override public BlockState getStateForPlacement( BlockItemUseContext placement ) { - return getDefaultState() - .with( FACING, placement.getPlacementHorizontalFacing() ) - .with( WATERLOGGED, getWaterloggedStateForPlacement( placement ) ); + return defaultBlockState() + .setValue( FACING, placement.getHorizontalDirection() ) + .setValue( WATERLOGGED, getWaterloggedStateForPlacement( placement ) ); } @Nonnull @@ -106,19 +108,19 @@ public class BlockTurtle extends BlockComputerBase implements IWater @Nonnull @Override @Deprecated - public BlockState updatePostPlacement( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos ) + public BlockState updateShape( @Nonnull BlockState state, @Nonnull Direction side, @Nonnull BlockState otherState, @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull BlockPos otherPos ) { updateWaterloggedPostPlacement( state, world, pos ); return state; } @Override - public void onBlockPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack ) + public void setPlacedBy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack ) { - super.onBlockPlacedBy( world, pos, state, player, stack ); + super.setPlacedBy( world, pos, state, player, stack ); - TileEntity tile = world.getTileEntity( pos ); - if( !world.isRemote && tile instanceof TileTurtle ) + TileEntity tile = world.getBlockEntity( pos ); + if( !world.isClientSide && tile instanceof TileTurtle ) { TileTurtle turtle = (TileTurtle) tile; diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index cd5d5973a..46b5fef4c 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -86,10 +86,10 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default protected ServerComputer createComputer( int instanceID, int id ) { ServerComputer computer = new ServerComputer( - getWorld(), id, label, instanceID, getFamily(), + getLevel(), id, label, instanceID, getFamily(), ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight ); - computer.setPosition( getPos() ); + computer.setPosition( getBlockPos() ); computer.addAPI( new TurtleAPI( computer.getAPIEnvironment(), getAccess() ) ); m_brain.setupComputer( computer ); return computer; @@ -109,15 +109,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default super.destroy(); // Drop contents - if( !getWorld().isRemote ) + if( !getLevel().isClientSide ) { - int size = getSizeInventory(); + int size = getContainerSize(); for( int i = 0; i < size; i++ ) { - ItemStack stack = getStackInSlot( i ); + ItemStack stack = getItem( i ); if( !stack.isEmpty() ) { - WorldUtil.dropItemStack( stack, getWorld(), getPos() ); + WorldUtil.dropItemStack( stack, getLevel(), getBlockPos() ); } } } @@ -127,7 +127,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default // Just turn off any redstone we had on for( Direction dir : DirectionUtil.FACINGS ) { - RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); + RedstoneUtil.propagateRedstoneOutput( getLevel(), getBlockPos(), dir ); } } } @@ -154,13 +154,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default public ActionResultType onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { // Apply dye - ItemStack currentItem = player.getHeldItem( hand ); + ItemStack currentItem = player.getItemInHand( hand ); if( !currentItem.isEmpty() ) { if( currentItem.getItem() instanceof DyeItem ) { // Dye to change turtle colour - if( !getWorld().isRemote ) + if( !getLevel().isClientSide ) { DyeColor dye = ((DyeItem) currentItem.getItem()).getDyeColor(); if( m_brain.getDyeColour() != dye ) @@ -177,15 +177,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default else if( currentItem.getItem() == Items.WATER_BUCKET && m_brain.getColour() != -1 ) { // Water to remove turtle colour - if( !getWorld().isRemote ) + if( !getLevel().isClientSide ) { if( m_brain.getColour() != -1 ) { m_brain.setColour( -1 ); if( !player.isCreative() ) { - player.setHeldItem( hand, new ItemStack( Items.BUCKET ) ); - player.inventory.markDirty(); + player.setItemInHand( hand, new ItemStack( Items.BUCKET ) ); + player.inventory.setChanged(); } } } @@ -214,15 +214,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default { super.tick(); m_brain.update(); - if( !getWorld().isRemote && m_inventoryChanged ) + if( !getLevel().isClientSide && m_inventoryChanged ) { ServerComputer computer = getServerComputer(); if( computer != null ) computer.queueEvent( "turtle_inventory" ); m_inventoryChanged = false; - for( int n = 0; n < getSizeInventory(); n++ ) + for( int n = 0; n < getContainerSize(); n++ ) { - m_previousInventory.set( n, getStackInSlot( n ).copy() ); + m_previousInventory.set( n, getItem( n ).copy() ); } } } @@ -256,9 +256,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public void read( @Nonnull CompoundNBT nbt ) + public void load( @Nonnull CompoundNBT nbt ) { - super.read( nbt ); + super.load( nbt ); // Read inventory ListNBT nbttaglist = nbt.getList( "Items", Constants.NBT.TAG_COMPOUND ); @@ -268,9 +268,9 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default { CompoundNBT tag = nbttaglist.getCompound( i ); int slot = tag.getByte( "Slot" ) & 0xff; - if( slot < getSizeInventory() ) + if( slot < getContainerSize() ) { - m_inventory.set( slot, ItemStack.read( tag ) ); + m_inventory.set( slot, ItemStack.of( tag ) ); m_previousInventory.set( slot, m_inventory.get( slot ).copy() ); } } @@ -281,7 +281,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default @Nonnull @Override - public CompoundNBT write( @Nonnull CompoundNBT nbt ) + public CompoundNBT save( @Nonnull CompoundNBT nbt ) { // Write inventory ListNBT nbttaglist = new ListNBT(); @@ -291,7 +291,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default { CompoundNBT tag = new CompoundNBT(); tag.putByte( "Slot", (byte) i ); - m_inventory.get( i ).write( tag ); + m_inventory.get( i ).save( tag ); nbttaglist.add( tag ); } } @@ -300,7 +300,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default // Write brain nbt = m_brain.writeToNBT( nbt ); - return super.write( nbt ); + return super.save( nbt ); } @Override @@ -314,13 +314,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default @Override public Direction getDirection() { - return getBlockState().get( BlockTurtle.FACING ); + return getBlockState().getValue( BlockTurtle.FACING ); } public void setDirection( Direction dir ) { if( dir.getAxis() == Direction.Axis.Y ) dir = Direction.NORTH; - world.setBlockState( pos, getBlockState().with( BlockTurtle.FACING, dir ) ); + level.setBlockAndUpdate( worldPosition, getBlockState().setValue( BlockTurtle.FACING, dir ) ); updateOutput(); updateInput(); onTileEntityChange(); @@ -373,13 +373,13 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default void setOwningPlayer( GameProfile player ) { m_brain.setOwningPlayer( player ); - markDirty(); + setChanged(); } // IInventory @Override - public int getSizeInventory() + public int getContainerSize() { return INVENTORY_SIZE; } @@ -396,32 +396,32 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default @Nonnull @Override - public ItemStack getStackInSlot( int slot ) + public ItemStack getItem( int slot ) { return slot >= 0 && slot < INVENTORY_SIZE ? m_inventory.get( slot ) : ItemStack.EMPTY; } @Nonnull @Override - public ItemStack removeStackFromSlot( int slot ) + public ItemStack removeItemNoUpdate( int slot ) { - ItemStack result = getStackInSlot( slot ); - setInventorySlotContents( slot, ItemStack.EMPTY ); + ItemStack result = getItem( slot ); + setItem( slot, ItemStack.EMPTY ); return result; } @Nonnull @Override - public ItemStack decrStackSize( int slot, int count ) + public ItemStack removeItem( int slot, int count ) { if( count == 0 ) return ItemStack.EMPTY; - ItemStack stack = getStackInSlot( slot ); + ItemStack stack = getItem( slot ); if( stack.isEmpty() ) return ItemStack.EMPTY; if( stack.getCount() <= count ) { - setInventorySlotContents( slot, ItemStack.EMPTY ); + setItem( slot, ItemStack.EMPTY ); return stack; } @@ -431,7 +431,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public void setInventorySlotContents( int i, @Nonnull ItemStack stack ) + public void setItem( int i, @Nonnull ItemStack stack ) { if( i >= 0 && i < INVENTORY_SIZE && !InventoryUtil.areItemsEqual( stack, m_inventory.get( i ) ) ) { @@ -441,7 +441,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public void clear() + public void clearContent() { boolean changed = false; for( int i = 0; i < INVENTORY_SIZE; i++ ) @@ -457,14 +457,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public void markDirty() + public void setChanged() { - super.markDirty(); + super.setChanged(); if( !m_inventoryChanged ) { - for( int n = 0; n < getSizeInventory(); n++ ) + for( int n = 0; n < getContainerSize(); n++ ) { - if( !ItemStack.areItemStacksEqual( getStackInSlot( n ), m_previousInventory.get( n ) ) ) + if( !ItemStack.matches( getItem( n ), m_previousInventory.get( n ) ) ) { m_inventoryChanged = true; break; @@ -474,20 +474,20 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public boolean isUsableByPlayer( @Nonnull PlayerEntity player ) + public boolean stillValid( @Nonnull PlayerEntity player ) { return isUsable( player, false ); } private void onInventoryDefinitelyChanged() { - super.markDirty(); + super.setChanged(); m_inventoryChanged = true; } public void onTileEntityChange() { - super.markDirty(); + super.setChanged(); } // Networking stuff diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index e09af75cb..9ba2d1456 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -124,7 +124,7 @@ public class TurtleBrain implements ITurtleAccess public void update() { World world = getWorld(); - if( !world.isRemote ) + if( !world.isClientSide ) { // Advance movement updateCommands(); @@ -273,20 +273,20 @@ public class TurtleBrain implements ITurtleAccess @Override public World getWorld() { - return m_owner.getWorld(); + return m_owner.getLevel(); } @Nonnull @Override public BlockPos getPosition() { - return m_owner.getPos(); + return m_owner.getBlockPos(); } @Override public boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos ) { - if( world.isRemote || getWorld().isRemote ) + if( world.isClientSide || getWorld().isClientSide ) { throw new UnsupportedOperationException( "Cannot teleport on the client" ); } @@ -294,7 +294,7 @@ public class TurtleBrain implements ITurtleAccess // Cache info about the old turtle (so we don't access this after we delete ourselves) World oldWorld = getWorld(); TileTurtle oldOwner = m_owner; - BlockPos oldPos = m_owner.getPos(); + BlockPos oldPos = m_owner.getBlockPos(); BlockState oldBlock = m_owner.getBlockState(); if( oldWorld == world && oldPos.equals( pos ) ) @@ -307,31 +307,31 @@ public class TurtleBrain implements ITurtleAccess if( !world.isAreaLoaded( pos, 0 ) ) return false; // Ensure we're inside the world border - if( !world.getWorldBorder().contains( pos ) ) return false; + if( !world.getWorldBorder().isWithinBounds( pos ) ) return false; IFluidState existingFluid = world.getBlockState( pos ).getFluidState(); BlockState newState = oldBlock // We only mark this as waterlogged when travelling into a source block. This prevents us from spreading // fluid by creating a new source when moving into a block, causing the next block to be almost full and // then moving into that. - .with( WATERLOGGED, existingFluid.isTagged( FluidTags.WATER ) && existingFluid.isSource() ); + .setValue( WATERLOGGED, existingFluid.is( FluidTags.WATER ) && existingFluid.isSource() ); oldOwner.notifyMoveStart(); try { // Create a new turtle - if( world.setBlockState( pos, newState, 0 ) ) + if( world.setBlock( pos, newState, 0 ) ) { Block block = world.getBlockState( pos ).getBlock(); if( block == oldBlock.getBlock() ) { - TileEntity newTile = world.getTileEntity( pos ); + TileEntity newTile = world.getBlockEntity( pos ); if( newTile instanceof TileTurtle ) { // Copy the old turtle state into the new turtle TileTurtle newTurtle = (TileTurtle) newTile; - newTurtle.setWorldAndPos( world, pos ); + newTurtle.setLevelAndPosition( world, pos ); newTurtle.transferStateFrom( oldOwner ); newTurtle.createServerComputer().setWorld( world ); newTurtle.createServerComputer().setPosition( pos ); @@ -365,7 +365,7 @@ public class TurtleBrain implements ITurtleAccess public Vec3d getVisualPosition( float f ) { Vec3d offset = getRenderOffset( f ); - BlockPos pos = m_owner.getPos(); + BlockPos pos = m_owner.getBlockPos(); return new Vec3d( pos.getX() + 0.5 + offset.x, pos.getY() + 0.5 + offset.y, @@ -376,7 +376,7 @@ public class TurtleBrain implements ITurtleAccess @Override public float getVisualYaw( float f ) { - float yaw = getDirection().getHorizontalAngle(); + float yaw = getDirection().toYRot(); switch( m_animation ) { case TURN_LEFT: @@ -423,9 +423,9 @@ public class TurtleBrain implements ITurtleAccess @Override public void setSelectedSlot( int slot ) { - if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot set the slot on the client" ); + if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot set the slot on the client" ); - if( slot >= 0 && slot < m_owner.getSizeInventory() ) + if( slot >= 0 && slot < m_owner.getContainerSize() ) { m_selectedSlot = slot; m_owner.onTileEntityChange(); @@ -481,7 +481,7 @@ public class TurtleBrain implements ITurtleAccess @Override public boolean consumeFuel( int fuel ) { - if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot consume fuel on the client" ); + if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot consume fuel on the client" ); if( !isFuelNeeded() ) return true; @@ -497,7 +497,7 @@ public class TurtleBrain implements ITurtleAccess @Override public void addFuel( int fuel ) { - if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot add fuel on the client" ); + if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot add fuel on the client" ); int addition = Math.max( fuel, 0 ); setFuelLevel( getFuelLevel() + addition ); @@ -513,7 +513,7 @@ public class TurtleBrain implements ITurtleAccess @Override public MethodResult executeCommand( @Nonnull ITurtleCommand command ) { - if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot run commands on the client" ); + if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot run commands on the client" ); // Issue command int commandID = issueCommand( command ); @@ -523,7 +523,7 @@ public class TurtleBrain implements ITurtleAccess @Override public void playAnimation( @Nonnull TurtleAnimation animation ) { - if( getWorld().isRemote ) throw new UnsupportedOperationException( "Cannot play animations on the client" ); + if( getWorld().isClientSide ) throw new UnsupportedOperationException( "Cannot play animations on the client" ); m_animation = animation; if( m_animation == TurtleAnimation.SHORT_WAIT ) @@ -636,7 +636,7 @@ public class TurtleBrain implements ITurtleAccess if( upgrade != null ) m_upgrades.put( side, upgrade ); // Notify clients and create peripherals - if( m_owner.getWorld() != null ) + if( m_owner.getLevel() != null ) { updatePeripherals( m_owner.createServerComputer() ); m_owner.updateBlock(); @@ -694,9 +694,9 @@ public class TurtleBrain implements ITurtleAccess double distance = -1.0 + getAnimationFraction( f ); return new Vec3d( - distance * dir.getXOffset(), - distance * dir.getYOffset(), - distance * dir.getZOffset() + distance * dir.getStepX(), + distance * dir.getStepY(), + distance * dir.getStepZ() ); } default: @@ -848,41 +848,41 @@ public class TurtleBrain implements ITurtleAccess float pushFrac = 1.0f - (float) (m_animationProgress + 1) / ANIM_DURATION; float push = Math.max( pushFrac + 0.0125f, 0.0f ); - if( moveDir.getXOffset() < 0 ) + if( moveDir.getStepX() < 0 ) { - minX += moveDir.getXOffset() * push; + minX += moveDir.getStepX() * push; } else { - maxX -= moveDir.getXOffset() * push; + maxX -= moveDir.getStepX() * push; } - if( moveDir.getYOffset() < 0 ) + if( moveDir.getStepY() < 0 ) { - minY += moveDir.getYOffset() * push; + minY += moveDir.getStepY() * push; } else { - maxY -= moveDir.getYOffset() * push; + maxY -= moveDir.getStepY() * push; } - if( moveDir.getZOffset() < 0 ) + if( moveDir.getStepZ() < 0 ) { - minZ += moveDir.getZOffset() * push; + minZ += moveDir.getStepZ() * push; } else { - maxZ -= moveDir.getZOffset() * push; + maxZ -= moveDir.getStepZ() * push; } AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ ); - List list = world.getEntitiesWithinAABB( Entity.class, aabb, EntityPredicates.NOT_SPECTATING ); + List list = world.getEntitiesOfClass( Entity.class, aabb, EntityPredicates.NO_SPECTATORS ); if( !list.isEmpty() ) { double pushStep = 1.0f / ANIM_DURATION; - double pushStepX = moveDir.getXOffset() * pushStep; - double pushStepY = moveDir.getYOffset() * pushStep; - double pushStepZ = moveDir.getZOffset() * pushStep; + double pushStepX = moveDir.getStepX() * pushStep; + double pushStepY = moveDir.getStepY() * pushStep; + double pushStepZ = moveDir.getStepZ() * pushStep; for( Entity entity : list ) { entity.move( MoverType.PISTON, new Vec3d( pushStepX, pushStepY, pushStepZ ) ); @@ -892,7 +892,7 @@ public class TurtleBrain implements ITurtleAccess } // Advance valentines day easter egg - if( world.isRemote && m_animation == TurtleAnimation.MOVE_FORWARD && m_animationProgress == 4 ) + if( world.isClientSide && m_animation == TurtleAnimation.MOVE_FORWARD && m_animationProgress == 4 ) { // Spawn love pfx if valentines day Holiday currentHoliday = HolidayUtil.getCurrentHoliday(); @@ -901,14 +901,14 @@ public class TurtleBrain implements ITurtleAccess Vec3d position = getVisualPosition( 1.0f ); if( position != null ) { - double x = position.x + world.rand.nextGaussian() * 0.1; - double y = position.y + 0.5 + world.rand.nextGaussian() * 0.1; - double z = position.z + world.rand.nextGaussian() * 0.1; + double x = position.x + world.random.nextGaussian() * 0.1; + double y = position.y + 0.5 + world.random.nextGaussian() * 0.1; + double z = position.z + world.random.nextGaussian() * 0.1; world.addParticle( ParticleTypes.HEART, x, y, z, - world.rand.nextGaussian() * 0.02, - world.rand.nextGaussian() * 0.02, - world.rand.nextGaussian() * 0.02 + world.random.nextGaussian() * 0.02, + world.random.nextGaussian() * 0.02, + world.random.nextGaussian() * 0.02 ); } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java index 01633a247..9c018ce25 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java @@ -38,15 +38,15 @@ public class TurtleCompareCommand implements ITurtleCommand Direction direction = m_direction.toWorldDir( turtle ); // Get currently selected stack - ItemStack selectedStack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() ); + ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() ); // Get stack representing thing in front World world = turtle.getWorld(); BlockPos oldPosition = turtle.getPosition(); - BlockPos newPosition = oldPosition.offset( direction ); + BlockPos newPosition = oldPosition.relative( direction ); ItemStack lookAtStack = ItemStack.EMPTY; - if( !world.isAirBlock( newPosition ) ) + if( !world.isEmptyBlock( newPosition ) ) { BlockState lookAtState = world.getBlockState( newPosition ); Block lookAtBlock = lookAtState.getBlock(); @@ -69,7 +69,7 @@ public class TurtleCompareCommand implements ITurtleCommand // (try 5 times to try and beat random number generators) for( int i = 0; i < 5 && lookAtStack.isEmpty(); i++ ) { - List drops = Block.getDrops( lookAtState, (ServerWorld) world, newPosition, world.getTileEntity( newPosition ) ); + List drops = Block.getDrops( lookAtState, (ServerWorld) world, newPosition, world.getBlockEntity( newPosition ) ); if( !drops.isEmpty() ) { for( ItemStack drop : drops ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java index b57e471b9..74cc04b1e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareToCommand.java @@ -26,8 +26,8 @@ public class TurtleCompareToCommand implements ITurtleCommand @Override public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { - ItemStack selectedStack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() ); - ItemStack stack = turtle.getInventory().getStackInSlot( m_slot ); + ItemStack selectedStack = turtle.getInventory().getItem( turtle.getSelectedSlot() ); + ItemStack stack = turtle.getInventory().getItem( m_slot ); if( InventoryUtil.areItemsStackable( selectedStack, stack ) ) { return TurtleCommandResult.success(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDetectCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDetectCommand.java index 3b1c88917..df3c79dc7 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDetectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDetectCommand.java @@ -34,9 +34,9 @@ public class TurtleDetectCommand implements ITurtleCommand // Check if thing in front is air or not World world = turtle.getWorld(); BlockPos oldPosition = turtle.getPosition(); - BlockPos newPosition = oldPosition.offset( direction ); + BlockPos newPosition = oldPosition.relative( direction ); - return !WorldUtil.isLiquidBlock( world, newPosition ) && !world.isAirBlock( newPosition ) + return !WorldUtil.isLiquidBlock( world, newPosition ) && !world.isEmptyBlock( newPosition ) ? TurtleCommandResult.success() : TurtleCommandResult.failure(); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java index 747062d4c..21d5f2a4d 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java @@ -56,7 +56,7 @@ public class TurtleDropCommand implements ITurtleCommand // Get inventory for thing in front World world = turtle.getWorld(); BlockPos oldPosition = turtle.getPosition(); - BlockPos newPosition = oldPosition.offset( direction ); + BlockPos newPosition = oldPosition.relative( direction ); Direction side = direction.getOpposite(); IItemHandler inventory = InventoryUtil.getInventory( world, newPosition, side ); @@ -95,7 +95,7 @@ public class TurtleDropCommand implements ITurtleCommand { // Drop the item into the world WorldUtil.dropItemStack( stack, world, oldPosition, direction ); - world.playBroadcastSound( 1000, newPosition, 0 ); + world.globalLevelEvent( 1000, newPosition, 0 ); turtle.playAnimation( TurtleAnimation.WAIT ); return TurtleCommandResult.success(); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java index bcb596b98..16dbc3511 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java @@ -39,7 +39,7 @@ public class TurtleInspectCommand implements ITurtleCommand // Check if thing in front is air or not World world = turtle.getWorld(); BlockPos oldPosition = turtle.getPosition(); - BlockPos newPosition = oldPosition.offset( direction ); + BlockPos newPosition = oldPosition.relative( direction ); BlockState state = world.getBlockState( newPosition ); if( state.getBlock().isAir( state, world, newPosition ) ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java index b7e8c879b..4f4c37585 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java @@ -45,7 +45,7 @@ public class TurtleMoveCommand implements ITurtleCommand // Check if we can move World oldWorld = turtle.getWorld(); BlockPos oldPosition = turtle.getPosition(); - BlockPos newPosition = oldPosition.offset( direction ); + BlockPos newPosition = oldPosition.relative( direction ); TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, oldPosition, direction ); TurtleCommandResult canEnterResult = canEnter( turtlePlayer, oldWorld, newPosition ); @@ -56,7 +56,7 @@ public class TurtleMoveCommand implements ITurtleCommand // Check existing block is air or replaceable BlockState state = oldWorld.getBlockState( newPosition ); - if( !oldWorld.isAirBlock( newPosition ) && + if( !oldWorld.isEmptyBlock( newPosition ) && !WorldUtil.isLiquidBlock( oldWorld, newPosition ) && !state.getMaterial().isReplaceable() ) { @@ -64,13 +64,13 @@ public class TurtleMoveCommand implements ITurtleCommand } // Check there isn't anything in the way - VoxelShape collision = state.getCollisionShape( oldWorld, oldPosition ).withOffset( + VoxelShape collision = state.getCollisionShape( oldWorld, oldPosition ).move( newPosition.getX(), newPosition.getY(), newPosition.getZ() ); - if( !oldWorld.checkNoEntityCollision( null, collision ) ) + if( !oldWorld.isUnobstructed( null, collision ) ) { if( !ComputerCraft.turtlesCanPush || m_direction == MoveDirection.UP || m_direction == MoveDirection.DOWN ) { @@ -78,15 +78,15 @@ public class TurtleMoveCommand implements ITurtleCommand } // Check there is space for all the pushable entities to be pushed - List list = oldWorld.getEntitiesWithinAABB( Entity.class, getBox( collision ), x -> x != null && x.isAlive() && x.preventEntitySpawning ); + List list = oldWorld.getEntitiesOfClass( Entity.class, getBox( collision ), x -> x != null && x.isAlive() && x.blocksBuilding ); for( Entity entity : list ) { - AxisAlignedBB pushedBB = entity.getBoundingBox().offset( - direction.getXOffset(), - direction.getYOffset(), - direction.getZOffset() + AxisAlignedBB pushedBB = entity.getBoundingBox().move( + direction.getStepX(), + direction.getStepY(), + direction.getStepZ() ); - if( !oldWorld.checkNoEntityCollision( null, VoxelShapes.create( pushedBB ) ) ) + if( !oldWorld.isUnobstructed( null, VoxelShapes.create( pushedBB ) ) ) { return TurtleCommandResult.failure( "Movement obstructed" ); } @@ -137,7 +137,7 @@ public class TurtleMoveCommand implements ITurtleCommand { return TurtleCommandResult.failure( position.getY() < 0 ? "Too low to move" : "Too high to move" ); } - if( !World.isValid( position ) ) return TurtleCommandResult.failure( "Cannot leave the world" ); + if( !World.isInWorldBounds( position ) ) return TurtleCommandResult.failure( "Cannot leave the world" ); // Check spawn protection if( ComputerCraft.turtlesObeyBlockProtection && !TurtlePermissions.isBlockEnterable( world, position, turtlePlayer ) ) @@ -146,7 +146,7 @@ public class TurtleMoveCommand implements ITurtleCommand } if( !world.isAreaLoaded( position, 0 ) ) return TurtleCommandResult.failure( "Cannot leave loaded world" ); - if( !world.getWorldBorder().contains( position ) ) + if( !world.getWorldBorder().isWithinBounds( position ) ) { return TurtleCommandResult.failure( "Cannot pass the world border" ); } @@ -156,7 +156,7 @@ public class TurtleMoveCommand implements ITurtleCommand private static AxisAlignedBB getBox( VoxelShape shape ) { - return shape.isEmpty() ? EMPTY_BOX : shape.getBoundingBox(); + return shape.isEmpty() ? EMPTY_BOX : shape.bounds(); } private static final AxisAlignedBB EMPTY_BOX = new AxisAlignedBB( 0, 0, 0, 0, 0, 0 ); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java index a7b739f5a..cbdc4991f 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java @@ -56,7 +56,7 @@ public class TurtlePlaceCommand implements ITurtleCommand public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get thing to place - ItemStack stack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() ); + ItemStack stack = turtle.getInventory().getItem( turtle.getSelectedSlot() ); if( stack.isEmpty() ) { return TurtleCommandResult.failure( "No items to place" ); @@ -64,10 +64,10 @@ public class TurtlePlaceCommand implements ITurtleCommand // Remember old block Direction direction = m_direction.toWorldDir( turtle ); - BlockPos coordinates = turtle.getPosition().offset( direction ); + BlockPos coordinates = turtle.getPosition().relative( direction ); // Create a fake player, and orient it appropriately - BlockPos playerPosition = turtle.getPosition().offset( direction ); + BlockPos playerPosition = turtle.getPosition().relative( direction ); TurtlePlayer turtlePlayer = createPlayer( turtle, playerPosition, direction ); TurtleBlockEvent.Place place = new TurtleBlockEvent.Place( turtle, turtlePlayer, turtle.getWorld(), coordinates, stack ); @@ -82,8 +82,8 @@ public class TurtlePlaceCommand implements ITurtleCommand if( remainder != stack ) { // Put the remaining items back - turtle.getInventory().setInventorySlotContents( turtle.getSelectedSlot(), remainder ); - turtle.getInventory().markDirty(); + turtle.getInventory().setItem( turtle.getSelectedSlot(), remainder ); + turtle.getInventory().setChanged(); // Animate and return success turtle.playAnimation( TurtleAnimation.WAIT ); @@ -109,7 +109,7 @@ public class TurtlePlaceCommand implements ITurtleCommand public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, Direction direction, Object[] extraArguments, String[] outErrorMessage ) { // Create a fake player, and orient it appropriately - BlockPos playerPosition = turtle.getPosition().offset( direction ); + BlockPos playerPosition = turtle.getPosition().relative( direction ); TurtlePlayer turtlePlayer = createPlayer( turtle, playerPosition, direction ); return deploy( stack, turtle, turtlePlayer, direction, extraArguments, outErrorMessage ); @@ -126,7 +126,7 @@ public class TurtlePlaceCommand implements ITurtleCommand // Deploy on the block immediately in front BlockPos position = turtle.getPosition(); - BlockPos newPosition = position.offset( direction ); + BlockPos newPosition = position.relative( direction ); remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition, direction.getOpposite(), extraArguments, true, outErrorMessage ); if( remainder != stack ) { @@ -134,7 +134,7 @@ public class TurtlePlaceCommand implements ITurtleCommand } // Deploy on the block one block away - remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.offset( direction ), direction.getOpposite(), extraArguments, false, outErrorMessage ); + remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.relative( direction ), direction.getOpposite(), extraArguments, false, outErrorMessage ); if( remainder != stack ) { return remainder; @@ -143,7 +143,7 @@ public class TurtlePlaceCommand implements ITurtleCommand if( direction.getAxis() != Direction.Axis.Y ) { // Deploy down on the block in front - remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.down(), Direction.UP, extraArguments, false, outErrorMessage ); + remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.below(), Direction.UP, extraArguments, false, outErrorMessage ); if( remainder != stack ) { return remainder; @@ -177,31 +177,31 @@ public class TurtlePlaceCommand implements ITurtleCommand // Stop intersection with the turtle itself if( turtle.getPosition().equals( position ) ) { - posX += 0.48 * direction.getXOffset(); - posY += 0.48 * direction.getYOffset(); - posZ += 0.48 * direction.getZOffset(); + posX += 0.48 * direction.getStepX(); + posY += 0.48 * direction.getStepY(); + posZ += 0.48 * direction.getStepZ(); } if( direction.getAxis() != Direction.Axis.Y ) { - turtlePlayer.rotationYaw = direction.getHorizontalAngle(); - turtlePlayer.rotationPitch = 0.0f; + turtlePlayer.yRot = direction.toYRot(); + turtlePlayer.xRot = 0.0f; } else { - turtlePlayer.rotationYaw = turtle.getDirection().getHorizontalAngle(); - turtlePlayer.rotationPitch = DirectionUtil.toPitchAngle( direction ); + turtlePlayer.yRot = turtle.getDirection().toYRot(); + turtlePlayer.xRot = DirectionUtil.toPitchAngle( direction ); } - turtlePlayer.setRawPosition( posX, posY, posZ ); - turtlePlayer.prevPosX = posX; - turtlePlayer.prevPosY = posY; - turtlePlayer.prevPosZ = posZ; - turtlePlayer.prevRotationPitch = turtlePlayer.rotationPitch; - turtlePlayer.prevRotationYaw = turtlePlayer.rotationYaw; + turtlePlayer.setPosRaw( posX, posY, posZ ); + turtlePlayer.xo = posX; + turtlePlayer.yo = posY; + turtlePlayer.zo = posZ; + turtlePlayer.xRotO = turtlePlayer.xRot; + turtlePlayer.yRotO = turtlePlayer.yRot; - turtlePlayer.rotationYawHead = turtlePlayer.rotationYaw; - turtlePlayer.prevRotationYawHead = turtlePlayer.rotationYawHead; + turtlePlayer.yHeadRot = turtlePlayer.yRot; + turtlePlayer.yHeadRotO = turtlePlayer.yHeadRot; } @Nonnull @@ -210,8 +210,8 @@ public class TurtlePlaceCommand implements ITurtleCommand // See if there is an entity present final World world = turtle.getWorld(); final BlockPos position = turtle.getPosition(); - Vec3d turtlePos = turtlePlayer.getPositionVec(); - Vec3d rayDir = turtlePlayer.getLook( 1.0f ); + Vec3d turtlePos = turtlePlayer.position(); + Vec3d rayDir = turtlePlayer.getViewVector( 1.0f ); Pair hit = WorldUtil.rayTraceEntities( world, turtlePos, rayDir, 1.5 ); if( hit == null ) { @@ -235,7 +235,7 @@ public class TurtlePlaceCommand implements ITurtleCommand ActionResultType cancelResult = ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, Hand.MAIN_HAND ); if( cancelResult == null ) { - cancelResult = hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, Hand.MAIN_HAND ); + cancelResult = hitEntity.interactAt( turtlePlayer, hitPos, Hand.MAIN_HAND ); } if( cancelResult == ActionResultType.SUCCESS ) @@ -252,13 +252,13 @@ public class TurtlePlaceCommand implements ITurtleCommand } else if( cancelResult == null ) { - if( hitEntity.processInitialInteract( turtlePlayer, Hand.MAIN_HAND ) ) + if( hitEntity.interact( turtlePlayer, Hand.MAIN_HAND ) ) { placed = true; } else if( hitEntity instanceof LivingEntity ) { - placed = stackCopy.interactWithEntity( turtlePlayer, (LivingEntity) hitEntity, Hand.MAIN_HAND ); + placed = stackCopy.interactEnemy( turtlePlayer, (LivingEntity) hitEntity, Hand.MAIN_HAND ); if( placed ) turtlePlayer.loadInventory( stackCopy ); } } @@ -273,7 +273,7 @@ public class TurtlePlaceCommand implements ITurtleCommand // Put everything we collected into the turtles inventory, then return ItemStack remainder = turtlePlayer.unloadInventory( turtle ); - if( !placed && ItemStack.areItemStacksEqual( stack, remainder ) ) + if( !placed && ItemStack.matches( stack, remainder ) ) { return stack; } @@ -290,15 +290,15 @@ public class TurtlePlaceCommand implements ITurtleCommand private static boolean canDeployOnBlock( @Nonnull BlockItemUseContext context, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, Direction side, boolean allowReplaceable, String[] outErrorMessage ) { World world = turtle.getWorld(); - if( !World.isValid( position ) || world.isAirBlock( position ) || - (context.getItem().getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, position )) ) + if( !World.isInWorldBounds( position ) || world.isEmptyBlock( position ) || + (context.getItemInHand().getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, position )) ) { return false; } BlockState state = world.getBlockState( position ); - boolean replaceable = state.isReplaceable( context ); + boolean replaceable = state.canBeReplaced( context ); if( !allowReplaceable && replaceable ) return false; if( ComputerCraft.turtlesObeyBlockProtection ) @@ -306,7 +306,7 @@ public class TurtlePlaceCommand implements ITurtleCommand // Check spawn protection boolean editable = replaceable ? TurtlePermissions.isBlockEditable( world, position, player ) - : TurtlePermissions.isBlockEditable( world, position.offset( side ), player ); + : TurtlePermissions.isBlockEditable( world, position.relative( side ), player ); if( !editable ) { if( outErrorMessage != null ) outErrorMessage[0] = "Cannot place in protected area"; @@ -322,16 +322,16 @@ public class TurtlePlaceCommand implements ITurtleCommand { // Re-orient the fake player Direction playerDir = side.getOpposite(); - BlockPos playerPosition = position.offset( side ); + BlockPos playerPosition = position.relative( side ); orientPlayer( turtle, turtlePlayer, playerPosition, playerDir ); ItemStack stackCopy = stack.copy(); turtlePlayer.loadInventory( stackCopy ); // Calculate where the turtle would hit the block - float hitX = 0.5f + side.getXOffset() * 0.5f; - float hitY = 0.5f + side.getYOffset() * 0.5f; - float hitZ = 0.5f + side.getZOffset() * 0.5f; + float hitX = 0.5f + side.getStepX() * 0.5f; + float hitY = 0.5f + side.getStepY() * 0.5f; + float hitZ = 0.5f + side.getStepZ() * 0.5f; if( Math.abs( hitY - 0.5f ) < 0.01f ) { hitY = 0.45f; @@ -350,7 +350,7 @@ public class TurtlePlaceCommand implements ITurtleCommand // Do the deploying (put everything in the players inventory) boolean placed = false; - TileEntity existingTile = turtle.getWorld().getTileEntity( position ); + TileEntity existingTile = turtle.getWorld().getBlockEntity( position ); // See PlayerInteractionManager.processRightClickBlock // TODO: ^ Check we're still consistent. @@ -363,7 +363,7 @@ public class TurtlePlaceCommand implements ITurtleCommand turtlePlayer.loadInventory( stackCopy ); } else if( event.getUseItem() != Event.Result.DENY && - stackCopy.onItemUse( context ) == ActionResultType.SUCCESS ) + stackCopy.useOn( context ) == ActionResultType.SUCCESS ) { placed = true; turtlePlayer.loadInventory( stackCopy ); @@ -379,11 +379,11 @@ public class TurtlePlaceCommand implements ITurtleCommand } else if( actionResult == null ) { - ActionResult result = stackCopy.useItemRightClick( turtle.getWorld(), turtlePlayer, Hand.MAIN_HAND ); - if( result.getType() == ActionResultType.SUCCESS && !ItemStack.areItemStacksEqual( stack, result.getResult() ) ) + ActionResult result = stackCopy.use( turtle.getWorld(), turtlePlayer, Hand.MAIN_HAND ); + if( result.getResult() == ActionResultType.SUCCESS && !ItemStack.matches( stack, result.getObject() ) ) { placed = true; - turtlePlayer.loadInventory( result.getResult() ); + turtlePlayer.loadInventory( result.getObject() ); } } } @@ -394,10 +394,10 @@ public class TurtlePlaceCommand implements ITurtleCommand if( extraArguments != null && extraArguments.length >= 1 && extraArguments[0] instanceof String ) { World world = turtle.getWorld(); - TileEntity tile = world.getTileEntity( position ); + TileEntity tile = world.getBlockEntity( position ); if( tile == null || tile == existingTile ) { - tile = world.getTileEntity( position.offset( side ) ); + tile = world.getBlockEntity( position.relative( side ) ); } if( tile instanceof SignTileEntity ) { @@ -405,33 +405,33 @@ public class TurtlePlaceCommand implements ITurtleCommand String s = (String) extraArguments[0]; String[] split = s.split( "\n" ); int firstLine = split.length <= 2 ? 1 : 0; - for( int i = 0; i < signTile.signText.length; i++ ) + for( int i = 0; i < signTile.messages.length; i++ ) { if( i >= firstLine && i < firstLine + split.length ) { if( split[i - firstLine].length() > 15 ) { - signTile.signText[i] = new StringTextComponent( split[i - firstLine].substring( 0, 15 ) ); + signTile.messages[i] = new StringTextComponent( split[i - firstLine].substring( 0, 15 ) ); } else { - signTile.signText[i] = new StringTextComponent( split[i - firstLine] ); + signTile.messages[i] = new StringTextComponent( split[i - firstLine] ); } } else { - signTile.signText[i] = new StringTextComponent( "" ); + signTile.messages[i] = new StringTextComponent( "" ); } } - signTile.markDirty(); - world.notifyBlockUpdate( tile.getPos(), tile.getBlockState(), tile.getBlockState(), 3 ); + signTile.setChanged(); + world.sendBlockUpdated( tile.getBlockPos(), tile.getBlockState(), tile.getBlockState(), 3 ); } } } // Put everything we collected into the turtles inventory, then return ItemStack remainder = turtlePlayer.unloadInventory( turtle ); - if( !placed && ItemStack.areItemStacksEqual( stack, remainder ) ) + if( !placed && ItemStack.matches( stack, remainder ) ) { return stack; } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java index 270b25183..5da920cf8 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java @@ -61,7 +61,7 @@ public final class TurtlePlayer extends FakePlayer // Constructing a player overrides the "active player" variable in advancements. As fake players cannot // get advancements, this prevents a normal player who has placed a turtle from getting advancements. // We try to locate the "actual" player and restore them. - ServerPlayerEntity actualPlayer = world.getServer().getPlayerList().getPlayerByUUID( profile.getId() ); + ServerPlayerEntity actualPlayer = world.getServer().getPlayerList().getPlayer( profile.getId() ); if( actualPlayer != null ) player.getAdvancements().setPlayer( actualPlayer ); } @@ -75,19 +75,19 @@ public final class TurtlePlayer extends FakePlayer private void setState( ITurtleAccess turtle ) { - if( openContainer != container ) + if( containerMenu != inventoryMenu ) { - ComputerCraft.log.warn( "Turtle has open container ({})", openContainer ); - closeContainer(); + ComputerCraft.log.warn( "Turtle has open container ({})", containerMenu ); + doCloseContainer(); } BlockPos position = turtle.getPosition(); - setRawPosition( position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5 ); + setPosRaw( position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5 ); - rotationYaw = turtle.getDirection().getHorizontalAngle(); - rotationPitch = 0.0f; + yRot = turtle.getDirection().toYRot(); + xRot = 0.0f; - inventory.clear(); + inventory.clearContent(); } public static TurtlePlayer get( ITurtleAccess access ) @@ -97,7 +97,7 @@ public final class TurtlePlayer extends FakePlayer TurtleBrain brain = (TurtleBrain) access; TurtlePlayer player = brain.m_cachedPlayer; if( player == null || player.getGameProfile() != getProfile( access.getOwningPlayer() ) - || player.getEntityWorld() != access.getWorld() ) + || player.getCommandSenderWorld() != access.getWorld() ) { player = brain.m_cachedPlayer = create( brain ); } @@ -112,22 +112,22 @@ public final class TurtlePlayer extends FakePlayer public void loadInventory( @Nonnull ItemStack currentStack ) { // Load up the fake inventory - inventory.currentItem = 0; - inventory.setInventorySlotContents( 0, currentStack ); + inventory.selected = 0; + inventory.setItem( 0, currentStack ); } public ItemStack unloadInventory( ITurtleAccess turtle ) { // Get the item we placed with - ItemStack results = inventory.getStackInSlot( 0 ); - inventory.setInventorySlotContents( 0, ItemStack.EMPTY ); + ItemStack results = inventory.getItem( 0 ); + inventory.setItem( 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.getSizeInventory(); i++ ) + for( int i = 0; i < inventory.getContainerSize(); i++ ) { - ItemStack stack = inventory.getStackInSlot( i ); + ItemStack stack = inventory.getItem( i ); if( !stack.isEmpty() ) { ItemStack remainder = InventoryUtil.storeItems( stack, turtle.getItemHandler(), turtle.getSelectedSlot() ); @@ -135,10 +135,10 @@ public final class TurtlePlayer extends FakePlayer { WorldUtil.dropItemStack( remainder, turtle.getWorld(), dropPosition, dropDirection ); } - inventory.setInventorySlotContents( i, ItemStack.EMPTY ); + inventory.setItem( i, ItemStack.EMPTY ); } } - inventory.markDirty(); + inventory.setChanged(); return results; } @@ -150,9 +150,9 @@ public final class TurtlePlayer extends FakePlayer } @Override - public Vec3d getPositionVector() + public Vec3d getCommandSenderWorldPosition() { - return getPositionVec(); + return position(); } @Override @@ -170,18 +170,18 @@ public final class TurtlePlayer extends FakePlayer //region Code which depends on the connection @Nonnull @Override - public OptionalInt openContainer( @Nullable INamedContainerProvider prover ) + public OptionalInt openMenu( @Nullable INamedContainerProvider prover ) { return OptionalInt.empty(); } @Override - public void sendEnterCombat() + public void onEnterCombat() { } @Override - public void sendEndCombat() + public void onLeaveCombat() { } @@ -197,7 +197,7 @@ public final class TurtlePlayer extends FakePlayer } @Override - public void openSignEditor( @Nonnull SignTileEntity signTile ) + public void openTextEdit( @Nonnull SignTileEntity signTile ) { } @@ -207,32 +207,32 @@ public final class TurtlePlayer extends FakePlayer } @Override - public void openBook( @Nonnull ItemStack stack, @Nonnull Hand hand ) + public void openItemGui( @Nonnull ItemStack stack, @Nonnull Hand hand ) { } @Override - public void closeScreen() + public void closeContainer() { } @Override - public void updateHeldItem() + public void broadcastCarriedItem() { } @Override - protected void onNewPotionEffect( @Nonnull EffectInstance id ) + protected void onEffectAdded( @Nonnull EffectInstance id ) { } @Override - protected void onChangedPotionEffect( @Nonnull EffectInstance id, boolean apply ) + protected void onEffectUpdated( @Nonnull EffectInstance id, boolean apply ) { } @Override - protected void onFinishedPotionEffect( @Nonnull EffectInstance effect ) + protected void onEffectRemoved( @Nonnull EffectInstance effect ) { } //endregion diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java index 58a789979..fdee852cb 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleRefuelCommand.java @@ -29,7 +29,7 @@ public class TurtleRefuelCommand implements ITurtleCommand public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { int slot = turtle.getSelectedSlot(); - ItemStack stack = turtle.getInventory().getStackInSlot( slot ); + ItemStack stack = turtle.getInventory().getItem( slot ); if( stack.isEmpty() ) return TurtleCommandResult.failure( "No items to combust" ); TurtleRefuelEvent event = new TurtleRefuelEvent( turtle, stack ); diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java index 8ca4b8b26..776394792 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java @@ -52,7 +52,7 @@ public class TurtleSuckCommand implements ITurtleCommand // Get inventory for thing in front World world = turtle.getWorld(); BlockPos turtlePosition = turtle.getPosition(); - BlockPos blockPosition = turtlePosition.offset( direction ); + BlockPos blockPosition = turtlePosition.relative( direction ); Direction side = direction.getOpposite(); IItemHandler inventory = InventoryUtil.getInventory( world, blockPosition, side ); @@ -97,7 +97,7 @@ public class TurtleSuckCommand implements ITurtleCommand blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), blockPosition.getX() + 1.0, blockPosition.getY() + 1.0, blockPosition.getZ() + 1.0 ); - List list = world.getEntitiesWithinAABB( ItemEntity.class, aabb, EntityPredicates.IS_ALIVE ); + List list = world.getEntitiesOfClass( ItemEntity.class, aabb, EntityPredicates.ENTITY_STILL_ALIVE ); if( list.isEmpty() ) return TurtleCommandResult.failure( "No items to take" ); for( ItemEntity entity : list ) @@ -141,7 +141,7 @@ public class TurtleSuckCommand implements ITurtleCommand } // Play fx - world.playBroadcastSound( 1000, turtlePosition, 0 ); // BLOCK_DISPENSER_DISPENSE + world.globalLevelEvent( 1000, turtlePosition, 0 ); // BLOCK_DISPENSER_DISPENSE turtle.playAnimation( TurtleAnimation.WAIT ); return TurtleCommandResult.success(); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java index 05fc7978c..63a3375b2 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleTurnCommand.java @@ -38,13 +38,13 @@ public class TurtleTurnCommand implements ITurtleCommand { case LEFT: { - turtle.setDirection( turtle.getDirection().rotateYCCW() ); + turtle.setDirection( turtle.getDirection().getCounterClockWise() ); turtle.playAnimation( TurtleAnimation.TURN_LEFT ); return TurtleCommandResult.success(); } case RIGHT: { - turtle.setDirection( turtle.getDirection().rotateY() ); + turtle.setDirection( turtle.getDirection().getClockWise() ); turtle.playAnimation( TurtleAnimation.TURN_RIGHT ); return TurtleCommandResult.success(); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java index c02a6e933..c11357614 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java @@ -40,7 +40,7 @@ public class ContainerTurtle extends ContainerComputerBase super( Registry.ModContainers.TURTLE.get(), id, canUse, computer, family ); this.properties = properties; - trackIntArray( properties ); + addDataSlots( properties ); // Turtle inventory for( int y = 0; y < 4; y++ ) @@ -70,7 +70,7 @@ public class ContainerTurtle extends ContainerComputerBase public ContainerTurtle( int id, PlayerInventory player, TurtleBrain turtle ) { this( - id, p -> turtle.getOwner().isUsableByPlayer( p ), turtle.getOwner().createServerComputer(), turtle.getFamily(), + id, p -> turtle.getOwner().stillValid( p ), turtle.getOwner().createServerComputer(), turtle.getFamily(), player, turtle.getInventory(), (SingleIntArray) turtle::getSelectedSlot ); } @@ -91,24 +91,24 @@ public class ContainerTurtle extends ContainerComputerBase @Nonnull private ItemStack tryItemMerge( PlayerEntity player, int slotNum, int firstSlot, int lastSlot, boolean reverse ) { - Slot slot = inventorySlots.get( slotNum ); + Slot slot = slots.get( slotNum ); ItemStack originalStack = ItemStack.EMPTY; - if( slot != null && slot.getHasStack() ) + if( slot != null && slot.hasItem() ) { - ItemStack clickedStack = slot.getStack(); + ItemStack clickedStack = slot.getItem(); originalStack = clickedStack.copy(); - if( !mergeItemStack( clickedStack, firstSlot, lastSlot, reverse ) ) + if( !moveItemStackTo( clickedStack, firstSlot, lastSlot, reverse ) ) { return ItemStack.EMPTY; } if( clickedStack.isEmpty() ) { - slot.putStack( ItemStack.EMPTY ); + slot.set( ItemStack.EMPTY ); } else { - slot.onSlotChanged(); + slot.setChanged(); } if( clickedStack.getCount() != originalStack.getCount() ) @@ -125,7 +125,7 @@ public class ContainerTurtle extends ContainerComputerBase @Nonnull @Override - public ItemStack transferStackInSlot( @Nonnull PlayerEntity player, int slotNum ) + public ItemStack quickMoveStack( @Nonnull PlayerEntity player, int slotNum ) { if( slotNum >= 0 && slotNum < 16 ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java index f849357e5..331f8e28f 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java @@ -27,6 +27,8 @@ import javax.annotation.Nullable; import static dan200.computercraft.shared.turtle.core.TurtleBrain.*; +import net.minecraft.item.Item.Properties; + public class ItemTurtle extends ItemComputerBase implements ITurtleItem { public ItemTurtle( BlockTurtle block, Properties settings ) @@ -38,7 +40,7 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem { // Build the stack ItemStack stack = new ItemStack( this ); - if( label != null ) stack.setDisplayName( new StringTextComponent( label ) ); + if( label != null ) stack.setHoverName( new StringTextComponent( label ) ); if( id >= 0 ) stack.getOrCreateTag().putInt( NBT_ID, id ); IColouredItem.setColourBasic( stack, colour ); if( fuelLevel > 0 ) stack.getOrCreateTag().putInt( NBT_FUEL, fuelLevel ); @@ -58,9 +60,9 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem } @Override - public void fillItemGroup( @Nonnull ItemGroup group, @Nonnull NonNullList list ) + public void fillItemCategory( @Nonnull ItemGroup group, @Nonnull NonNullList list ) { - if( !isInGroup( group ) ) return; + if( !allowdedIn( group ) ) return; ComputerFamily family = getFamily(); @@ -73,9 +75,9 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem @Nonnull @Override - public ITextComponent getDisplayName( @Nonnull ItemStack stack ) + public ITextComponent getName( @Nonnull ItemStack stack ) { - String baseString = getTranslationKey( stack ); + String baseString = getDescriptionId( stack ); ITurtleUpgrade left = getUpgrade( stack, TurtleSide.LEFT ); ITurtleUpgrade right = getUpgrade( stack, TurtleSide.RIGHT ); if( left != null && right != null ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java index 05e598bac..af2dbe8bc 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java @@ -17,6 +17,8 @@ import net.minecraft.util.ResourceLocation; import javax.annotation.Nonnull; +import dan200.computercraft.shared.computer.recipe.ComputerFamilyRecipe.Serializer; + public final class TurtleRecipe extends ComputerFamilyRecipe { private TurtleRecipe( ResourceLocation identifier, String group, int width, int height, NonNullList ingredients, ItemStack result, ComputerFamily family ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java index 6240ad6a8..5c76773b2 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java @@ -29,14 +29,14 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe } @Override - public boolean canFit( int x, int y ) + public boolean canCraftInDimensions( int x, int y ) { return x >= 3 && y >= 1; } @Nonnull @Override - public ItemStack getRecipeOutput() + public ItemStack getResultItem() { return TurtleItemFactory.create( -1, null, -1, ComputerFamily.NORMAL, null, null, 0, null ); } @@ -44,12 +44,12 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe @Override public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world ) { - return !getCraftingResult( inventory ).isEmpty(); + return !assemble( inventory ).isEmpty(); } @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) + public ItemStack assemble( @Nonnull CraftingInventory inventory ) { // Scan the grid for a row containing a turtle and 1 or 2 items ItemStack leftItem = ItemStack.EMPTY; @@ -64,7 +64,7 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe boolean finishedRow = false; for( int x = 0; x < inventory.getWidth(); x++ ) { - ItemStack item = inventory.getStackInSlot( x + y * inventory.getWidth() ); + ItemStack item = inventory.getItem( x + y * inventory.getWidth() ); if( !item.isEmpty() ) { if( finishedRow ) @@ -122,7 +122,7 @@ public final class TurtleUpgradeRecipe extends SpecialRecipe // Turtle is already found, just check this row is empty for( int x = 0; x < inventory.getWidth(); x++ ) { - ItemStack item = inventory.getStackInSlot( x + y * inventory.getWidth() ); + ItemStack item = inventory.getItem( x + y * inventory.getWidth() ); if( !item.isEmpty() ) { return ItemStack.EMPTY; diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java index 903d6677c..044416527 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java @@ -45,12 +45,12 @@ public class TurtleHoe extends TurtleTool if( !super.canBreakBlock( state, world, pos, player ) ) return false; Material material = state.getMaterial(); - return material == Material.PLANTS || + return material == Material.PLANT || material == Material.CACTUS || - material == Material.GOURD || + material == Material.VEGETABLE || material == Material.LEAVES || - material == Material.OCEAN_PLANT || - material == Material.TALL_PLANTS; + material == Material.WATER_PLANT || + material == Material.REPLACEABLE_PLANT; } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java index 42b063470..bba1393c9 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java @@ -56,7 +56,7 @@ public class TurtleInventoryCrafting extends CraftingInventory if( x < m_xStart || x >= m_xStart + 3 || y < m_yStart || y >= m_yStart + 3 ) { - if( !m_turtle.getInventory().getStackInSlot( x + y * TileTurtle.INVENTORY_WIDTH ).isEmpty() ) + if( !m_turtle.getInventory().getItem( x + y * TileTurtle.INVENTORY_WIDTH ).isEmpty() ) { return null; } @@ -65,13 +65,13 @@ public class TurtleInventoryCrafting extends CraftingInventory } // Check the actual crafting - return m_turtle.getWorld().getRecipeManager().getRecipe( IRecipeType.CRAFTING, this, m_turtle.getWorld() ).orElse( null ); + return m_turtle.getWorld().getRecipeManager().getRecipeFor( IRecipeType.CRAFTING, this, m_turtle.getWorld() ).orElse( null ); } @Nullable public List doCrafting( World world, int maxCount ) { - if( world.isRemote || !(world instanceof ServerWorld) ) return null; + if( world.isClientSide || !(world instanceof ServerWorld) ) return null; // Find out what we can craft IRecipe recipe = tryCrafting( 0, 0 ); @@ -88,11 +88,11 @@ public class TurtleInventoryCrafting extends CraftingInventory ArrayList results = new ArrayList<>(); for( int i = 0; i < maxCount && recipe.matches( this, world ); i++ ) { - ItemStack result = recipe.getCraftingResult( this ); + ItemStack result = recipe.assemble( this ); if( result.isEmpty() ) break; results.add( result ); - result.onCrafting( world, player, result.getCount() ); + result.onCraftedBy( world, player, result.getCount() ); BasicEventHooks.firePlayerCraftingEvent( player, result, this ); ForgeHooks.setCraftingPlayer( player ); @@ -101,13 +101,13 @@ public class TurtleInventoryCrafting extends CraftingInventory for( int slot = 0; slot < remainders.size(); slot++ ) { - ItemStack existing = getStackInSlot( slot ); + ItemStack existing = getItem( slot ); ItemStack remainder = remainders.get( slot ); if( !existing.isEmpty() ) { - decrStackSize( slot, 1 ); - existing = getStackInSlot( slot ); + removeItem( slot, 1 ); + existing = getItem( slot ); } if( remainder.isEmpty() ) continue; @@ -116,12 +116,12 @@ public class TurtleInventoryCrafting extends CraftingInventory // afterwards). if( existing.isEmpty() ) { - setInventorySlotContents( slot, remainder ); + setItem( slot, remainder ); } - else if( ItemStack.areItemsEqual( existing, remainder ) && ItemStack.areItemStackTagsEqual( existing, remainder ) ) + else if( ItemStack.isSame( existing, remainder ) && ItemStack.tagMatches( existing, remainder ) ) { remainder.grow( existing.getCount() ); - setInventorySlotContents( slot, remainder ); + setItem( slot, remainder ); } else { @@ -157,74 +157,74 @@ public class TurtleInventoryCrafting extends CraftingInventory // IInventory implementation @Override - public int getSizeInventory() + public int getContainerSize() { return getWidth() * getHeight(); } @Nonnull @Override - public ItemStack getStackInSlot( int i ) + public ItemStack getItem( int i ) { i = modifyIndex( i ); - return m_turtle.getInventory().getStackInSlot( i ); + return m_turtle.getInventory().getItem( i ); } @Nonnull @Override - public ItemStack removeStackFromSlot( int i ) + public ItemStack removeItemNoUpdate( int i ) { i = modifyIndex( i ); - return m_turtle.getInventory().removeStackFromSlot( i ); + return m_turtle.getInventory().removeItemNoUpdate( i ); } @Nonnull @Override - public ItemStack decrStackSize( int i, int size ) + public ItemStack removeItem( int i, int size ) { i = modifyIndex( i ); - return m_turtle.getInventory().decrStackSize( i, size ); + return m_turtle.getInventory().removeItem( i, size ); } @Override - public void setInventorySlotContents( int i, @Nonnull ItemStack stack ) + public void setItem( int i, @Nonnull ItemStack stack ) { i = modifyIndex( i ); - m_turtle.getInventory().setInventorySlotContents( i, stack ); + m_turtle.getInventory().setItem( i, stack ); } @Override - public int getInventoryStackLimit() + public int getMaxStackSize() { - return m_turtle.getInventory().getInventoryStackLimit(); + return m_turtle.getInventory().getMaxStackSize(); } @Override - public void markDirty() + public void setChanged() { - m_turtle.getInventory().markDirty(); + m_turtle.getInventory().setChanged(); } @Override - public boolean isUsableByPlayer( @Nonnull PlayerEntity player ) + public boolean stillValid( @Nonnull PlayerEntity player ) { return true; } @Override - public boolean isItemValidForSlot( int i, @Nonnull ItemStack stack ) + public boolean canPlaceItem( int i, @Nonnull ItemStack stack ) { i = modifyIndex( i ); - return m_turtle.getInventory().isItemValidForSlot( i, stack ); + return m_turtle.getInventory().canPlaceItem( i, stack ); } @Override - public void clear() + public void clearContent() { - for( int i = 0; i < getSizeInventory(); i++ ) + for( int i = 0; i < getContainerSize(); i++ ) { int j = modifyIndex( i ); - m_turtle.getInventory().setInventorySlotContents( j, ItemStack.EMPTY ); + m_turtle.getInventory().setItem( j, ItemStack.EMPTY ); } } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java index 4e5f97785..4fe11b97b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java @@ -144,7 +144,7 @@ public class TurtleModem extends AbstractTurtleUpgrade public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side ) { // Advance the modem - if( !turtle.getWorld().isRemote ) + if( !turtle.getWorld().isClientSide ) { IPeripheral peripheral = turtle.getPeripheral( side ); if( peripheral instanceof Peripheral ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java index cbec04c14..3981ad12d 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java @@ -45,16 +45,16 @@ public class TurtleShovel extends TurtleTool if( !super.canBreakBlock( state, world, pos, player ) ) return false; Material material = state.getMaterial(); - return material == Material.EARTH || + return material == Material.DIRT || material == Material.SAND || - material == Material.SNOW || + material == Material.TOP_SNOW || material == Material.CLAY || - material == Material.SNOW_BLOCK || - material == Material.PLANTS || + material == Material.SNOW || + material == Material.PLANT || material == Material.CACTUS || - material == Material.GOURD || + material == Material.VEGETABLE || material == Material.LEAVES || - material == Material.TALL_PLANTS; + material == Material.REPLACEABLE_PLANT; } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java index 425208eb9..e1cb4f552 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java @@ -37,9 +37,9 @@ public class TurtleSword extends TurtleTool if( !super.canBreakBlock( state, world, pos, player ) ) return false; Material material = state.getMaterial(); - return material == Material.PLANTS || + return material == Material.PLANT || material == Material.LEAVES || - material == Material.TALL_PLANTS || + material == Material.REPLACEABLE_PLANT || material == Material.WOOL || material == Material.WEB; } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java index 96c619a3d..3f6a02ebe 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -78,7 +78,7 @@ public class TurtleTool extends AbstractTurtleUpgrade // Check we've not got anything vaguely interesting on the item. We allow other mods to add their // own NBT, with the understanding such details will be lost to the mist of time. - if( stack.isDamaged() || stack.isEnchanted() || stack.hasDisplayName() ) return false; + if( stack.isDamaged() || stack.isEnchanted() || stack.hasCustomHoverName() ) return false; if( tag.contains( "AttributeModifiers", Constants.NBT.TAG_LIST ) && !tag.getList( "AttributeModifiers", Constants.NBT.TAG_COMPOUND ).isEmpty() ) { @@ -123,7 +123,7 @@ public class TurtleTool extends AbstractTurtleUpgrade Block block = state.getBlock(); return !state.isAir( world, pos ) && block != Blocks.BEDROCK - && state.getPlayerRelativeBlockHardness( player, world, pos ) > 0 + && state.getDestroyProgress( player, world, pos ) > 0 && block.canEntityDestroy( state, world, pos, player ); } @@ -137,14 +137,14 @@ public class TurtleTool extends AbstractTurtleUpgrade // Create a fake player, and orient it appropriately World world = turtle.getWorld(); BlockPos position = turtle.getPosition(); - TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getTileEntity( position ); + TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getBlockEntity( position ); if( turtleTile == null ) return TurtleCommandResult.failure( "Turtle has vanished from existence." ); final TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, position, direction ); // See if there is an entity present - Vec3d turtlePos = turtlePlayer.getPositionVec(); - Vec3d rayDir = turtlePlayer.getLook( 1.0f ); + Vec3d turtlePos = turtlePlayer.position(); + Vec3d rayDir = turtlePlayer.getViewVector( 1.0f ); Pair hit = WorldUtil.rayTraceEntities( world, turtlePos, rayDir, 1.5 ); if( hit != null ) { @@ -155,7 +155,7 @@ public class TurtleTool extends AbstractTurtleUpgrade Entity hitEntity = hit.getKey(); // Fire several events to ensure we have permissions. - if( MinecraftForge.EVENT_BUS.post( new AttackEntityEvent( turtlePlayer, hitEntity ) ) || !hitEntity.canBeAttackedWithItem() ) + if( MinecraftForge.EVENT_BUS.post( new AttackEntityEvent( turtlePlayer, hitEntity ) ) || !hitEntity.isAttackable() ) { return TurtleCommandResult.failure( "Nothing to attack here" ); } @@ -171,26 +171,26 @@ public class TurtleTool extends AbstractTurtleUpgrade // Attack the entity boolean attacked = false; - if( !hitEntity.hitByEntity( turtlePlayer ) ) + if( !hitEntity.skipAttackInteraction( turtlePlayer ) ) { float damage = (float) turtlePlayer.getAttribute( SharedMonsterAttributes.ATTACK_DAMAGE ).getValue(); damage *= getDamageMultiplier(); if( damage > 0.0f ) { - DamageSource source = DamageSource.causePlayerDamage( turtlePlayer ); + DamageSource source = DamageSource.playerAttack( turtlePlayer ); if( hitEntity instanceof ArmorStandEntity ) { // Special case for armor stands: attack twice to guarantee destroy - hitEntity.attackEntityFrom( source, damage ); + hitEntity.hurt( source, damage ); if( hitEntity.isAlive() ) { - hitEntity.attackEntityFrom( source, damage ); + hitEntity.hurt( source, damage ); } attacked = true; } else { - if( hitEntity.attackEntityFrom( source, damage ) ) + if( hitEntity.hurt( source, damage ) ) { attacked = true; } @@ -217,11 +217,11 @@ public class TurtleTool extends AbstractTurtleUpgrade // Get ready to dig World world = turtle.getWorld(); BlockPos turtlePosition = turtle.getPosition(); - TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getTileEntity( turtlePosition ); + TileEntity turtleTile = turtle instanceof TurtleBrain ? ((TurtleBrain) turtle).getOwner() : world.getBlockEntity( turtlePosition ); if( turtleTile == null ) return TurtleCommandResult.failure( "Turtle has vanished from existence." ); - BlockPos blockPosition = turtlePosition.offset( direction ); - if( world.isAirBlock( blockPosition ) || WorldUtil.isLiquidBlock( world, blockPosition ) ) + BlockPos blockPosition = turtlePosition.relative( direction ); + if( world.isEmptyBlock( blockPosition ) || WorldUtil.isLiquidBlock( world, blockPosition ) ) { return TurtleCommandResult.failure( "Nothing to dig here" ); } @@ -262,21 +262,21 @@ public class TurtleTool extends AbstractTurtleUpgrade // Consume the items the block drops DropConsumer.set( world, blockPosition, turtleDropConsumer( turtleTile, turtle ) ); - TileEntity tile = world.getTileEntity( blockPosition ); + TileEntity tile = world.getBlockEntity( blockPosition ); // Much of this logic comes from PlayerInteractionManager#tryHarvestBlock, so it's a good idea // to consult there before making any changes. // Play the destruction sound and particles - world.playEvent( 2001, blockPosition, Block.getStateId( state ) ); + world.levelEvent( 2001, blockPosition, Block.getId( state ) ); // Destroy the block boolean canHarvest = state.canHarvestBlock( world, blockPosition, turtlePlayer ); boolean canBreak = state.removedByPlayer( world, blockPosition, turtlePlayer, canHarvest, fluidState ); - if( canBreak ) state.getBlock().onPlayerDestroy( world, blockPosition, state ); + if( canBreak ) state.getBlock().destroy( world, blockPosition, state ); if( canHarvest && canBreak ) { - state.getBlock().harvestBlock( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getHeldItemMainhand() ); + state.getBlock().playerDestroy( world, turtlePlayer, blockPosition, state, tile, turtlePlayer.getMainHandItem() ); } stopConsuming( turtleTile, turtle ); diff --git a/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java b/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java index 955d52bac..d446d5782 100644 --- a/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java +++ b/src/main/java/dan200/computercraft/shared/util/CreativeTabMain.java @@ -24,7 +24,7 @@ public class CreativeTabMain extends ItemGroup @Nonnull @Override @OnlyIn( Dist.CLIENT ) - public ItemStack createIcon() + public ItemStack makeIcon() { return new ItemStack( Registry.ModBlocks.COMPUTER_NORMAL.get() ); } diff --git a/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java b/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java index d23ebfcfb..849cbfc81 100644 --- a/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java +++ b/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java @@ -14,23 +14,23 @@ import javax.annotation.Nonnull; public interface DefaultInventory extends IInventory { @Override - default int getInventoryStackLimit() + default int getMaxStackSize() { return 64; } @Override - default void openInventory( @Nonnull PlayerEntity player ) + default void startOpen( @Nonnull PlayerEntity player ) { } @Override - default void closeInventory( @Nonnull PlayerEntity player ) + default void stopOpen( @Nonnull PlayerEntity player ) { } @Override - default boolean isItemValidForSlot( int slot, @Nonnull ItemStack stack ) + default boolean canPlaceItem( int slot, @Nonnull ItemStack stack ) { return true; } diff --git a/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java b/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java index 92f13dea9..82588557b 100644 --- a/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java +++ b/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java @@ -15,13 +15,13 @@ import javax.annotation.Nullable; public interface DefaultSidedInventory extends DefaultInventory, ISidedInventory { @Override - default boolean canInsertItem( int slot, @Nonnull ItemStack stack, @Nullable Direction side ) + default boolean canPlaceItemThroughFace( int slot, @Nonnull ItemStack stack, @Nullable Direction side ) { - return isItemValidForSlot( slot, stack ); + return canPlaceItem( slot, stack ); } @Override - default boolean canExtractItem( int slot, @Nonnull ItemStack stack, @Nonnull Direction side ) + default boolean canTakeItemThroughFace( int slot, @Nonnull ItemStack stack, @Nonnull Direction side ) { return true; } diff --git a/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java b/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java index 65d186659..974411072 100644 --- a/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java @@ -20,8 +20,8 @@ public final class DirectionUtil if( dir == front ) return ComputerSide.FRONT; if( dir == front.getOpposite() ) return ComputerSide.BACK; - if( dir == front.rotateYCCW() ) return ComputerSide.LEFT; - if( dir == front.rotateY() ) return ComputerSide.RIGHT; + if( dir == front.getCounterClockWise() ) return ComputerSide.LEFT; + if( dir == front.getClockWise() ) return ComputerSide.RIGHT; if( dir == Direction.UP ) return ComputerSide.TOP; return ComputerSide.BOTTOM; } diff --git a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java index cb861edba..7aeaee014 100644 --- a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java +++ b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java @@ -40,8 +40,8 @@ public final class DropConsumer dropConsumer = consumer; remainingDrops = new ArrayList<>(); dropEntity = entity; - dropWorld = entity.world; - dropBounds = new AxisAlignedBB( entity.getPosition() ).grow( 2, 2, 2 ); + dropWorld = entity.level; + dropBounds = new AxisAlignedBB( entity.getCommandSenderBlockPosition() ).inflate( 2, 2, 2 ); } public static void set( World world, BlockPos pos, Function consumer ) @@ -50,7 +50,7 @@ public final class DropConsumer remainingDrops = new ArrayList<>( 2 ); dropEntity = null; dropWorld = world; - dropBounds = new AxisAlignedBB( pos ).grow( 2, 2, 2 ); + dropBounds = new AxisAlignedBB( pos ).inflate( 2, 2, 2 ); } public static List clear() @@ -77,7 +77,7 @@ public final class DropConsumer { // Capture any nearby item spawns if( dropWorld == event.getWorld() && event.getEntity() instanceof ItemEntity - && dropBounds.contains( event.getEntity().getPositionVector() ) ) + && dropBounds.contains( event.getEntity().getCommandSenderWorldPosition() ) ) { handleDrops( ((ItemEntity) event.getEntity()).getItem() ); event.setCanceled( true ); diff --git a/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java b/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java index d153b633d..9670068ea 100644 --- a/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java +++ b/src/main/java/dan200/computercraft/shared/util/FakeNetHandler.java @@ -22,7 +22,7 @@ public class FakeNetHandler extends ServerPlayNetHandler { public FakeNetHandler( @Nonnull FakePlayer player ) { - super( player.getServerWorld().getServer(), new FakeNetworkManager(), player ); + super( player.getLevel().getServer(), new FakeNetworkManager(), player ); } @Override @@ -41,32 +41,32 @@ public class FakeNetHandler extends ServerPlayNetHandler } @Override - public void sendPacket( @Nonnull IPacket packet ) + public void send( @Nonnull IPacket packet ) { } @Override - public void sendPacket( @Nonnull IPacket packet, @Nullable GenericFutureListener> whenSent ) + public void send( @Nonnull IPacket packet, @Nullable GenericFutureListener> whenSent ) { } @Override - public void processInput( @Nonnull CInputPacket packet ) + public void handlePlayerInput( @Nonnull CInputPacket packet ) { } @Override - public void processVehicleMove( @Nonnull CMoveVehiclePacket packet ) + public void handleMoveVehicle( @Nonnull CMoveVehiclePacket packet ) { } @Override - public void processConfirmTeleport( @Nonnull CConfirmTeleportPacket packet ) + public void handleAcceptTeleportPacket( @Nonnull CConfirmTeleportPacket packet ) { } @Override - public void handleRecipeBookUpdate( @Nonnull CRecipeInfoPacket packet ) + public void handleRecipeBookUpdatePacket( @Nonnull CRecipeInfoPacket packet ) { } @@ -76,192 +76,192 @@ public class FakeNetHandler extends ServerPlayNetHandler } @Override - public void processTabComplete( @Nonnull CTabCompletePacket packet ) + public void handleCustomCommandSuggestions( @Nonnull CTabCompletePacket packet ) { } @Override - public void processUpdateCommandBlock( @Nonnull CUpdateCommandBlockPacket packet ) + public void handleSetCommandBlock( @Nonnull CUpdateCommandBlockPacket packet ) { } @Override - public void processUpdateCommandMinecart( @Nonnull CUpdateMinecartCommandBlockPacket packet ) + public void handleSetCommandMinecart( @Nonnull CUpdateMinecartCommandBlockPacket packet ) { } @Override - public void processPickItem( @Nonnull CPickItemPacket packet ) + public void handlePickItem( @Nonnull CPickItemPacket packet ) { } @Override - public void processRenameItem( @Nonnull CRenameItemPacket packet ) + public void handleRenameItem( @Nonnull CRenameItemPacket packet ) { } @Override - public void processUpdateBeacon( @Nonnull CUpdateBeaconPacket packet ) + public void handleSetBeaconPacket( @Nonnull CUpdateBeaconPacket packet ) { } @Override - public void processUpdateStructureBlock( @Nonnull CUpdateStructureBlockPacket packet ) + public void handleSetStructureBlock( @Nonnull CUpdateStructureBlockPacket packet ) { } @Override - public void func_217262_a( @Nonnull CUpdateJigsawBlockPacket packet ) + public void handleSetJigsawBlock( @Nonnull CUpdateJigsawBlockPacket packet ) { } @Override - public void processSelectTrade( @Nonnull CSelectTradePacket packet ) + public void handleSelectTrade( @Nonnull CSelectTradePacket packet ) { } @Override - public void processEditBook( @Nonnull CEditBookPacket packet ) + public void handleEditBook( @Nonnull CEditBookPacket packet ) { } @Override - public void processNBTQueryEntity( @Nonnull CQueryEntityNBTPacket packet ) + public void handleEntityTagQuery( @Nonnull CQueryEntityNBTPacket packet ) { } @Override - public void processNBTQueryBlockEntity( @Nonnull CQueryTileEntityNBTPacket packet ) + public void handleBlockEntityTagQuery( @Nonnull CQueryTileEntityNBTPacket packet ) { } @Override - public void processPlayer( @Nonnull CPlayerPacket packet ) + public void handleMovePlayer( @Nonnull CPlayerPacket packet ) { } @Override - public void processPlayerDigging( @Nonnull CPlayerDiggingPacket packet ) + public void handlePlayerAction( @Nonnull CPlayerDiggingPacket packet ) { } @Override - public void processTryUseItemOnBlock( @Nonnull CPlayerTryUseItemOnBlockPacket packet ) + public void handleUseItemOn( @Nonnull CPlayerTryUseItemOnBlockPacket packet ) { } @Override - public void processTryUseItem( @Nonnull CPlayerTryUseItemPacket packet ) + public void handleUseItem( @Nonnull CPlayerTryUseItemPacket packet ) { } @Override - public void handleSpectate( @Nonnull CSpectatePacket packet ) + public void handleTeleportToEntityPacket( @Nonnull CSpectatePacket packet ) { } @Override - public void handleResourcePackStatus( @Nonnull CResourcePackStatusPacket packet ) + public void handleResourcePackResponse( @Nonnull CResourcePackStatusPacket packet ) { } @Override - public void processSteerBoat( @Nonnull CSteerBoatPacket packet ) + public void handlePaddleBoat( @Nonnull CSteerBoatPacket packet ) { } @Override - public void processHeldItemChange( @Nonnull CHeldItemChangePacket packet ) + public void handleSetCarriedItem( @Nonnull CHeldItemChangePacket packet ) { } @Override - public void processChatMessage( @Nonnull CChatMessagePacket packet ) + public void handleChat( @Nonnull CChatMessagePacket packet ) { } @Override - public void handleAnimation( @Nonnull CAnimateHandPacket packet ) + public void handleAnimate( @Nonnull CAnimateHandPacket packet ) { } @Override - public void processEntityAction( @Nonnull CEntityActionPacket packet ) + public void handlePlayerCommand( @Nonnull CEntityActionPacket packet ) { } @Override - public void processUseEntity( @Nonnull CUseEntityPacket packet ) + public void handleInteract( @Nonnull CUseEntityPacket packet ) { } @Override - public void processClientStatus( @Nonnull CClientStatusPacket packet ) + public void handleClientCommand( @Nonnull CClientStatusPacket packet ) { } @Override - public void processCloseWindow( @Nonnull CCloseWindowPacket packet ) + public void handleContainerClose( @Nonnull CCloseWindowPacket packet ) { } @Override - public void processClickWindow( @Nonnull CClickWindowPacket packet ) + public void handleContainerClick( @Nonnull CClickWindowPacket packet ) { } @Override - public void processPlaceRecipe( @Nonnull CPlaceRecipePacket packet ) + public void handlePlaceRecipe( @Nonnull CPlaceRecipePacket packet ) { } @Override - public void processEnchantItem( @Nonnull CEnchantItemPacket packet ) + public void handleContainerButtonClick( @Nonnull CEnchantItemPacket packet ) { } @Override - public void processCreativeInventoryAction( @Nonnull CCreativeInventoryActionPacket packet ) + public void handleSetCreativeModeSlot( @Nonnull CCreativeInventoryActionPacket packet ) { } @Override - public void processConfirmTransaction( @Nonnull CConfirmTransactionPacket packet ) + public void handleContainerAck( @Nonnull CConfirmTransactionPacket packet ) { } @Override - public void processUpdateSign( @Nonnull CUpdateSignPacket packet ) + public void handleSignUpdate( @Nonnull CUpdateSignPacket packet ) { } @Override - public void processKeepAlive( @Nonnull CKeepAlivePacket packet ) + public void handleKeepAlive( @Nonnull CKeepAlivePacket packet ) { } @Override - public void processPlayerAbilities( @Nonnull CPlayerAbilitiesPacket packet ) + public void handlePlayerAbilities( @Nonnull CPlayerAbilitiesPacket packet ) { } @Override - public void processClientSettings( @Nonnull CClientSettingsPacket packet ) + public void handleClientInformation( @Nonnull CClientSettingsPacket packet ) { } @Override - public void processCustomPayload( @Nonnull CCustomPayloadPacket packet ) + public void handleCustomPayload( @Nonnull CCustomPayloadPacket packet ) { } @Override - public void func_217263_a( @Nonnull CSetDifficultyPacket packet ) + public void handleChangeDifficulty( @Nonnull CSetDifficultyPacket packet ) { } @Override - public void func_217261_a( @Nonnull CLockDifficultyPacket packet ) + public void handleLockDifficulty( @Nonnull CLockDifficultyPacket packet ) { } @@ -281,7 +281,7 @@ public class FakeNetHandler extends ServerPlayNetHandler } @Override - public void setConnectionState( @Nonnull ProtocolType state ) + public void setProtocol( @Nonnull ProtocolType state ) { } @@ -301,18 +301,18 @@ public class FakeNetHandler extends ServerPlayNetHandler } @Override - public void setNetHandler( @Nonnull INetHandler handler ) + public void setListener( @Nonnull INetHandler handler ) { this.handler = handler; } @Override - public void sendPacket( @Nonnull IPacket packet ) + public void send( @Nonnull IPacket packet ) { } @Override - public void sendPacket( @Nonnull IPacket packet, @Nullable GenericFutureListener> whenSent ) + public void send( @Nonnull IPacket packet, @Nullable GenericFutureListener> whenSent ) { } @@ -322,37 +322,37 @@ public class FakeNetHandler extends ServerPlayNetHandler } @Override - public void closeChannel( @Nonnull ITextComponent message ) + public void disconnect( @Nonnull ITextComponent message ) { this.closeReason = message; } @Override - public void enableEncryption( @Nonnull SecretKey key ) + public void setEncryptionKey( @Nonnull SecretKey key ) { } @Nonnull @Override - public INetHandler getNetHandler() + public INetHandler getPacketListener() { return handler; } @Nullable @Override - public ITextComponent getExitMessage() + public ITextComponent getDisconnectedReason() { return closeReason; } @Override - public void disableAutoRead() + public void setReadOnly() { } @Override - public void setCompressionThreshold( int threshold ) + public void setupCompression( int threshold ) { } } diff --git a/src/main/java/dan200/computercraft/shared/util/FixedPointTileEntityType.java b/src/main/java/dan200/computercraft/shared/util/FixedPointTileEntityType.java index ffc2fc411..2eb921f20 100644 --- a/src/main/java/dan200/computercraft/shared/util/FixedPointTileEntityType.java +++ b/src/main/java/dan200/computercraft/shared/util/FixedPointTileEntityType.java @@ -35,7 +35,7 @@ public final class FixedPointTileEntityType extends TileEn } @Override - public boolean isValidBlock( @Nonnull Block block ) + public boolean isValid( @Nonnull Block block ) { return block == this.block.get(); } diff --git a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java index dfa7a8ac4..d8aeba4a2 100644 --- a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java +++ b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java @@ -42,7 +42,7 @@ public final class IDAssigner public static File getDir() { MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); - File worldDirectory = server.getWorld( DimensionType.OVERWORLD ).getSaveHandler().getWorldDirectory(); + File worldDirectory = server.getLevel( DimensionType.OVERWORLD ).getLevelStorage().getFolder(); return new File( worldDirectory, ComputerCraft.MOD_ID ); } diff --git a/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java b/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java index eed4f920f..418fa9449 100644 --- a/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java +++ b/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java @@ -45,7 +45,7 @@ public final class ImpostorRecipe extends ShapedRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) + public ItemStack assemble( @Nonnull CraftingInventory inventory ) { return ItemStack.EMPTY; } @@ -60,34 +60,34 @@ public final class ImpostorRecipe extends ShapedRecipe public static final IRecipeSerializer SERIALIZER = new BasicRecipeSerializer() { @Override - public ImpostorRecipe read( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json ) + public ImpostorRecipe fromJson( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json ) { - String group = JSONUtils.getString( json, "group", "" ); - ShapedRecipe recipe = IRecipeSerializer.CRAFTING_SHAPED.read( identifier, json ); - ItemStack result = CraftingHelper.getItemStack( JSONUtils.getJsonObject( json, "result" ), true ); + String group = JSONUtils.getAsString( json, "group", "" ); + ShapedRecipe recipe = IRecipeSerializer.SHAPED_RECIPE.fromJson( identifier, json ); + ItemStack result = CraftingHelper.getItemStack( JSONUtils.getAsJsonObject( json, "result" ), true ); return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getIngredients(), result ); } @Override - public ImpostorRecipe read( @Nonnull ResourceLocation identifier, @Nonnull PacketBuffer buf ) + public ImpostorRecipe fromNetwork( @Nonnull ResourceLocation identifier, @Nonnull PacketBuffer buf ) { int width = buf.readVarInt(); int height = buf.readVarInt(); - String group = buf.readString( Short.MAX_VALUE ); + String group = buf.readUtf( Short.MAX_VALUE ); NonNullList items = NonNullList.withSize( width * height, Ingredient.EMPTY ); - for( int k = 0; k < items.size(); ++k ) items.set( k, Ingredient.read( buf ) ); - ItemStack result = buf.readItemStack(); + for( int k = 0; k < items.size(); ++k ) items.set( k, Ingredient.fromNetwork( buf ) ); + ItemStack result = buf.readItem(); return new ImpostorRecipe( identifier, group, width, height, items, result ); } @Override - public void write( @Nonnull PacketBuffer buf, @Nonnull ImpostorRecipe recipe ) + public void toNetwork( @Nonnull PacketBuffer buf, @Nonnull ImpostorRecipe recipe ) { buf.writeVarInt( recipe.getRecipeWidth() ); buf.writeVarInt( recipe.getRecipeHeight() ); - buf.writeString( recipe.getGroup() ); - for( Ingredient ingredient : recipe.getIngredients() ) ingredient.write( buf ); - buf.writeItemStack( recipe.getRecipeOutput() ); + buf.writeUtf( recipe.getGroup() ); + for( Ingredient ingredient : recipe.getIngredients() ) ingredient.toNetwork( buf ); + buf.writeItem( recipe.getResultItem() ); } }; } diff --git a/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java b/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java index 42b77e9fe..60d449ef7 100644 --- a/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java +++ b/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java @@ -47,7 +47,7 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) + public ItemStack assemble( @Nonnull CraftingInventory inventory ) { return ItemStack.EMPTY; } @@ -62,10 +62,10 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe public static final IRecipeSerializer SERIALIZER = new BasicRecipeSerializer() { @Override - public ImpostorShapelessRecipe read( @Nonnull ResourceLocation id, @Nonnull JsonObject json ) + public ImpostorShapelessRecipe fromJson( @Nonnull ResourceLocation id, @Nonnull JsonObject json ) { - String s = JSONUtils.getString( json, "group", "" ); - NonNullList ingredients = readIngredients( JSONUtils.getJsonArray( json, "ingredients" ) ); + String s = JSONUtils.getAsString( json, "group", "" ); + NonNullList ingredients = readIngredients( JSONUtils.getAsJsonArray( json, "ingredients" ) ); if( ingredients.isEmpty() ) throw new JsonParseException( "No ingredients for shapeless recipe" ); if( ingredients.size() > 9 ) @@ -73,7 +73,7 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe throw new JsonParseException( "Too many ingredients for shapeless recipe the max is 9" ); } - ItemStack itemstack = CraftingHelper.getItemStack( JSONUtils.getJsonObject( json, "result" ), true ); + ItemStack itemstack = CraftingHelper.getItemStack( JSONUtils.getAsJsonObject( json, "result" ), true ); return new ImpostorShapelessRecipe( id, s, itemstack, ingredients ); } @@ -82,34 +82,34 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe NonNullList items = NonNullList.create(); for( int i = 0; i < arrays.size(); ++i ) { - Ingredient ingredient = Ingredient.deserialize( arrays.get( i ) ); - if( !ingredient.hasNoMatchingItems() ) items.add( ingredient ); + Ingredient ingredient = Ingredient.fromJson( arrays.get( i ) ); + if( !ingredient.isEmpty() ) items.add( ingredient ); } return items; } @Override - public ImpostorShapelessRecipe read( @Nonnull ResourceLocation id, PacketBuffer buffer ) + public ImpostorShapelessRecipe fromNetwork( @Nonnull ResourceLocation id, PacketBuffer buffer ) { - String s = buffer.readString( 32767 ); + String s = buffer.readUtf( 32767 ); int i = buffer.readVarInt(); NonNullList items = NonNullList.withSize( i, Ingredient.EMPTY ); - for( int j = 0; j < items.size(); j++ ) items.set( j, Ingredient.read( buffer ) ); - ItemStack result = buffer.readItemStack(); + for( int j = 0; j < items.size(); j++ ) items.set( j, Ingredient.fromNetwork( buffer ) ); + ItemStack result = buffer.readItem(); return new ImpostorShapelessRecipe( id, s, result, items ); } @Override - public void write( @Nonnull PacketBuffer buffer, @Nonnull ImpostorShapelessRecipe recipe ) + public void toNetwork( @Nonnull PacketBuffer buffer, @Nonnull ImpostorShapelessRecipe recipe ) { - buffer.writeString( recipe.getGroup() ); + buffer.writeUtf( recipe.getGroup() ); buffer.writeVarInt( recipe.getIngredients().size() ); - for( Ingredient ingredient : recipe.getIngredients() ) ingredient.write( buffer ); - buffer.writeItemStack( recipe.getRecipeOutput() ); + for( Ingredient ingredient : recipe.getIngredients() ) ingredient.toNetwork( buffer ); + buffer.writeItem( recipe.getResultItem() ); } }; } diff --git a/src/main/java/dan200/computercraft/shared/util/InventoryDelegate.java b/src/main/java/dan200/computercraft/shared/util/InventoryDelegate.java index 9e07db877..bf01c855b 100644 --- a/src/main/java/dan200/computercraft/shared/util/InventoryDelegate.java +++ b/src/main/java/dan200/computercraft/shared/util/InventoryDelegate.java @@ -25,9 +25,9 @@ public interface InventoryDelegate extends IInventory IInventory getInventory(); @Override - default int getSizeInventory() + default int getContainerSize() { - return getInventory().getSizeInventory(); + return getInventory().getContainerSize(); } @Override @@ -38,82 +38,82 @@ public interface InventoryDelegate extends IInventory @Nonnull @Override - default ItemStack getStackInSlot( int slot ) + default ItemStack getItem( int slot ) { - return getInventory().getStackInSlot( slot ); + return getInventory().getItem( slot ); } @Nonnull @Override - default ItemStack decrStackSize( int slot, int count ) + default ItemStack removeItem( int slot, int count ) { - return getInventory().decrStackSize( slot, count ); + return getInventory().removeItem( slot, count ); } @Nonnull @Override - default ItemStack removeStackFromSlot( int slot ) + default ItemStack removeItemNoUpdate( int slot ) { - return getInventory().removeStackFromSlot( slot ); + return getInventory().removeItemNoUpdate( slot ); } @Override - default void setInventorySlotContents( int slot, @Nonnull ItemStack stack ) + default void setItem( int slot, @Nonnull ItemStack stack ) { - getInventory().setInventorySlotContents( slot, stack ); + getInventory().setItem( slot, stack ); } @Override - default int getInventoryStackLimit() + default int getMaxStackSize() { - return getInventory().getInventoryStackLimit(); + return getInventory().getMaxStackSize(); } @Override - default void markDirty() + default void setChanged() { - getInventory().markDirty(); + getInventory().setChanged(); } @Override - default boolean isUsableByPlayer( @Nonnull PlayerEntity player ) + default boolean stillValid( @Nonnull PlayerEntity player ) { - return getInventory().isUsableByPlayer( player ); + return getInventory().stillValid( player ); } @Override - default void openInventory( @Nonnull PlayerEntity player ) + default void startOpen( @Nonnull PlayerEntity player ) { - getInventory().openInventory( player ); + getInventory().startOpen( player ); } @Override - default void closeInventory( @Nonnull PlayerEntity player ) + default void stopOpen( @Nonnull PlayerEntity player ) { - getInventory().closeInventory( player ); + getInventory().stopOpen( player ); } @Override - default boolean isItemValidForSlot( int slot, @Nonnull ItemStack stack ) + default boolean canPlaceItem( int slot, @Nonnull ItemStack stack ) { - return getInventory().isItemValidForSlot( slot, stack ); + return getInventory().canPlaceItem( slot, stack ); } @Override - default void clear() + default void clearContent() { - getInventory().clear(); + getInventory().clearContent(); } @Override - default int count( @Nonnull Item stack ) + default int countItem( @Nonnull Item stack ) { - return getInventory().count( stack ); + return getInventory().countItem( stack ); } @Override - default boolean hasAny( @Nonnull Set set ) + default boolean hasAnyOf( @Nonnull Set set ) { - return getInventory().hasAny( set ); + return getInventory().hasAnyOf( set ); } } diff --git a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java index 46fb5b37e..faab94b04 100644 --- a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java @@ -31,7 +31,7 @@ public final class InventoryUtil public static boolean areItemsEqual( @Nonnull ItemStack a, @Nonnull ItemStack b ) { - return a == b || ItemStack.areItemStacksEqual( a, b ); + return a == b || ItemStack.matches( a, b ); } public static boolean areItemsStackable( @Nonnull ItemStack a, @Nonnull ItemStack b ) @@ -44,7 +44,7 @@ public final class InventoryUtil public static IItemHandler getInventory( World world, BlockPos pos, Direction side ) { // Look for tile with inventory - TileEntity tileEntity = world.getTileEntity( pos ); + TileEntity tileEntity = world.getBlockEntity( pos ); if( tileEntity != null ) { LazyOptional itemHandler = tileEntity.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side ); @@ -64,13 +64,13 @@ public final class InventoryUtil // Look for entity with inventory Vec3d vecStart = new Vec3d( - pos.getX() + 0.5 + 0.6 * side.getXOffset(), - pos.getY() + 0.5 + 0.6 * side.getYOffset(), - pos.getZ() + 0.5 + 0.6 * side.getZOffset() + pos.getX() + 0.5 + 0.6 * side.getStepX(), + pos.getY() + 0.5 + 0.6 * side.getStepY(), + pos.getZ() + 0.5 + 0.6 * side.getStepZ() ); Direction dir = side.getOpposite(); Vec3d vecDir = new Vec3d( - dir.getXOffset(), dir.getYOffset(), dir.getZOffset() + dir.getStepX(), dir.getStepY(), dir.getStepZ() ); Pair hit = WorldUtil.rayTraceEntities( world, vecStart, vecDir, 1.1 ); if( hit != null ) diff --git a/src/main/java/dan200/computercraft/shared/util/NBTUtil.java b/src/main/java/dan200/computercraft/shared/util/NBTUtil.java index 2d534ac5b..5895ebdfb 100644 --- a/src/main/java/dan200/computercraft/shared/util/NBTUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/NBTUtil.java @@ -76,12 +76,12 @@ public final class NBTUtil switch( tag.getId() ) { case TAG_BYTE: - return ((ByteNBT) tag).getByte() > 0; + return ((ByteNBT) tag).getAsByte() > 0; case TAG_DOUBLE: - return ((DoubleNBT) tag).getDouble(); + return ((DoubleNBT) tag).getAsDouble(); default: case TAG_STRING: - return tag.getString(); + return tag.getAsString(); case TAG_COMPOUND: { CompoundNBT c = (CompoundNBT) tag; @@ -109,17 +109,17 @@ public final class NBTUtil case Constants.NBT.TAG_SHORT: case Constants.NBT.TAG_INT: case Constants.NBT.TAG_LONG: - return ((NumberNBT) tag).getLong(); + return ((NumberNBT) tag).getAsLong(); case Constants.NBT.TAG_FLOAT: case Constants.NBT.TAG_DOUBLE: - return ((NumberNBT) tag).getDouble(); + return ((NumberNBT) tag).getAsDouble(); case Constants.NBT.TAG_STRING: // String - return tag.getString(); + return tag.getAsString(); case Constants.NBT.TAG_COMPOUND: // Compound { CompoundNBT compound = (CompoundNBT) tag; Map map = new HashMap<>( compound.size() ); - for( String key : compound.keySet() ) + for( String key : compound.getAllKeys() ) { Object value = toLua( compound.get( key ) ); if( value != null ) map.put( key, value ); @@ -135,14 +135,14 @@ public final class NBTUtil } case Constants.NBT.TAG_BYTE_ARRAY: { - byte[] array = ((ByteArrayNBT) tag).getByteArray(); + byte[] array = ((ByteArrayNBT) tag).getAsByteArray(); Map map = new HashMap<>( array.length ); for( int i = 0; i < array.length; i++ ) map.put( i + 1, array[i] ); return map; } case Constants.NBT.TAG_INT_ARRAY: { - int[] array = ((IntArrayNBT) tag).getIntArray(); + int[] array = ((IntArrayNBT) tag).getAsIntArray(); Map map = new HashMap<>( array.length ); for( int i = 0; i < array.length; i++ ) map.put( i + 1, array[i] ); return map; diff --git a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java index b142b7f70..b27cb75b9 100644 --- a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java @@ -42,7 +42,7 @@ public final class RecipeUtil public static ShapedTemplate getTemplate( JsonObject json ) { Map ingMap = Maps.newHashMap(); - for( Map.Entry entry : JSONUtils.getJsonObject( json, "key" ).entrySet() ) + for( Map.Entry entry : JSONUtils.getAsJsonObject( json, "key" ).entrySet() ) { if( entry.getKey().length() != 1 ) { @@ -53,12 +53,12 @@ public final class RecipeUtil throw new JsonSyntaxException( "Invalid key entry: ' ' is a reserved symbol." ); } - ingMap.put( entry.getKey().charAt( 0 ), Ingredient.deserialize( entry.getValue() ) ); + ingMap.put( entry.getKey().charAt( 0 ), Ingredient.fromJson( entry.getValue() ) ); } ingMap.put( ' ', Ingredient.EMPTY ); - JsonArray patternJ = JSONUtils.getJsonArray( json, "pattern" ); + JsonArray patternJ = JSONUtils.getAsJsonArray( json, "pattern" ); if( patternJ.size() == 0 ) { @@ -68,7 +68,7 @@ public final class RecipeUtil String[] pattern = new String[patternJ.size()]; for( int x = 0; x < pattern.length; x++ ) { - String line = JSONUtils.getString( patternJ.get( x ), "pattern[" + x + "]" ); + String line = JSONUtils.convertToString( patternJ.get( x ), "pattern[" + x + "]" ); if( x > 0 && pattern[0].length() != line.length() ) { throw new JsonSyntaxException( "Invalid pattern: each row must be the same width" ); @@ -108,7 +108,7 @@ public final class RecipeUtil public static ComputerFamily getFamily( JsonObject json, String name ) { - String familyName = JSONUtils.getString( json, name ); + String familyName = JSONUtils.getAsString( json, name ); for( ComputerFamily family : ComputerFamily.values() ) { if( family.name().equalsIgnoreCase( familyName ) ) return family; diff --git a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java index 933a287cb..41c632dc9 100644 --- a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java @@ -21,8 +21,8 @@ public final class RedstoneUtil BlockState block = world.getBlockState( pos ); if( ForgeEventFactory.onNeighborNotify( world, pos, block, EnumSet.of( side ), false ).isCanceled() ) return; - BlockPos neighbourPos = pos.offset( side ); + BlockPos neighbourPos = pos.relative( side ); world.neighborChanged( neighbourPos, block.getBlock(), pos ); - world.notifyNeighborsOfStateExcept( neighbourPos, block.getBlock(), side.getOpposite() ); + world.updateNeighborsAtExceptFromFacing( neighbourPos, block.getBlock(), side.getOpposite() ); } } diff --git a/src/main/java/dan200/computercraft/shared/util/SingleIntArray.java b/src/main/java/dan200/computercraft/shared/util/SingleIntArray.java index 19f763e67..cad7144b5 100644 --- a/src/main/java/dan200/computercraft/shared/util/SingleIntArray.java +++ b/src/main/java/dan200/computercraft/shared/util/SingleIntArray.java @@ -24,7 +24,7 @@ public interface SingleIntArray extends IIntArray } @Override - default int size() + default int getCount() { return 1; } diff --git a/src/main/java/dan200/computercraft/shared/util/TickScheduler.java b/src/main/java/dan200/computercraft/shared/util/TickScheduler.java index 760ad6a8c..6a1a78627 100644 --- a/src/main/java/dan200/computercraft/shared/util/TickScheduler.java +++ b/src/main/java/dan200/computercraft/shared/util/TickScheduler.java @@ -40,8 +40,8 @@ public final class TickScheduler public static void schedule( TileGeneric tile ) { - World world = tile.getWorld(); - if( world != null && !world.isRemote ) toTick.add( tile ); + World world = tile.getLevel(); + if( world != null && !world.isClientSide ) toTick.add( tile ); } @SubscribeEvent @@ -55,12 +55,12 @@ public final class TickScheduler TileEntity tile = iterator.next(); iterator.remove(); - World world = tile.getWorld(); - BlockPos pos = tile.getPos(); + World world = tile.getLevel(); + BlockPos pos = tile.getBlockPos(); - if( world != null && pos != null && world.isAreaLoaded( pos, 0 ) && world.getTileEntity( pos ) == tile ) + if( world != null && pos != null && world.isAreaLoaded( pos, 0 ) && world.getBlockEntity( pos ) == tile ) { - world.getPendingBlockTicks().scheduleTick( pos, tile.getBlockState().getBlock(), 0 ); + world.getBlockTicks().scheduleTick( pos, tile.getBlockState().getBlock(), 0 ); } } } diff --git a/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java b/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java index ec541024d..57904d60a 100644 --- a/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java +++ b/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java @@ -19,7 +19,7 @@ public class ValidatingSlot extends Slot } @Override - public boolean isItemValid( @Nonnull ItemStack stack ) + public boolean mayPlace( @Nonnull ItemStack stack ) { return true; // inventory.isItemValidForSlot( slotNumber, stack ); } diff --git a/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java b/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java index e9d6e9c54..76dda67af 100644 --- a/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java +++ b/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java @@ -36,7 +36,7 @@ public final class WaterloggableHelpers */ public static IFluidState getWaterloggedFluidState( BlockState state ) { - return state.get( WATERLOGGED ) ? Fluids.WATER.getStillFluidState( false ) : Fluids.EMPTY.getDefaultState(); + return state.getValue( WATERLOGGED ) ? Fluids.WATER.getSource( false ) : Fluids.EMPTY.defaultFluidState(); } /** @@ -48,14 +48,14 @@ public final class WaterloggableHelpers */ public static void updateWaterloggedPostPlacement( BlockState state, IWorld world, BlockPos pos ) { - if( state.get( WATERLOGGED ) ) + if( state.getValue( WATERLOGGED ) ) { - world.getPendingFluidTicks().scheduleTick( pos, Fluids.WATER, Fluids.WATER.getTickRate( world ) ); + world.getLiquidTicks().scheduleTick( pos, Fluids.WATER, Fluids.WATER.getTickDelay( world ) ); } } public static boolean getWaterloggedStateForPlacement( BlockItemUseContext context ) { - return context.getWorld().getFluidState( context.getPos() ).getFluid() == Fluids.WATER; + return context.getLevel().getFluidState( context.getClickedPos() ).getType() == Fluids.WATER; } } diff --git a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java index d7415a5d5..a11eb97a4 100644 --- a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java @@ -24,7 +24,7 @@ import java.util.Map; public final class WorldUtil { @SuppressWarnings( "Guava" ) - private static final Predicate CAN_COLLIDE = x -> x != null && x.isAlive() && x.canBeCollidedWith(); + private static final Predicate CAN_COLLIDE = x -> x != null && x.isAlive() && x.isPickable(); private static final Map entityCache = new MapMaker().weakKeys().weakValues().makeMap(); @@ -38,21 +38,21 @@ public final class WorldUtil { @Nonnull @Override - public EntitySize getSize( @Nonnull Pose pose ) + public EntitySize getDimensions( @Nonnull Pose pose ) { return EntitySize.fixed( 0, 0 ); } }; - entity.noClip = true; - entity.recalculateSize(); + entity.noPhysics = true; + entity.refreshDimensions(); entityCache.put( world, entity ); return entity; } public static boolean isLiquidBlock( World world, BlockPos pos ) { - if( !World.isValid( pos ) ) return false; + if( !World.isInWorldBounds( pos ) ) return false; return world.getBlockState( pos ).getMaterial().isLiquid(); } @@ -60,7 +60,7 @@ public final class WorldUtil { if( shape.isEmpty() ) return false; // AxisAlignedBB.contains, but without strict inequalities. - AxisAlignedBB bb = shape.getBoundingBox(); + AxisAlignedBB bb = shape.bounds(); return vec.x >= bb.minX && vec.x <= bb.maxX && vec.y >= bb.minY && vec.y <= bb.maxY && vec.z >= bb.minZ && vec.z <= bb.maxZ; } @@ -70,12 +70,12 @@ public final class WorldUtil // Raycast for blocks Entity collisionEntity = getEntity( world ); - collisionEntity.setPosition( vecStart.x, vecStart.y, vecStart.z ); + collisionEntity.setPos( vecStart.x, vecStart.y, vecStart.z ); RayTraceContext context = new RayTraceContext( vecStart, vecEnd, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, collisionEntity ); - RayTraceResult result = world.rayTraceBlocks( context ); + RayTraceResult result = world.clip( context ); if( result != null && result.getType() == RayTraceResult.Type.BLOCK ) { - distance = vecStart.distanceTo( result.getHitVec() ); + distance = vecStart.distanceTo( result.getLocation() ); vecEnd = vecStart.add( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance ); } @@ -94,7 +94,7 @@ public final class WorldUtil Entity closest = null; double closestDist = 99.0; - List list = world.getEntitiesWithinAABB( Entity.class, bigBox, CAN_COLLIDE ); + List list = world.getEntitiesOfClass( Entity.class, bigBox, CAN_COLLIDE ); for( Entity entity : list ) { AxisAlignedBB littleBox = entity.getBoundingBox(); @@ -105,7 +105,7 @@ public final class WorldUtil continue; } - Vec3d littleBoxResult = littleBox.rayTrace( vecStart, vecEnd ).orElse( null ); + Vec3d littleBoxResult = littleBox.clip( vecStart, vecEnd ).orElse( null ); if( littleBoxResult != null ) { double dist = vecStart.distanceTo( littleBoxResult ); @@ -140,7 +140,7 @@ public final class WorldUtil public static Vec3d getRayEnd( PlayerEntity player ) { double reach = player.getAttribute( PlayerEntity.REACH_DISTANCE ).getValue(); - Vec3d look = player.getLookVec(); + Vec3d look = player.getLookAngle(); return getRayStart( player ).add( look.x * reach, look.y * reach, look.z * reach ); } @@ -156,9 +156,9 @@ public final class WorldUtil double zDir; if( direction != null ) { - xDir = direction.getXOffset(); - yDir = direction.getYOffset(); - zDir = direction.getZOffset(); + xDir = direction.getStepX(); + yDir = direction.getStepY(); + zDir = direction.getStepZ(); } else { @@ -181,12 +181,12 @@ public final class WorldUtil public static void dropItemStack( @Nonnull ItemStack stack, World world, Vec3d pos, double xDir, double yDir, double zDir ) { ItemEntity item = new ItemEntity( world, pos.x, pos.y, pos.z, stack.copy() ); - item.setMotion( + item.setDeltaMovement( xDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1, yDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1, zDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1 ); - item.setDefaultPickupDelay(); - world.addEntity( item ); + item.setDefaultPickUpDelay(); + world.addFreshEntity( item ); } } diff --git a/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java b/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java index b66d9accb..9077172b8 100644 --- a/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java +++ b/src/test/java/dan200/computercraft/core/filesystem/ResourceMountTest.java @@ -29,7 +29,7 @@ public class ResourceMountTest public void before() { SimpleReloadableResourceManager manager = new SimpleReloadableResourceManager( ResourcePackType.SERVER_DATA, null ); - manager.addResourcePack( new FolderPack( new File( "src/main/resources" ) ) ); + manager.add( new FolderPack( new File( "src/main/resources" ) ) ); mount = ResourceMount.get( "computercraft", "lua/rom", manager ); } diff --git a/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java b/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java index a329fb565..ae6dd9117 100644 --- a/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java +++ b/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java @@ -259,7 +259,7 @@ public class NetworkTest grid.forEach( ( existing, pos ) -> { for( Direction facing : DirectionUtil.FACINGS ) { - BlockPos offset = pos.offset( facing ); + BlockPos offset = pos.relative( facing ); if( offset.getX() > BRUTE_SIZE / 2 == pos.getX() > BRUTE_SIZE / 2 ) { IWiredNode other = grid.get( offset );