diff --git a/build.gradle b/build.gradle index b91b7b776..7f8f4cc7c 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } dependencies { classpath 'com.google.code.gson:gson:2.8.1' - classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.117' + classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.128' classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2' classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0' } @@ -98,7 +98,7 @@ dependencies { // deobfProvided "pl.asie:Charset-Lib:0.5.4.6" // deobfProvided "MCMultiPart2:MCMultiPart:2.5.3" - runtimeOnly fg.deobf("mezz.jei:jei-1.13.2:5.0.0.20") + // runtimeOnly fg.deobf("mezz.jei:jei-1.13.2:5.0.0.20") shade 'org.squiddev:Cobalt:0.5.0-SNAPSHOT' @@ -127,7 +127,7 @@ jar { manifest { attributes(["Specification-Title": "computercraft", "Specification-Vendor": "SquidDev", - "Specification-Version": "25.0", + "Specification-Version": "26.0", "Implementation-Title": "CC: Tweaked", "Implementation-Version": "${mod_version}", "Implementation-Vendor" :"SquidDev", @@ -355,7 +355,7 @@ curseforge { apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : '' project { id = '282001' - releaseType = 'release' + releaseType = 'beta' changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})." relations { @@ -431,7 +431,7 @@ githubRelease { .takeWhile { it != 'Type "help changelog" to see the full version history.' } .join("\n").trim() } - prerelease false + prerelease true } def uploadTasks = ["uploadArchives", "curseforge", "githubRelease"] diff --git a/gradle.properties b/gradle.properties index ba8ad0fed..75c81b3d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,6 +2,6 @@ mod_version=1.83.1 # Minecraft properties -mc_version=1.13.2 -forge_version=25.0.219 -mappings_version=20190530-1.13.2 +mc_version=1.14.2 +forge_version=26.0.5 +mappings_version=20190608-1.14.2 diff --git a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java index 14ac6ea84..938c63cd9 100644 --- a/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java +++ b/src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java @@ -26,7 +26,7 @@ import dan200.computercraft.shared.util.IDAssigner; import dan200.computercraft.shared.wired.CapabilityWiredElement; import dan200.computercraft.shared.wired.WiredNode; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; @@ -94,7 +94,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI } @Override - public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) + public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) { return BundledRedstone.getDefaultOutput( world, pos, side ); } @@ -133,7 +133,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI @Nonnull @Override - public LazyOptional getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) + public LazyOptional getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side ) { TileEntity tile = world.getTileEntity( pos ); return tile == null ? LazyOptional.empty() : tile.getCapability( CapabilityWiredElement.CAPABILITY, side ); diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java index 8570d676e..65ea0aaae 100644 --- a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -20,7 +20,7 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider; import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.turtle.ITurtleUpgrade; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; @@ -183,7 +183,7 @@ public final class ComputerCraftAPI * If there is no block capable of emitting bundled redstone at the location, -1 will be returned. * @see IBundledRedstoneProvider */ - public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) + public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) { return getInstance().getBundledRedstoneOutput( world, pos, side ); } @@ -242,7 +242,7 @@ public final class ComputerCraftAPI * @see IWiredElement#getNode() */ @Nonnull - public static LazyOptional getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) + public static LazyOptional getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side ) { return getInstance().getWiredElementAt( world, pos, side ); } @@ -284,7 +284,7 @@ public final class ComputerCraftAPI void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider ); - int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ); + int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ); void registerMediaProvider( @Nonnull IMediaProvider provider ); @@ -299,6 +299,6 @@ public final class ComputerCraftAPI IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element ); @Nonnull - LazyOptional getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ); + LazyOptional getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side ); } } diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java index 0c39e83cf..aef586157 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -7,7 +7,7 @@ package dan200.computercraft.api.peripheral; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -34,5 +34,5 @@ public interface IPeripheralProvider * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) */ @Nullable - IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ); + IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ); } diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralTile.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralTile.java index 55e5a5c3f..accc87bef 100644 --- a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralTile.java +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralTile.java @@ -5,7 +5,7 @@ */ package dan200.computercraft.api.peripheral; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -25,8 +25,8 @@ public interface IPeripheralTile * * @param side The side to get the peripheral from. * @return A peripheral, or {@code null} if there is not a peripheral here. - * @see IPeripheralProvider#getPeripheral(World, BlockPos, EnumFacing) + * @see IPeripheralProvider#getPeripheral(World, BlockPos, Direction) */ @Nullable - IPeripheral getPeripheral( @Nonnull EnumFacing side ); + IPeripheral getPeripheral( @Nonnull Direction side ); } diff --git a/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java b/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java index beeda54fe..5ee079342 100644 --- a/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java +++ b/src/main/java/dan200/computercraft/api/pocket/IPocketAccess.java @@ -8,7 +8,7 @@ package dan200.computercraft.api.pocket; import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.entity.Entity; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ResourceLocation; import javax.annotation.Nonnull; @@ -75,7 +75,7 @@ public interface IPocketAccess * @see #updateUpgradeNBTData() */ @Nonnull - NBTTagCompound getUpgradeNBTData(); + CompoundNBT getUpgradeNBTData(); /** * Mark the upgrade-specific NBT as dirty. diff --git a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java index ee98f9958..2b29fd695 100644 --- a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -6,7 +6,7 @@ package dan200.computercraft.api.redstone; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -30,5 +30,5 @@ public interface IBundledRedstoneProvider * handle this block. * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) */ - int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ); + int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ); } diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java index 1c29fd097..7d9b80721 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -11,8 +11,8 @@ import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.inventory.IInventory; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -83,10 +83,10 @@ public interface ITurtleAccess * Returns the world direction the turtle is currently facing. * * @return The world direction the turtle is currently facing. - * @see #setDirection(EnumFacing) + * @see #setDirection(Direction) */ @Nonnull - EnumFacing getDirection(); + Direction getDirection(); /** * Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to @@ -95,7 +95,7 @@ public interface ITurtleAccess * @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west). * @see #getDirection() */ - void setDirection( @Nonnull EnumFacing dir ); + void setDirection( @Nonnull Direction dir ); /** * Get the currently selected slot in the turtle's inventory. @@ -290,7 +290,7 @@ public interface ITurtleAccess * @see #updateUpgradeNBTData(TurtleSide) */ @Nonnull - NBTTagCompound getUpgradeNBTData( @Nullable TurtleSide side ); + CompoundNBT getUpgradeNBTData( @Nullable TurtleSide side ); /** * Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java index bfbe36a45..e36f9230a 100644 --- a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -13,7 +13,7 @@ import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -113,7 +113,7 @@ public interface ITurtleUpgrade * to be called. */ @Nonnull - default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction ) + default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction ) { return TurtleCommandResult.failure(); } diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java index 795513cc9..f9263e09d 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -6,7 +6,7 @@ package dan200.computercraft.api.turtle; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -15,7 +15,7 @@ import javax.annotation.Nullable; * Used to indicate the result of executing a turtle command. * * @see ITurtleCommand#execute(ITurtleAccess) - * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing) + * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction) */ public final class TurtleCommandResult { diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java index cf8e6b086..9110a5155 100644 --- a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java @@ -6,14 +6,14 @@ package dan200.computercraft.api.turtle; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; /** * An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by * a turtle. * * @see ITurtleUpgrade#getType() - * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing) + * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction) */ public enum TurtleVerb { diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java index de95a7d8f..65cb27793 100644 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java +++ b/src/main/java/dan200/computercraft/api/turtle/event/TurtleAttackEvent.java @@ -11,7 +11,7 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleVerb; import net.minecraft.entity.Entity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.entity.player.AttackEntityEvent; @@ -21,7 +21,7 @@ import java.util.Objects; /** * Fired when a turtle attempts to attack an entity. * - * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)}, + * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)}, * as the base {@code turtle.attack()} command does not fire it. * * Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both. diff --git a/src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java b/src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java index 036075795..930c90325 100644 --- a/src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java +++ b/src/main/java/dan200/computercraft/api/turtle/event/TurtleBlockEvent.java @@ -12,9 +12,9 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleVerb; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; @@ -75,7 +75,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent /** * Fired when a turtle attempts to dig a block. * - * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)}, + * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)}, * as the base {@code turtle.dig()} command does not fire it. * * Note that such commands should also fire {@link BlockEvent.BreakEvent}, so you do not need to listen to both. @@ -84,11 +84,11 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent */ public static class Dig extends TurtleBlockEvent { - private final IBlockState block; + private final BlockState block; private final ITurtleUpgrade upgrade; private final TurtleSide side; - public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side ) + public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side ) { super( turtle, TurtleAction.DIG, player, world, pos ); @@ -106,7 +106,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent * @return The block which is going to be broken. */ @Nonnull - public IBlockState getBlock() + public BlockState getBlock() { return block; } @@ -185,10 +185,10 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent */ public static class Inspect extends TurtleBlockEvent { - private final IBlockState state; + private final BlockState state; private final Map data; - public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Map data ) + public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Map data ) { super( turtle, TurtleAction.INSPECT, player, world, pos ); @@ -204,7 +204,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent * @return The inspected block state. */ @Nonnull - public IBlockState getState() + public BlockState getState() { return state; } diff --git a/src/main/java/dan200/computercraft/client/ClientRegistry.java b/src/main/java/dan200/computercraft/client/ClientRegistry.java index 48bd06443..d32af07ff 100644 --- a/src/main/java/dan200/computercraft/client/ClientRegistry.java +++ b/src/main/java/dan200/computercraft/client/ClientRegistry.java @@ -16,7 +16,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IUnbakedModel; import net.minecraft.client.renderer.model.ModelResourceLocation; -import net.minecraft.client.renderer.model.ModelRotation; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.resources.IResourceManager; import net.minecraft.util.ResourceLocation; @@ -25,6 +24,7 @@ import net.minecraftforge.client.event.ColorHandlerEvent; import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.client.model.BasicState; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -82,7 +82,7 @@ public final class ClientRegistry IResourceManager manager = Minecraft.getInstance().getResourceManager(); for( String extra : EXTRA_TEXTURES ) { - event.getMap().registerSprite( manager, new ResourceLocation( ComputerCraft.MOD_ID, extra ) ); + // TODO: event.getMap().registerSprite( manager, new ResourceLocation( ComputerCraft.MOD_ID, extra ) ); } } @@ -160,9 +160,9 @@ public final class ClientRegistry model.getTextures( loader::getUnbakedModel, new HashSet<>() ); return model.bake( - loader::getUnbakedModel, + loader, ModelLoader.defaultTextureGetter(), - ModelRotation.X0_Y0, false, DefaultVertexFormats.BLOCK + new BasicState( model.getDefaultState(), false ), DefaultVertexFormats.BLOCK ); } } diff --git a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java index 1445cd87d..888bf6ad3 100644 --- a/src/main/java/dan200/computercraft/client/ClientTableFormatter.java +++ b/src/main/java/dan200/computercraft/client/ClientTableFormatter.java @@ -12,8 +12,8 @@ import dan200.computercraft.shared.command.text.TableFormatter; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiNewChat; -import net.minecraft.client.gui.GuiUtilRenderComponents; +import net.minecraft.client.gui.NewChatGui; +import net.minecraft.client.gui.RenderComponentsUtil; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextFormatting; @@ -65,18 +65,18 @@ public class ClientTableFormatter implements TableFormatter public void writeLine( int id, ITextComponent component ) { Minecraft mc = Minecraft.getInstance(); - GuiNewChat chat = mc.ingameGUI.getChatGUI(); + NewChatGui chat = mc.field_71456_v.getChatGUI(); // ingameGUI // Trim the text if it goes over the allowed length int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() ); - List list = GuiUtilRenderComponents.splitText( component, maxWidth, mc.fontRenderer, false, false ); + List list = RenderComponentsUtil.splitText( component, maxWidth, mc.fontRenderer, false, false ); if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id ); } @Override public int display( TableBuilder table ) { - GuiNewChat chat = Minecraft.getInstance().ingameGUI.getChatGUI(); + NewChatGui chat = Minecraft.getInstance().field_71456_v.getChatGUI(); int lastHeight = lastHeights.get( table.getId() ); diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index b2e22db05..3903d1e32 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -6,11 +6,11 @@ package dan200.computercraft.client.gui; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; @@ -129,9 +129,9 @@ public final class FixedWidthFontRenderer } drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH, p, greyScale ); } - GlStateManager.disableTexture2D(); + GlStateManager.disableTexture(); tessellator.draw(); - GlStateManager.enableTexture2D(); + GlStateManager.enableTexture(); } public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale, Palette p ) @@ -195,6 +195,6 @@ public final class FixedWidthFontRenderer public void bindFont() { m_textureManager.bindTexture( FONT ); - GlStateManager.texParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP ); + GlStateManager.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP ); } } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java index 097c4c28e..f23162d81 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiComputer.java @@ -6,19 +6,22 @@ package dan200.computercraft.client.gui; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.ComputerCraft; import dan200.computercraft.client.gui.widgets.WidgetTerminal; import dan200.computercraft.client.gui.widgets.WidgetWrapper; import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.inventory.ContainerComputer; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.inventory.Container; +import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.Container; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; -public class GuiComputer extends GuiContainer +public class GuiComputer extends ContainerScreen { public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" ); public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" ); @@ -33,9 +36,12 @@ public class GuiComputer extends GuiContainer private WidgetTerminal terminal; private WidgetWrapper terminalWrapper; - public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight ) + public GuiComputer( + T container, PlayerInventory player, ITextComponent title, + ComputerFamily family, ClientComputer computer, int termWidth, int termHeight + ) { - super( container ); + super( container, player, title ); m_family = family; m_computer = computer; m_termWidth = termWidth; @@ -43,10 +49,10 @@ public class GuiComputer extends GuiContainer terminal = null; } - public GuiComputer( TileComputer computer ) + public static GuiComputer create( int id, TileComputer computer, PlayerInventory inventory, ITextComponent component ) { - this( - new ContainerComputer( computer ), + return new GuiComputer<>( + new ContainerComputer( id, computer ), inventory, component, computer.getFamily(), computer.createClientComputer(), ComputerCraft.terminalWidth_computer, @@ -55,9 +61,9 @@ public class GuiComputer extends GuiContainer } @Override - protected void initGui() + protected void init() { - mc.keyboardListener.enableRepeatEvents( true ); + minecraft.keyboardListener.enableRepeatEvents( true ); int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH; int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT; @@ -65,9 +71,9 @@ public class GuiComputer extends GuiContainer xSize = termPxWidth + 4 + 24; ySize = termPxHeight + 4 + 24; - super.initGui(); + super.init(); - terminal = new WidgetTerminal( mc, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 ); + terminal = new WidgetTerminal( minecraft, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 ); terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight ); children.add( terminalWrapper ); @@ -75,12 +81,12 @@ public class GuiComputer extends GuiContainer } @Override - public void onGuiClosed() + public void removed() { - super.onGuiClosed(); + super.removed(); children.remove( terminal ); terminal = null; - mc.keyboardListener.enableRepeatEvents( false ); + minecraft.keyboardListener.enableRepeatEvents( false ); } @Override @@ -108,32 +114,32 @@ public class GuiComputer extends GuiContainer { case Normal: default: - mc.getTextureManager().bindTexture( BACKGROUND_NORMAL ); + minecraft.getTextureManager().bindTexture( BACKGROUND_NORMAL ); break; case Advanced: - mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED ); + minecraft.getTextureManager().bindTexture( BACKGROUND_ADVANCED ); break; case Command: - mc.getTextureManager().bindTexture( BACKGROUND_COMMAND ); + minecraft.getTextureManager().bindTexture( BACKGROUND_COMMAND ); break; } - drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 ); - drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 12 ); - drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 ); - drawTexturedModalRect( endX, endY, 24, 40, 12, 12 ); + blit( startX - 12, startY - 12, 12, 28, 12, 12 ); + blit( startX - 12, endY, 12, 40, 12, 12 ); + blit( endX, startY - 12, 24, 28, 12, 12 ); + blit( endX, endY, 24, 40, 12, 12 ); - drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 ); - drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 12 ); + blit( startX, startY - 12, 0, 0, endX - startX, 12 ); + blit( startX, endY, 0, 12, endX - startX, 12 ); - drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY ); - drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY ); + blit( startX - 12, startY, 0, 28, 12, endY - startY ); + blit( endX, startY, 36, 28, 12, endY - startY ); } @Override public void render( int mouseX, int mouseY, float partialTicks ) { - drawDefaultBackground(); + renderBackground(); super.render( mouseX, mouseY, partialTicks ); renderHoveredToolTip( mouseX, mouseY ); } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java index ab4284839..c3cc55347 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java @@ -6,44 +6,42 @@ package dan200.computercraft.client.gui; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.resources.I18n; +import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; -public class GuiDiskDrive extends GuiContainer +public class GuiDiskDrive extends ContainerScreen { private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" ); - private final ContainerDiskDrive m_container; - - public GuiDiskDrive( ContainerDiskDrive container ) + public GuiDiskDrive( ContainerDiskDrive container, PlayerInventory player, ITextComponent title ) { - super( container ); - m_container = container; + super( container, player, title ); } @Override protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) { - String title = m_container.getDiskDrive().getDisplayName().getString(); - fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 ); - fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 ); + String title = this.title.getFormattedText(); + font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 ); + font.drawString( title, 8, ySize - 96 + 2, 0x404040 ); } @Override protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) { GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); - mc.getTextureManager().bindTexture( BACKGROUND ); - drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); + minecraft.getTextureManager().bindTexture( BACKGROUND ); + blit( guiLeft, guiTop, 0, 0, xSize, ySize ); } @Override public void render( int mouseX, int mouseY, float partialTicks ) { - drawDefaultBackground(); + renderBackground(); super.render( mouseX, mouseY, partialTicks ); renderHoveredToolTip( mouseX, mouseY ); } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java b/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java index e3781ae96..a075e1d5f 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPocketComputer.java @@ -10,15 +10,17 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; -public class GuiPocketComputer extends GuiComputer +public class GuiPocketComputer extends GuiComputer { - public GuiPocketComputer( ContainerPocketComputer container ) + public GuiPocketComputer( ContainerPocketComputer container, PlayerInventory player, ITextComponent title ) { super( - container, + container, player, title, getFamily( container.getStack() ), ItemPocketComputer.createClientComputer( container.getStack() ), ComputerCraft.terminalWidth_pocketComputer, diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java index 80e146f52..e00387d4d 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java @@ -6,46 +6,45 @@ package dan200.computercraft.client.gui; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; -public class GuiPrinter extends GuiContainer +public class GuiPrinter extends ContainerScreen { private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" ); - private final ContainerPrinter container; - - public GuiPrinter( ContainerPrinter container ) + public GuiPrinter( ContainerPrinter container, PlayerInventory player, ITextComponent title ) { - super( container ); - this.container = container; + super( container, player, title ); } @Override protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) { - String title = container.getPrinter().getDisplayName().getString(); - fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 ); - fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 ); + 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 ); } @Override protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) { GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); - mc.getTextureManager().bindTexture( BACKGROUND ); - drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); + minecraft.getTextureManager().bindTexture( BACKGROUND ); + blit( guiLeft, guiTop, 0, 0, xSize, ySize ); - if( container.isPrinting() ) drawTexturedModalRect( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 ); + if( getContainer().isPrinting() ) blit( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 ); } @Override public void render( int mouseX, int mouseY, float partialTicks ) { - drawDefaultBackground(); + renderBackground(); super.render( mouseX, mouseY, partialTicks ); renderHoveredToolTip( 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 f1349bc74..c4dd204f7 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrintout.java @@ -6,16 +6,18 @@ package dan200.computercraft.client.gui; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.media.items.ItemPrintout; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.util.text.ITextComponent; import org.lwjgl.glfw.GLFW; import static dan200.computercraft.client.render.PrintoutRenderer.*; -public class GuiPrintout extends GuiContainer +public class GuiPrintout extends ContainerScreen { private final boolean m_book; private final int m_pages; @@ -23,9 +25,9 @@ public class GuiPrintout extends GuiContainer private final TextBuffer[] m_colours; private int m_page; - public GuiPrintout( ContainerHeldItem container ) + public GuiPrintout( ContainerHeldItem container, PlayerInventory player, ITextComponent title ) { - super( container ); + super( container, player, title ); ySize = Y_SIZE; @@ -63,9 +65,9 @@ public class GuiPrintout extends GuiContainer } @Override - public boolean mouseScrolled( double delta ) + public boolean mouseScrolled( double x, double y, double delta ) { - if( super.mouseScrolled( delta ) ) return true; + if( super.mouseScrolled( x, y, delta ) ) return true; if( delta < 0 ) { // Scroll up goes to the next page @@ -90,7 +92,7 @@ public class GuiPrintout extends GuiContainer GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); GlStateManager.enableDepthTest(); - drawBorder( guiLeft, guiTop, zLevel, m_page, m_pages, m_book ); + drawBorder( guiLeft, guiTop, blitOffset, m_page, m_pages, m_book ); drawText( guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours ); } @@ -98,9 +100,9 @@ public class GuiPrintout extends GuiContainer public void render( int mouseX, int mouseY, float partialTicks ) { // We must take the background further back in order to not overlap with our printed pages. - zLevel--; - drawDefaultBackground(); - zLevel++; + blitOffset--; + renderBackground(); + blitOffset++; super.render( mouseX, mouseY, partialTicks ); renderHoveredToolTip( 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 496d8b576..cdbdd28b9 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiTurtle.java @@ -6,6 +6,7 @@ package dan200.computercraft.client.gui; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.ComputerCraft; import dan200.computercraft.client.gui.widgets.WidgetTerminal; import dan200.computercraft.client.gui.widgets.WidgetWrapper; @@ -13,11 +14,12 @@ import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.gui.screen.inventory.ContainerScreen; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; -public class GuiTurtle extends GuiContainer +public class GuiTurtle extends ContainerScreen { private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" ); private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" ); @@ -30,9 +32,9 @@ public class GuiTurtle extends GuiContainer private WidgetTerminal terminal; private WidgetWrapper terminalWrapper; - public GuiTurtle( TileTurtle turtle, ContainerTurtle container ) + public GuiTurtle( TileTurtle turtle, ContainerTurtle container, PlayerInventory player, ITextComponent title ) { - super( container ); + super( container, player, title ); m_container = container; m_family = turtle.getFamily(); @@ -43,16 +45,16 @@ public class GuiTurtle extends GuiContainer } @Override - protected void initGui() + protected void init() { - super.initGui(); - mc.keyboardListener.enableRepeatEvents( true ); + super.init(); + minecraft.keyboardListener.enableRepeatEvents( true ); int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH; int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT; terminal = new WidgetTerminal( - mc, () -> m_computer, + minecraft, () -> m_computer, ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalHeight_turtle, 2, 2, 2, 2 @@ -64,11 +66,12 @@ public class GuiTurtle extends GuiContainer } @Override - public void onGuiClosed() + public void removed() { + super.removed(); children.remove( terminal ); terminal = null; - mc.keyboardListener.enableRepeatEvents( false ); + minecraft.keyboardListener.enableRepeatEvents( false ); } @Override @@ -87,8 +90,8 @@ public class GuiTurtle extends GuiContainer GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); int slotX = slot % 4; int slotY = slot / 4; - mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); - drawTexturedModalRect( guiLeft + m_container.turtleInvStartX - 2 + slotX * 18, guiTop + m_container.playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 ); + 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 ); } } @@ -101,8 +104,8 @@ public class GuiTurtle extends GuiContainer // Draw border/inventory GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); - mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); - drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); + minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); + blit( guiLeft, guiTop, 0, 0, xSize, ySize ); drawSelectionSlot( advanced ); } @@ -110,7 +113,7 @@ public class GuiTurtle extends GuiContainer @Override public void render( int mouseX, int mouseY, float partialTicks ) { - drawDefaultBackground(); + renderBackground(); super.render( mouseX, mouseY, partialTicks ); renderHoveredToolTip( mouseX, mouseY ); } 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 3f75ccbe3..72640661e 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetTerminal.java @@ -6,6 +6,7 @@ package dan200.computercraft.client.gui.widgets; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.Terminal; @@ -17,7 +18,6 @@ import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.IGuiEventListener; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.SharedConstants; @@ -35,6 +35,8 @@ public class WidgetTerminal implements IGuiEventListener private final Minecraft client; + private boolean focused; + private final Supplier computer; private final int termWidth; private final int termHeight; @@ -250,14 +252,23 @@ public class WidgetTerminal implements IGuiEventListener } @Override - public boolean mouseScrolled( double delta ) + public boolean mouseScrolled( double mouseX, double mouseY, double delta ) { ClientComputer computer = this.computer.get(); - if( computer == null || !computer.isColour() ) return false; + if( computer == null || !computer.isColour() || delta == 0 ) return false; - if( lastMouseX >= 0 && lastMouseY >= 0 && delta != 0 ) + Terminal term = computer.getTerminal(); + if( term != null ) { - queueEvent( "mouse_scroll", delta < 0 ? 1 : -1, lastMouseX + 1, lastMouseY + 1 ); + int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH); + int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT); + charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 ); + charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 ); + + computer.mouseScroll( delta < 0 ? 1 : -1, charX + 1, charY + 1 ); + + lastMouseX = charX; + lastMouseY = charY; } return true; @@ -284,9 +295,9 @@ public class WidgetTerminal implements IGuiEventListener } @Override - public void focusChanged( boolean focused ) + public boolean changeFocus( boolean reversed ) { - if( !focused ) + if( focused ) { // When blurring, we should make all keys go up for( int key = 0; key < keysDown.size(); key++ ) @@ -305,6 +316,8 @@ public class WidgetTerminal implements IGuiEventListener shutdownTimer = terminateTimer = rebootTimer = -1; } + focused = !focused; + return true; } public void draw( int originX, int originY ) diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetWrapper.java b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetWrapper.java index b657983a0..fed1e086b 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/WidgetWrapper.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/WidgetWrapper.java @@ -26,15 +26,9 @@ public class WidgetWrapper implements IGuiEventListener } @Override - public void focusChanged( boolean b ) + public boolean changeFocus( boolean b ) { - listener.focusChanged( b ); - } - - @Override - public boolean canFocus() - { - return listener.canFocus(); + return listener.changeFocus( b ); } @Override @@ -59,9 +53,9 @@ public class WidgetWrapper implements IGuiEventListener } @Override - public boolean mouseScrolled( double delta ) + public boolean mouseScrolled( double x, double y, double delta ) { - return listener.mouseScrolled( delta ); + return listener.mouseScrolled( x, y, delta ); } @Override diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 39a6ccbb8..28f2affbc 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -7,33 +7,29 @@ package dan200.computercraft.client.proxy; import dan200.computercraft.ComputerCraft; -import dan200.computercraft.client.gui.*; +import dan200.computercraft.client.gui.GuiDiskDrive; +import dan200.computercraft.client.gui.GuiPocketComputer; +import dan200.computercraft.client.gui.GuiPrinter; +import dan200.computercraft.client.gui.GuiPrintout; import dan200.computercraft.client.render.TileEntityCableRenderer; import dan200.computercraft.client.render.TileEntityMonitorRenderer; import dan200.computercraft.client.render.TileEntityTurtleRenderer; -import dan200.computercraft.shared.computer.blocks.TileComputer; -import dan200.computercraft.shared.computer.core.ClientComputer; -import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; -import dan200.computercraft.shared.network.container.*; +import dan200.computercraft.shared.common.ContainerHeldItem; +import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; import dan200.computercraft.shared.peripheral.modem.wired.TileCable; import dan200.computercraft.shared.peripheral.monitor.ClientMonitor; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; +import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; +import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import dan200.computercraft.shared.turtle.blocks.TileTurtle; -import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.client.gui.ScreenManager; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ExtensionPoint; -import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import java.util.function.BiFunction; - @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD ) public final class ComputerCraftProxyClient { @@ -50,35 +46,11 @@ public final class ComputerCraftProxyClient private static void registerContainers() { - ContainerType.registerGui( TileEntityContainerType::computer, ( packet, player ) -> - new GuiComputer( (TileComputer) packet.getTileEntity( player ) ) ); - ContainerType.registerGui( TileEntityContainerType::diskDrive, GuiDiskDrive::new ); - ContainerType.registerGui( TileEntityContainerType::printer, GuiPrinter::new ); - ContainerType.registerGui( TileEntityContainerType::turtle, ( packet, player ) -> { - TileTurtle turtle = (TileTurtle) packet.getTileEntity( player ); - return new GuiTurtle( turtle, new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getClientComputer() ) ); - } ); - - ContainerType.registerGui( PocketComputerContainerType::new, GuiPocketComputer::new ); - ContainerType.registerGui( PrintoutContainerType::new, GuiPrintout::new ); - ContainerType.registerGui( ViewComputerContainerType::new, ( packet, player ) -> { - ClientComputer computer = ComputerCraft.clientComputerRegistry.get( packet.instanceId ); - if( computer == null ) - { - ComputerCraft.clientComputerRegistry.add( packet.instanceId, computer = new ClientComputer( packet.instanceId ) ); - } - - ContainerViewComputer container = new ContainerViewComputer( computer ); - return new GuiComputer( container, packet.family, computer, packet.width, packet.height ); - } ); - - ModLoadingContext.get().registerExtensionPoint( ExtensionPoint.GUIFACTORY, () -> packet -> { - ContainerType type = ContainerType.factories.get( packet.getId() ).get(); - if( packet.getAdditionalData() != null ) type.fromBytes( packet.getAdditionalData() ); - @SuppressWarnings( "unchecked" ) - BiFunction, EntityPlayer, GuiContainer> factory = (BiFunction, EntityPlayer, GuiContainer>) ContainerType.guiFactories.get( packet.getId() ); - return factory.apply( type, Minecraft.getInstance().player ); - } ); + ScreenManager.registerFactory( ContainerPrinter.TYPE, GuiPrinter::new ); + ScreenManager.registerFactory( ContainerDiskDrive.TYPE, GuiDiskDrive::new ); + ScreenManager.registerFactory( ContainerPocketComputer.TYPE, GuiPocketComputer::new ); + ScreenManager.registerFactory( ContainerHeldItem.PRINTOUT_TYPE, GuiPrintout::new ); + // TODO: ScreenManager.registerFactory( ContainerViewComputer.TYPE, GuiComputer::new ); } @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT ) diff --git a/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java b/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java index b6f06fd35..f298a722b 100644 --- a/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/CableHighlightRenderer.java @@ -6,17 +6,20 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.peripheral.modem.wired.BlockCable; import dan200.computercraft.shared.peripheral.modem.wired.CableShapes; import dan200.computercraft.shared.util.WorldUtil; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; @@ -36,17 +39,19 @@ public final class CableHighlightRenderer * Draw an outline for a specific part of a cable "Multipart". * * @param event The event to observe - * @see WorldRenderer#drawSelectionBox(EntityPlayer, RayTraceResult, int, float) + * @see WorldRenderer#drawSelectionBox(PlayerEntity, RayTraceResult, int, float) */ @SubscribeEvent public static void drawHighlight( DrawBlockHighlightEvent event ) { - if( event.getTarget().type != RayTraceResult.Type.BLOCK ) return; + if( event.getTarget().getType() != RayTraceResult.Type.BLOCK ) return; - BlockPos pos = event.getTarget().getBlockPos(); - World world = event.getPlayer().getEntityWorld(); + BlockRayTraceResult hit = (BlockRayTraceResult) event.getTarget(); + BlockPos pos = hit.getPos(); + World world = event.getInfo().func_216773_g().getEntityWorld(); + ActiveRenderInfo info = event.getInfo(); - IBlockState state = world.getBlockState( pos ); + BlockState state = world.getBlockState( pos ); // We only care about instances with both cable and modem. if( state.getBlock() != ComputerCraft.Blocks.cable || state.get( BlockCable.MODEM ).getFacing() == null || !state.get( BlockCable.CABLE ) ) @@ -56,33 +61,31 @@ public final class CableHighlightRenderer event.setCanceled( true ); - EntityPlayer player = event.getPlayer(); Minecraft mc = Minecraft.getInstance(); - float partialTicks = event.getPartialTicks(); GlStateManager.enableBlend(); GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO ); GlStateManager.lineWidth( Math.max( 2.5F, mc.mainWindow.getFramebufferWidth() / 1920.0F * 2.5F ) ); - GlStateManager.disableTexture2D(); + GlStateManager.disableTexture(); GlStateManager.depthMask( false ); GlStateManager.matrixMode( GL11.GL_PROJECTION ); GlStateManager.pushMatrix(); GlStateManager.scalef( 1.0F, 1.0F, 0.999F ); - double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks; - double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks; - double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks; - - VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), event.getTarget().hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) + VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ? CableShapes.getModemShape( state ) : CableShapes.getCableShape( state ); - WorldRenderer.drawShape( shape, pos.getX() - x, pos.getY() - y, pos.getZ() - z, 0.0F, 0.0F, 0.0F, 0.4F ); + Vec3d cameraPos = info.func_216785_c(); + WorldRenderer.drawShape( + shape, pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ(), + 0.0F, 0.0F, 0.0F, 0.4F + ); GlStateManager.popMatrix(); GlStateManager.matrixMode( GL11.GL_MODELVIEW ); GlStateManager.depthMask( true ); - GlStateManager.enableTexture2D(); + GlStateManager.enableTexture(); GlStateManager.disableBlend(); } } diff --git a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java index a9226a71e..7d30dac00 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java @@ -6,13 +6,13 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.FirstPersonRenderer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumHand; -import net.minecraft.util.EnumHandSide; +import net.minecraft.util.Hand; +import net.minecraft.util.HandSide; import net.minecraft.util.math.MathHelper; public abstract class ItemMapLikeRenderer @@ -25,19 +25,19 @@ public abstract class ItemMapLikeRenderer */ protected abstract void renderItem( ItemStack stack ); - protected void renderItemFirstPerson( EnumHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack ) + protected void renderItemFirstPerson( Hand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack ) { - EntityPlayer player = Minecraft.getInstance().player; + PlayerEntity player = Minecraft.getInstance().player; GlStateManager.pushMatrix(); - if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() ) + if( hand == Hand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() ) { renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack ); } else { renderItemFirstPersonSide( - hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(), + hand == Hand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(), equipProgress, swingProgress, stack ); } @@ -51,12 +51,12 @@ public abstract class ItemMapLikeRenderer * @param equipProgress The equip progress of this item * @param swingProgress The swing progress of this item * @param stack The stack to render - * @see FirstPersonRenderer#renderMapFirstPersonSide(float, EnumHandSide, float, ItemStack) + * @see FirstPersonRenderer#renderMapFirstPersonSide(float, HandSide, float, ItemStack) */ - private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack ) + private void renderItemFirstPersonSide( HandSide side, float equipProgress, float swingProgress, ItemStack stack ) { Minecraft minecraft = Minecraft.getInstance(); - float offset = side == EnumHandSide.RIGHT ? 1f : -1f; + float offset = side == HandSide.RIGHT ? 1f : -1f; GlStateManager.translatef( offset * 0.125f, -0.125f, 0f ); // If the player is not invisible then render a single arm diff --git a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java index de244a726..6c4e57597 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPocketRenderer.java @@ -6,6 +6,7 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.ComputerCraft; import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.gui.FixedWidthFontRenderer; @@ -18,7 +19,6 @@ import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.item.ItemStack; @@ -173,7 +173,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer private static void renderLight( int colour, int width, int height ) { GlStateManager.enableBlend(); - GlStateManager.disableTexture2D(); + GlStateManager.disableTexture(); float r = ((colour >>> 16) & 0xFF) / 255.0f; float g = ((colour >>> 8) & 0xFF) / 255.0f; @@ -188,7 +188,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer buffer.pos( width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex(); tessellator.draw(); - GlStateManager.enableTexture2D(); + GlStateManager.enableTexture(); } private static void renderTerminal( Terminal terminal, boolean greyscale, int width, int height ) diff --git a/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java index ab8eb2670..35bd7e047 100644 --- a/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/ItemPrintoutRenderer.java @@ -6,9 +6,9 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.media.items.ItemPrintout; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderItemInFrameEvent; diff --git a/src/main/java/dan200/computercraft/client/render/ModelTransformer.java b/src/main/java/dan200/computercraft/client/render/ModelTransformer.java index 539af8cfb..1a794d64f 100644 --- a/src/main/java/dan200/computercraft/client/render/ModelTransformer.java +++ b/src/main/java/dan200/computercraft/client/render/ModelTransformer.java @@ -9,7 +9,7 @@ package dan200.computercraft.client.render; import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraftforge.client.model.pipeline.IVertexConsumer; import net.minecraftforge.client.model.pipeline.LightUtil; import net.minecraftforge.client.model.pipeline.VertexTransformer; @@ -102,7 +102,7 @@ public final class ModelTransformer } @Override - public void setQuadOrientation( @Nonnull EnumFacing orientation ) + public void setQuadOrientation( @Nonnull Direction orientation ) { super.setQuadOrientation( orientation == null ? orientation : TRSRTransformation.rotate( positionMatrix, orientation ) ); } @@ -187,7 +187,7 @@ public final class ModelTransformer private final int[] vertexData; private int vertexIndex = 0, elementIndex = 0; - private EnumFacing orientation; + private Direction orientation; private int quadTint; private boolean diffuse; private TextureAtlasSprite texture; @@ -212,7 +212,7 @@ public final class ModelTransformer } @Override - public void setQuadOrientation( @Nonnull EnumFacing orientation ) + public void setQuadOrientation( @Nonnull Direction orientation ) { this.orientation = orientation; } diff --git a/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java b/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java index f5eee7ba8..8e313bb5a 100644 --- a/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/MonitorHighlightRenderer.java @@ -6,18 +6,19 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.DrawBlockHighlightEvent; @@ -27,7 +28,7 @@ import org.lwjgl.opengl.GL11; import java.util.EnumSet; -import static net.minecraft.util.EnumFacing.*; +import static net.minecraft.util.Direction.*; @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT ) public final class MonitorHighlightRenderer @@ -41,10 +42,13 @@ public final class MonitorHighlightRenderer @SubscribeEvent public static void drawHighlight( DrawBlockHighlightEvent event ) { - if( event.getTarget().type != RayTraceResult.Type.BLOCK || event.getPlayer().isSneaking() ) return; + if( event.getTarget().getType() != RayTraceResult.Type.BLOCK || event.getInfo().func_216773_g().isSneaking() ) + { + return; + } - World world = event.getPlayer().getEntityWorld(); - BlockPos pos = event.getTarget().getBlockPos(); + World world = event.getInfo().func_216773_g().getEntityWorld(); + BlockPos pos = ((BlockRayTraceResult) event.getTarget()).getPos(); TileEntity tile = world.getTileEntity( pos ); if( !(tile instanceof TileMonitor) ) return; @@ -53,8 +57,8 @@ public final class MonitorHighlightRenderer event.setCanceled( true ); // Determine which sides are part of the external faces of the monitor, and so which need to be rendered. - EnumSet faces = EnumSet.allOf( EnumFacing.class ); - EnumFacing front = monitor.getFront(); + EnumSet faces = EnumSet.allOf( Direction.class ); + Direction front = monitor.getFront(); faces.remove( front ); if( monitor.getXIndex() != 0 ) faces.remove( monitor.getRight().getOpposite() ); if( monitor.getXIndex() != monitor.getWidth() - 1 ) faces.remove( monitor.getRight() ); @@ -64,16 +68,12 @@ public final class MonitorHighlightRenderer GlStateManager.enableBlend(); GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO ); GlStateManager.lineWidth( Math.max( 2.5F, (float) Minecraft.getInstance().mainWindow.getFramebufferWidth() / 1920.0F * 2.5F ) ); - GlStateManager.disableTexture2D(); + GlStateManager.disableTexture(); GlStateManager.depthMask( false ); GlStateManager.pushMatrix(); - EntityPlayer player = event.getPlayer(); - double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks(); - double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks(); - double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks(); - - GlStateManager.translated( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() ); + Vec3d cameraPos = event.getInfo().func_216785_c(); + GlStateManager.translated( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() ); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); @@ -97,11 +97,11 @@ public final class MonitorHighlightRenderer GlStateManager.popMatrix(); GlStateManager.depthMask( true ); - GlStateManager.enableTexture2D(); + GlStateManager.enableTexture(); GlStateManager.disableBlend(); } - private static void line( BufferBuilder buffer, int x, int y, int z, EnumFacing direction ) + private static void line( BufferBuilder buffer, int x, int y, int z, Direction direction ) { double minX = x == 0 ? -EXPAND : 1 + EXPAND; double minY = y == 0 ? -EXPAND : 1 + EXPAND; diff --git a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java index 07e9af310..404a7f9b5 100644 --- a/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/PrintoutRenderer.java @@ -6,14 +6,14 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.platform.GlStateManager.DestFactor; +import com.mojang.blaze3d.platform.GlStateManager.SourceFactor; import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.GlStateManager.DestFactor; -import net.minecraft.client.renderer.GlStateManager.SourceFactor; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; @@ -76,7 +76,7 @@ public final class PrintoutRenderer { GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); GlStateManager.enableBlend(); - GlStateManager.enableTexture2D(); + GlStateManager.enableTexture(); GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO ); FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance(); @@ -91,7 +91,7 @@ public final class PrintoutRenderer { GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); GlStateManager.enableBlend(); - GlStateManager.enableTexture2D(); + GlStateManager.enableTexture(); GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO ); Minecraft.getInstance().getTextureManager().bindTexture( BG ); diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityCableRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityCableRenderer.java index efc46e40e..a6d7e6027 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityCableRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityCableRenderer.java @@ -6,6 +6,7 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.peripheral.modem.wired.BlockCable; import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant; @@ -13,10 +14,9 @@ import dan200.computercraft.shared.peripheral.modem.wired.CableShapes; import dan200.computercraft.shared.peripheral.modem.wired.TileCable; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.model.IBakedModel; @@ -25,10 +25,10 @@ import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.World; import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.model.data.EmptyModelData; import org.lwjgl.opengl.GL11; @@ -52,16 +52,19 @@ public class TileEntityCableRenderer extends TileEntityRenderer Minecraft mc = Minecraft.getInstance(); RayTraceResult hit = mc.objectMouseOver; - if( hit == null || !hit.getBlockPos().equals( pos ) ) return; + if( hit == null || hit.getType() != RayTraceResult.Type.BLOCK || !((BlockRayTraceResult) hit).getPos().equals( pos ) ) + { + return; + } - if( MinecraftForgeClient.getRenderPass() != 0 ) return; + if( ForgeHooksClient.getWorldRenderPass() != 0 ) return; World world = te.getWorld(); - IBlockState state = world.getBlockState( pos ); + BlockState state = world.getBlockState( pos ); Block block = state.getBlock(); if( block != ComputerCraft.Blocks.cable ) return; - state = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) + state = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ? block.getDefaultState().with( BlockCable.MODEM, state.get( BlockCable.MODEM ) ) : state.with( BlockCable.MODEM, CableModemVariant.None ); @@ -80,7 +83,7 @@ public class TileEntityCableRenderer extends TileEntityRenderer TextureAtlasSprite breakingTexture = mc.getTextureMap().getSprite( DESTROY_STAGES[destroyStage] ); mc.getBlockRendererDispatcher().getBlockModelRenderer().renderModel( world, - ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos ), + ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos, 0 ), state, pos, buffer, true, random, state.getPositionRandom( pos ), EmptyModelData.INSTANCE ); diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 3ac9ce6fa..211324e5f 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -6,6 +6,8 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GLX; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.core.terminal.Terminal; @@ -17,12 +19,10 @@ import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import org.lwjgl.opengl.GL11; @@ -64,8 +64,8 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer posZ += originPos.getZ() - monitorPos.getZ(); // Determine orientation - EnumFacing dir = origin.getDirection(); - EnumFacing front = origin.getFront(); + Direction dir = origin.getDirection(); + Direction front = origin.getFront(); float yaw = dir.getHorizontalAngle(); float pitch = DirectionUtil.toPitchAngle( front ); @@ -94,7 +94,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer // Draw the contents GlStateManager.depthMask( false ); - OpenGlHelper.glMultiTexCoord2f( OpenGlHelper.GL_TEXTURE1, 0xFFFF, 0xFFFF ); + GLX.glMultiTexCoord2f( GLX.GL_TEXTURE1, 0xFFFF, 0xFFFF ); GlStateManager.disableLighting(); mc.gameRenderer.disableLightmap(); try @@ -171,7 +171,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer } } GlStateManager.callList( originTerminal.renderDisplayLists[0] ); - GlStateManager.resetColor(); + GlStateManager.clearCurrentColor(); // Draw text fontRenderer.bindFont(); @@ -199,7 +199,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer } } GlStateManager.callList( originTerminal.renderDisplayLists[1] ); - GlStateManager.resetColor(); + GlStateManager.clearCurrentColor(); // Draw cursor fontRenderer.bindFont(); @@ -233,7 +233,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer if( FrameInfo.getGlobalCursorBlink() ) { GlStateManager.callList( originTerminal.renderDisplayLists[2] ); - GlStateManager.resetColor(); + GlStateManager.clearCurrentColor(); } } finally diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java index 9460e0e88..f7f77076b 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityTurtleRenderer.java @@ -6,6 +6,7 @@ package dan200.computercraft.client.render; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.shared.computer.core.ComputerFamily; @@ -13,22 +14,23 @@ import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.Holiday; import dan200.computercraft.shared.util.HolidayUtil; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ModelManager; import net.minecraft.client.renderer.model.ModelResourceLocation; -import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.model.data.EmptyModelData; @@ -85,13 +87,15 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer { // Render the label String label = turtle.createProxy().getLabel(); - if( label != null && rendererDispatcher.cameraHitResult != null && turtle.getPos().equals( rendererDispatcher.cameraHitResult.getBlockPos() ) ) + RayTraceResult hit = rendererDispatcher.cameraHitResult; + if( label != null && hit.getType() == RayTraceResult.Type.BLOCK && turtle.getPos().equals( ((BlockRayTraceResult) hit).getPos() ) ) { setLightmapDisabled( true ); - GameRenderer.drawNameplate( + GameRenderer.func_215307_a( getFontRenderer(), label, (float) posX + 0.5F, (float) posY + 1.2F, (float) posZ + 0.5F, 0, - rendererDispatcher.entityYaw, rendererDispatcher.entityPitch, false, false + rendererDispatcher.field_217666_g.func_216778_f(), rendererDispatcher.field_217666_g.func_216777_e(), false + // yaw, pitch ); setLightmapDisabled( false ); } @@ -99,7 +103,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer GlStateManager.pushMatrix(); try { - IBlockState state = turtle.getBlockState(); + BlockState state = turtle.getBlockState(); // Setup the transform Vec3d offset = turtle.getRenderOffset( partialTicks ); float yaw = turtle.getRenderYaw( partialTicks ); @@ -153,7 +157,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer } } - private void renderUpgrade( IBlockState state, TileTurtle turtle, TurtleSide side, float f ) + private void renderUpgrade( BlockState state, TileTurtle turtle, TurtleSide side, float f ) { ITurtleUpgrade upgrade = turtle.getUpgrade( side ); if( upgrade != null ) @@ -186,20 +190,20 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer } } - private void renderModel( IBlockState state, ModelResourceLocation modelLocation, int[] tints ) + private void renderModel( BlockState state, ModelResourceLocation modelLocation, int[] tints ) { Minecraft mc = Minecraft.getInstance(); ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager(); renderModel( state, modelManager.getModel( modelLocation ), tints ); } - private void renderModel( IBlockState state, IBakedModel model, int[] tints ) + private void renderModel( BlockState state, IBakedModel model, int[] tints ) { Random random = new Random( 0 ); Tessellator tessellator = Tessellator.getInstance(); - rendererDispatcher.textureManager.bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE ); + rendererDispatcher.textureManager.bindTexture( AtlasTexture.LOCATION_BLOCKS_TEXTURE ); renderQuads( tessellator, model.getQuads( state, null, random, EmptyModelData.INSTANCE ), tints ); - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { renderQuads( tessellator, model.getQuads( state, facing, random, EmptyModelData.INSTANCE ), tints ); } diff --git a/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java b/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java index 42ea8eedf..20a027348 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java +++ b/src/main/java/dan200/computercraft/client/render/TurtleModelLoader.java @@ -9,15 +9,15 @@ package dan200.computercraft.client.render; import dan200.computercraft.ComputerCraft; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IUnbakedModel; +import net.minecraft.client.renderer.model.ModelBakery; +import net.minecraft.client.renderer.texture.ISprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.resources.IResourceManager; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ICustomModelLoader; -import net.minecraftforge.common.model.IModelState; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.Arrays; import java.util.Collection; import java.util.Set; @@ -91,13 +91,13 @@ public final class TurtleModelLoader implements ICustomModelLoader .collect( Collectors.toSet() ); } - @Nullable + @Nonnull @Override - public IBakedModel bake( @Nonnull Function modelGetter, @Nonnull Function spriteGetter, @Nonnull IModelState state, boolean uvlock, @Nonnull VertexFormat format ) + public IBakedModel bake( @Nonnull ModelBakery bakery, @Nonnull Function spriteGetter, @Nonnull ISprite sprite, @Nonnull VertexFormat format ) { return new TurtleSmartItemModel( - modelGetter.apply( family ).bake( modelGetter, spriteGetter, state, uvlock, format ), - modelGetter.apply( COLOUR_TURTLE_MODEL ).bake( modelGetter, spriteGetter, state, uvlock, format ) + bakery.getBakedModel( family, sprite, spriteGetter, format ), + bakery.getBakedModel( COLOUR_TURTLE_MODEL, sprite, spriteGetter, format ) ); } } diff --git a/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java b/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java index 9834eb08c..7014b8368 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java +++ b/src/main/java/dan200/computercraft/client/render/TurtleMultiModel.java @@ -6,12 +6,12 @@ package dan200.computercraft.client.render; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ItemOverrideList; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraftforge.client.model.data.EmptyModelData; import net.minecraftforge.client.model.data.IModelData; @@ -29,7 +29,7 @@ public class TurtleMultiModel implements IBakedModel private final IBakedModel m_rightUpgradeModel; private final Matrix4f m_rightUpgradeTransform; private List m_generalQuads = null; - private Map> m_faceQuads = new EnumMap<>( EnumFacing.class ); + private Map> m_faceQuads = new EnumMap<>( Direction.class ); public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, Matrix4f generalTransform, IBakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, IBakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform ) { @@ -46,14 +46,14 @@ public class TurtleMultiModel implements IBakedModel @Nonnull @Override @Deprecated - public List getQuads( IBlockState state, EnumFacing side, @Nonnull Random rand ) + public List getQuads( BlockState state, Direction side, @Nonnull Random rand ) { return getQuads( state, side, rand, EmptyModelData.INSTANCE ); } @Nonnull @Override - public List getQuads( IBlockState state, EnumFacing side, @Nonnull Random rand, @Nonnull IModelData data ) + public List getQuads( BlockState state, Direction side, @Nonnull Random rand, @Nonnull IModelData data ) { if( side != null ) { @@ -67,7 +67,7 @@ public class TurtleMultiModel implements IBakedModel } } - private List buildQuads( IBlockState state, EnumFacing side, Random rand ) + private List buildQuads( BlockState state, Direction side, Random rand ) { ArrayList quads = new ArrayList<>(); ModelTransformer.transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform ); diff --git a/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java b/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java index ecd5dae7e..7c24c7f55 100644 --- a/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java +++ b/src/main/java/dan200/computercraft/client/render/TurtleSmartItemModel.java @@ -12,13 +12,13 @@ import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.shared.turtle.items.ItemTurtle; import dan200.computercraft.shared.util.Holiday; import dan200.computercraft.shared.util.HolidayUtil; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.model.data.IModelData; @@ -111,7 +111,7 @@ public class TurtleSmartItemModel implements IBakedModel { @Nonnull @Override - public IBakedModel getModelWithOverrides( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity ) + public IBakedModel getModelWithOverrides( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable LivingEntity entity ) { ItemTurtle turtle = (ItemTurtle) stack.getItem(); int colour = turtle.getColour( stack ); @@ -169,7 +169,7 @@ public class TurtleSmartItemModel implements IBakedModel @Nonnull @Override @Deprecated - public List getQuads( IBlockState state, EnumFacing facing, @Nonnull Random rand ) + public List getQuads( BlockState state, Direction facing, @Nonnull Random rand ) { return familyModel.getQuads( state, facing, rand ); } @@ -177,7 +177,7 @@ public class TurtleSmartItemModel implements IBakedModel @Nonnull @Override @Deprecated - public List getQuads( IBlockState state, EnumFacing facing, @Nonnull Random rand, @Nonnull IModelData data ) + public List getQuads( BlockState state, Direction facing, @Nonnull Random rand, @Nonnull IModelData data ) { return familyModel.getQuads( state, facing, rand, data ); } diff --git a/src/main/java/dan200/computercraft/core/computer/ComputerSide.java b/src/main/java/dan200/computercraft/core/computer/ComputerSide.java index 1cbbfa294..047608634 100644 --- a/src/main/java/dan200/computercraft/core/computer/ComputerSide.java +++ b/src/main/java/dan200/computercraft/core/computer/ComputerSide.java @@ -6,11 +6,13 @@ package dan200.computercraft.core.computer; +import net.minecraft.util.Direction; + import javax.annotation.Nonnull; import javax.annotation.Nullable; /** - * A side on a computer. Unlike {@link net.minecraft.util.EnumFacing}, this is relative to the direction the computer is + * A side on a computer. Unlike {@link Direction}, this is relative to the direction the computer is * facing.. */ public enum ComputerSide diff --git a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java index 4f6eb2e28..433497ba2 100644 --- a/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java +++ b/src/main/java/dan200/computercraft/core/filesystem/ResourceMount.java @@ -170,7 +170,7 @@ public class ResourceMount implements IMount { total += read; read = s.read( TEMP_BUFFER ); - } while ( read > 0 ); + } while( read > 0 ); return file.size = total; } @@ -267,7 +267,7 @@ public class ResourceMount implements IMount synchronized void add( IReloadableResourceManager manager, ResourceMount mount ) { - if( managers.add( manager ) ) manager.addReloadListener( this ); + if( managers.add( manager ) ) manager.func_219534_a( this ); // addReloadListener mounts.add( mount ); } } diff --git a/src/main/java/dan200/computercraft/core/terminal/Terminal.java b/src/main/java/dan200/computercraft/core/terminal/Terminal.java index a0229f53a..d0a4c9f04 100644 --- a/src/main/java/dan200/computercraft/core/terminal/Terminal.java +++ b/src/main/java/dan200/computercraft/core/terminal/Terminal.java @@ -7,7 +7,7 @@ package dan200.computercraft.core.terminal; import dan200.computercraft.shared.util.Palette; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; public class Terminal { @@ -334,7 +334,7 @@ public class Terminal m_changed = false; } - public synchronized NBTTagCompound writeToNBT( NBTTagCompound nbt ) + public synchronized CompoundNBT writeToNBT( CompoundNBT nbt ) { nbt.putInt( "term_cursorX", m_cursorX ); nbt.putInt( "term_cursorY", m_cursorY ); @@ -354,7 +354,7 @@ public class Terminal return nbt; } - public synchronized void readFromNBT( NBTTagCompound nbt ) + public synchronized void readFromNBT( CompoundNBT nbt ) { m_cursorX = nbt.getInt( "term_cursorX" ); m_cursorY = nbt.getInt( "term_cursorY" ); diff --git a/src/main/java/dan200/computercraft/shared/BundledRedstone.java b/src/main/java/dan200/computercraft/shared/BundledRedstone.java index 8c562c7a8..747355605 100644 --- a/src/main/java/dan200/computercraft/shared/BundledRedstone.java +++ b/src/main/java/dan200/computercraft/shared/BundledRedstone.java @@ -9,7 +9,7 @@ package dan200.computercraft.shared; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -30,12 +30,12 @@ public final class BundledRedstone providers.add( provider ); } - public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) + public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) { return World.isValid( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1; } - private static int getUnmaskedOutput( World world, BlockPos pos, EnumFacing side ) + private static int getUnmaskedOutput( World world, BlockPos pos, Direction side ) { if( !World.isValid( pos ) ) return -1; @@ -60,7 +60,7 @@ public final class BundledRedstone return combinedSignal; } - public static int getOutput( World world, BlockPos pos, EnumFacing side ) + public static int getOutput( World world, BlockPos pos, Direction side ) { int signal = getUnmaskedOutput( world, pos, side ); return signal >= 0 ? signal : 0; diff --git a/src/main/java/dan200/computercraft/shared/Peripherals.java b/src/main/java/dan200/computercraft/shared/Peripherals.java index 960ae0c0a..684bec613 100644 --- a/src/main/java/dan200/computercraft/shared/Peripherals.java +++ b/src/main/java/dan200/computercraft/shared/Peripherals.java @@ -9,7 +9,7 @@ package dan200.computercraft.shared; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheralProvider; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -30,12 +30,12 @@ public final class Peripherals providers.add( provider ); } - public static IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side ) + public static IPeripheral getPeripheral( World world, BlockPos pos, Direction side ) { return World.isValid( pos ) && !world.isRemote ? getPeripheralAt( world, pos, side ) : null; } - private static IPeripheral getPeripheralAt( World world, BlockPos pos, EnumFacing side ) + private static IPeripheral getPeripheralAt( World world, BlockPos pos, Direction side ) { // Try the handlers in order: for( IPeripheralProvider peripheralProvider : providers ) diff --git a/src/main/java/dan200/computercraft/shared/Registry.java b/src/main/java/dan200/computercraft/shared/Registry.java index 5c36d45e4..5786a543b 100644 --- a/src/main/java/dan200/computercraft/shared/Registry.java +++ b/src/main/java/dan200/computercraft/shared/Registry.java @@ -39,10 +39,10 @@ import dan200.computercraft.shared.util.CreativeTabMain; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityType; -import net.minecraft.init.Items; +import net.minecraft.item.BlockItem; import net.minecraft.item.Item; -import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemGroup; +import net.minecraft.item.Items; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; import net.minecraftforge.event.RegistryEvent; @@ -181,7 +181,7 @@ public final class Registry ); } - private static T setupItemBlock( T item ) + private static T setupItemBlock( T item ) { item.setRegistryName( item.getBlock().getRegistryName() ); return item; @@ -247,14 +247,14 @@ public final class Registry // Peripherals registry.registerAll( - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.speaker, defaultItem() ) ), - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.diskDrive, defaultItem() ) ), - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.printer, defaultItem() ) ), - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.monitorNormal, defaultItem() ) ), - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.monitorAdvanced, defaultItem() ) ), - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.wirelessModemNormal, defaultItem() ) ), - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.wirelessModemAdvanced, defaultItem() ) ), - setupItemBlock( new ItemBlock( ComputerCraft.Blocks.wiredModemFull, defaultItem() ) ) + setupItemBlock( new BlockItem( ComputerCraft.Blocks.speaker, defaultItem() ) ), + setupItemBlock( new BlockItem( ComputerCraft.Blocks.diskDrive, defaultItem() ) ), + setupItemBlock( new BlockItem( ComputerCraft.Blocks.printer, defaultItem() ) ), + setupItemBlock( new BlockItem( ComputerCraft.Blocks.monitorNormal, defaultItem() ) ), + setupItemBlock( new BlockItem( ComputerCraft.Blocks.monitorAdvanced, defaultItem() ) ), + setupItemBlock( new BlockItem( ComputerCraft.Blocks.wirelessModemNormal, defaultItem() ) ), + setupItemBlock( new BlockItem( ComputerCraft.Blocks.wirelessModemAdvanced, defaultItem() ) ), + setupItemBlock( new BlockItem( ComputerCraft.Blocks.wiredModemFull, defaultItem() ) ) ); ComputerCraft.Items.cable = new ItemBlockCable.Cable( ComputerCraft.Blocks.cable, defaultItem() ); @@ -286,7 +286,7 @@ public final class Registry ComputerCraft.TurtleUpgrades.diamondSword = new TurtleSword( new ResourceLocation( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD ); ComputerCraftAPI.registerTurtleUpgrade( ComputerCraft.TurtleUpgrades.diamondSword ); - ComputerCraft.TurtleUpgrades.diamondShovel = new TurtleShovel( new ResourceLocation( "minecraft", "diamond_shovel" ), Items.DIAMOND_SHOVEL ); + ComputerCraft.TurtleUpgrades.diamondShovel = new TurtleShovel( new ResourceLocation( "minecraft", "diamond_shovel" ), net.minecraft.item.Items.DIAMOND_SHOVEL ); ComputerCraftAPI.registerTurtleUpgrade( ComputerCraft.TurtleUpgrades.diamondShovel ); ComputerCraft.TurtleUpgrades.diamondPickaxe = new TurtleTool( new ResourceLocation( "minecraft", "diamond_pickaxe" ), Items.DIAMOND_PICKAXE ); diff --git a/src/main/java/dan200/computercraft/shared/TurtlePermissions.java b/src/main/java/dan200/computercraft/shared/TurtlePermissions.java index f28c421cf..2dbe4b725 100644 --- a/src/main/java/dan200/computercraft/shared/TurtlePermissions.java +++ b/src/main/java/dan200/computercraft/shared/TurtlePermissions.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.event.TurtleActionEvent; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -18,13 +18,13 @@ import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID ) public final class TurtlePermissions { - public static boolean isBlockEnterable( World world, BlockPos pos, EntityPlayer player ) + public static boolean isBlockEnterable( World world, BlockPos pos, PlayerEntity player ) { MinecraftServer server = world.getServer(); return server == null || world.isRemote || !server.isBlockProtected( world, pos, player ); } - public static boolean isBlockEditable( World world, BlockPos pos, EntityPlayer 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 ); diff --git a/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java b/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java index ce63d9a78..03314d6fd 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandComputerCraft.java @@ -20,17 +20,17 @@ import dan200.computercraft.core.tracking.TrackingField; import dan200.computercraft.shared.command.text.TableBuilder; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.network.Containers; +import dan200.computercraft.shared.network.container.ViewComputerContainerData; import net.minecraft.command.CommandSource; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.network.play.server.SPacketPlayerPosLook; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.network.play.server.SPlayerPositionLookPacket; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.world.ServerWorld; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import javax.annotation.Nonnull; import java.util.*; @@ -170,16 +170,21 @@ public final class CommandComputerCraft if( world == null || pos == null ) throw TP_NOT_THERE.create(); Entity entity = context.getSource().assertIsEntity(); - if( !(entity instanceof EntityPlayerMP) ) throw TP_NOT_PLAYER.create(); + if( !(entity instanceof ServerPlayerEntity) ) throw TP_NOT_PLAYER.create(); - EntityPlayerMP player = (EntityPlayerMP) entity; + ServerPlayerEntity player = (ServerPlayerEntity) entity; if( player.getEntityWorld() == world ) { - player.connection.setPlayerLocation( pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0, EnumSet.noneOf( SPacketPlayerPosLook.EnumFlags.class ) ); + player.connection.setPlayerLocation( + pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0, + EnumSet.noneOf( SPlayerPositionLookPacket.Flags.class ) + ); } else { - player.teleport( (WorldServer) world, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0 ); + player.teleport( (ServerWorld) world, + pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0 + ); } return 1; @@ -210,9 +215,9 @@ public final class CommandComputerCraft .requires( UserLevel.OP ) .arg( "computer", oneComputer() ) .executes( context -> { - EntityPlayerMP player = context.getSource().asPlayer(); + ServerPlayerEntity player = context.getSource().asPlayer(); ServerComputer computer = getComputerArgument( context, "computer" ); - Containers.openComputerGUI( player, computer ); + new ViewComputerContainerData( computer ).open( player ); return 1; } ) ) @@ -259,7 +264,7 @@ public final class CommandComputerCraft private static ITextComponent linkComputer( CommandSource source, ServerComputer serverComputer, int computerId ) { - ITextComponent out = new TextComponentString( "" ); + ITextComponent out = new StringTextComponent( "" ); // Append the computer instance if( serverComputer == null ) @@ -319,7 +324,7 @@ public final class CommandComputerCraft private static TrackingContext getTimingContext( CommandSource source ) { Entity entity = source.getEntity(); - return entity instanceof EntityPlayer ? Tracking.getContext( entity.getUniqueID() ) : Tracking.getContext( SYSTEM_UUID ); + return entity instanceof PlayerEntity ? Tracking.getContext( entity.getUniqueID() ) : 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 47ede7da2..a35b69cdd 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandCopy.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandCopy.java @@ -12,8 +12,8 @@ import dan200.computercraft.ComputerCraft; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandSource; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.HoverEvent; import net.minecraftforge.api.distmarker.Dist; @@ -58,10 +58,10 @@ public final class CommandCopy public static ITextComponent createCopyText( String text ) { - TextComponentString name = new TextComponentString( text ); + StringTextComponent name = new StringTextComponent( text ); name.getStyle() .setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, PREFIX + text ) ) - .setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TextComponentTranslation( "gui.computercraft.tooltip.copy" ) ) ); + .setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent( "gui.computercraft.tooltip.copy" ) ) ); return name; } } diff --git a/src/main/java/dan200/computercraft/shared/command/CommandUtils.java b/src/main/java/dan200/computercraft/shared/command/CommandUtils.java index 378c4d623..a837b770c 100644 --- a/src/main/java/dan200/computercraft/shared/command/CommandUtils.java +++ b/src/main/java/dan200/computercraft/shared/command/CommandUtils.java @@ -12,7 +12,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.command.CommandSource; import net.minecraft.command.ISuggestionProvider; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraftforge.common.util.FakePlayer; import java.util.Arrays; @@ -27,9 +27,9 @@ public final class CommandUtils public static boolean isPlayer( CommandSource output ) { Entity sender = output.getEntity(); - return sender instanceof EntityPlayerMP + return sender instanceof ServerPlayerEntity && !(sender instanceof FakePlayer) - && ((EntityPlayerMP) sender).connection != null; + && ((ServerPlayerEntity) sender).connection != null; } @SuppressWarnings( "unchecked" ) diff --git a/src/main/java/dan200/computercraft/shared/command/Exceptions.java b/src/main/java/dan200/computercraft/shared/command/Exceptions.java index 6773e39ea..e4a6b0a44 100644 --- a/src/main/java/dan200/computercraft/shared/command/Exceptions.java +++ b/src/main/java/dan200/computercraft/shared/command/Exceptions.java @@ -9,7 +9,7 @@ package dan200.computercraft.shared.command; import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TranslationTextComponent; public final class Exceptions { @@ -28,16 +28,16 @@ public final class Exceptions private static SimpleCommandExceptionType translated( String key ) { - return new SimpleCommandExceptionType( new TextComponentTranslation( key ) ); + return new SimpleCommandExceptionType( new TranslationTextComponent( key ) ); } private static DynamicCommandExceptionType translated1( String key ) { - return new DynamicCommandExceptionType( x -> new TextComponentTranslation( key, x ) ); + return new DynamicCommandExceptionType( x -> new TranslationTextComponent( key, x ) ); } private static Dynamic2CommandExceptionType translated2( String key ) { - return new Dynamic2CommandExceptionType( ( x, y ) -> new TextComponentTranslation( key, x, y ) ); + return new Dynamic2CommandExceptionType( ( x, y ) -> new TranslationTextComponent( key, x, y ) ); } } diff --git a/src/main/java/dan200/computercraft/shared/command/UserLevel.java b/src/main/java/dan200/computercraft/shared/command/UserLevel.java index 7a24bc1fe..6177c30a8 100644 --- a/src/main/java/dan200/computercraft/shared/command/UserLevel.java +++ b/src/main/java/dan200/computercraft/shared/command/UserLevel.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.command; import net.minecraft.command.CommandSource; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; import java.util.function.Predicate; @@ -62,8 +62,8 @@ public enum UserLevel implements Predicate MinecraftServer server = source.getServer(); Entity sender = source.getEntity(); - if( server.isSinglePlayer() && sender instanceof EntityPlayer && - ((EntityPlayer) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() ) ) + if( server.isSinglePlayer() && sender instanceof PlayerEntity && + ((PlayerEntity) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() ) ) { if( this == OWNER || this == OWNER_OP ) return true; } diff --git a/src/main/java/dan200/computercraft/shared/command/arguments/ArgumentSerializers.java b/src/main/java/dan200/computercraft/shared/command/arguments/ArgumentSerializers.java index ad8837024..20af81c37 100644 --- a/src/main/java/dan200/computercraft/shared/command/arguments/ArgumentSerializers.java +++ b/src/main/java/dan200/computercraft/shared/command/arguments/ArgumentSerializers.java @@ -18,12 +18,12 @@ public final class ArgumentSerializers @SuppressWarnings( "unchecked" ) private static > void registerUnsafe( ResourceLocation id, Class type, IArgumentSerializer serializer ) { - ArgumentTypes.register( id, type, (IArgumentSerializer) serializer ); + ArgumentTypes.func_218136_a( id.toString(), type, (IArgumentSerializer) serializer ); } private static > void register( ResourceLocation id, Class type, IArgumentSerializer serializer ) { - ArgumentTypes.register( id, type, serializer ); + ArgumentTypes.func_218136_a( id.toString(), type, serializer ); } private static > void register( ResourceLocation id, T instance ) diff --git a/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java b/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java index 6311ffd07..a7c957865 100644 --- a/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java +++ b/src/main/java/dan200/computercraft/shared/command/arguments/RepeatArgumentType.java @@ -19,7 +19,7 @@ import net.minecraft.command.arguments.ArgumentTypes; import net.minecraft.command.arguments.IArgumentSerializer; import net.minecraft.network.PacketBuffer; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -160,7 +160,7 @@ public final class RepeatArgumentType implements ArgumentType> { Message message = arg.some.create().getRawMessage(); if( message instanceof ITextComponent ) return (ITextComponent) message; - return new TextComponentString( message.getString() ); + return new StringTextComponent( message.getString() ); } } } 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 6fa685443..ca3c3db79 100644 --- a/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java +++ b/src/main/java/dan200/computercraft/shared/command/builder/HelpingArgumentBuilder.java @@ -15,7 +15,7 @@ import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import net.minecraft.command.CommandSource; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.event.ClickEvent; @@ -174,7 +174,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder type; - public BlockGeneric( Properties settings, TileEntityType type ) + public BlockGeneric( Properties settings, NamedTileEntityType type ) { super( settings ); this.type = type; + type.setBlock( this ); } @Override @Deprecated - public final void onReplaced( @Nonnull IBlockState block, @Nonnull World world, @Nonnull BlockPos pos, IBlockState replace, boolean bool ) + public final void onReplaced( @Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool ) { if( block.getBlock() == replace.getBlock() ) return; @@ -46,22 +48,22 @@ public abstract class BlockGeneric extends Block @Override @Deprecated - public final boolean onBlockActivated( IBlockState state, World world, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public final boolean onBlockActivated( BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { TileEntity tile = world.getTileEntity( pos ); - return tile instanceof TileGeneric && ((TileGeneric) tile).onActivate( player, hand, side, hitX, hitY, hitZ ); + return tile instanceof TileGeneric && ((TileGeneric) tile).onActivate( player, hand, hit ); } @Override @Deprecated - public final void neighborChanged( IBlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos ) + public final void neighborChanged( BlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean isMoving ) { TileEntity tile = world.getTileEntity( pos ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos ); } @Override - public final void onNeighborChange( IBlockState state, IWorldReader world, BlockPos pos, BlockPos neighbour ) + public final void onNeighborChange( BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbour ) { TileEntity tile = world.getTileEntity( pos ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourTileEntityChange( neighbour ); @@ -69,21 +71,21 @@ public abstract class BlockGeneric extends Block @Override @Deprecated - public void tick( IBlockState state, World world, BlockPos pos, Random rand ) + public void tick( BlockState state, World world, BlockPos pos, Random rand ) { TileEntity te = world.getTileEntity( pos ); if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick(); } @Override - public boolean hasTileEntity( IBlockState state ) + public boolean hasTileEntity( BlockState state ) { return true; } @Nullable @Override - public TileEntity createTileEntity( @Nonnull IBlockState state, @Nonnull IBlockReader world ) + public TileEntity createTileEntity( @Nonnull BlockState state, @Nonnull IBlockReader world ) { return type.create(); } diff --git a/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java b/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java index 4e7ad3791..85f79d085 100644 --- a/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java +++ b/src/main/java/dan200/computercraft/shared/common/ClientTerminal.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.common; import dan200.computercraft.core.terminal.Terminal; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; public class ClientTerminal implements ITerminal { @@ -47,12 +47,12 @@ public class ClientTerminal implements ITerminal return m_colour; } - public void readDescription( NBTTagCompound nbt ) + public void readDescription( CompoundNBT nbt ) { m_colour = nbt.getBoolean( "colour" ); if( nbt.contains( "terminal" ) ) { - NBTTagCompound terminal = nbt.getCompound( "terminal" ); + CompoundNBT terminal = nbt.getCompound( "terminal" ); resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) ); m_terminal.readFromNBT( terminal ); } diff --git a/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java index d17d95e25..738ff499a 100644 --- a/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java +++ b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java @@ -6,30 +6,29 @@ package dan200.computercraft.shared.common; -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.shared.util.AbstractRecipe; import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.ColourTracker; import dan200.computercraft.shared.util.ColourUtils; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.EnumDyeColor; +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.item.DyeColor; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.RecipeSerializers; +import net.minecraft.item.crafting.SpecialRecipe; +import net.minecraft.item.crafting.SpecialRecipeSerializer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import javax.annotation.Nonnull; -public class ColourableRecipe extends AbstractRecipe +public class ColourableRecipe extends SpecialRecipe { - public ColourableRecipe( ResourceLocation id ) + private ColourableRecipe( ResourceLocation id ) { super( id ); } @Override - public boolean matches( @Nonnull IInventory inv, @Nonnull World world ) + public boolean matches( @Nonnull CraftingInventory inv, @Nonnull World world ) { boolean hasColourable = false; boolean hasDye = false; @@ -58,7 +57,7 @@ public class ColourableRecipe extends AbstractRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull IInventory inv ) + public ItemStack getCraftingResult( @Nonnull CraftingInventory inv ) { ItemStack colourable = ItemStack.EMPTY; @@ -76,7 +75,7 @@ public class ColourableRecipe extends AbstractRecipe } else { - EnumDyeColor dye = ColourUtils.getStackColour( stack ); + DyeColor dye = ColourUtils.getStackColour( stack ); if( dye == null ) continue; Colour colour = Colour.fromInt( 15 - dye.getId() ); @@ -101,7 +100,5 @@ public class ColourableRecipe extends AbstractRecipe return SERIALIZER; } - public static final IRecipeSerializer SERIALIZER = new RecipeSerializers.SimpleSerializer<>( - ComputerCraft.MOD_ID + ":colour", ColourableRecipe::new - ); + public static final IRecipeSerializer SERIALIZER = new SpecialRecipeSerializer<>( ColourableRecipe::new ); } diff --git a/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java b/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java index af4f46983..d6dec3d36 100644 --- a/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java +++ b/src/main/java/dan200/computercraft/shared/common/ContainerHeldItem.java @@ -6,21 +6,28 @@ package dan200.computercraft.shared.common; +import dan200.computercraft.shared.network.container.ContainerData; +import dan200.computercraft.shared.network.container.PrintoutContainerData; import dan200.computercraft.shared.util.InventoryUtil; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumHand; +import net.minecraft.util.Hand; import javax.annotation.Nonnull; public class ContainerHeldItem extends Container { - private final ItemStack m_stack; - private final EnumHand m_hand; + public static final ContainerType PRINTOUT_TYPE = ContainerData.create( PrintoutContainerData::new ); - public ContainerHeldItem( EntityPlayer player, EnumHand hand ) + private final ItemStack m_stack; + private final Hand m_hand; + + public ContainerHeldItem( ContainerType type, int id, PlayerEntity player, Hand hand ) { + super( type, id ); + m_hand = hand; m_stack = InventoryUtil.copyItem( player.getHeldItem( hand ) ); } @@ -32,7 +39,7 @@ public class ContainerHeldItem extends Container } @Override - public boolean canInteractWith( @Nonnull EntityPlayer player ) + public boolean canInteractWith( @Nonnull PlayerEntity player ) { if( !player.isAlive() ) return false; diff --git a/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java index 5b0a26148..3f57d81f0 100644 --- a/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/shared/common/DefaultBundledRedstoneProvider.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.common; import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import net.minecraft.block.Block; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -17,12 +17,12 @@ import javax.annotation.Nonnull; public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider { @Override - public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) + public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) { return getDefaultBundledRedstoneOutput( world, pos, side ); } - public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ) + public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, Direction side ) { Block block = world.getBlockState( pos ).getBlock(); if( block instanceof IBundledRedstoneBlock ) diff --git a/src/main/java/dan200/computercraft/shared/common/IBundledRedstoneBlock.java b/src/main/java/dan200/computercraft/shared/common/IBundledRedstoneBlock.java index d6212dbed..4d4b2d28c 100644 --- a/src/main/java/dan200/computercraft/shared/common/IBundledRedstoneBlock.java +++ b/src/main/java/dan200/computercraft/shared/common/IBundledRedstoneBlock.java @@ -6,13 +6,13 @@ package dan200.computercraft.shared.common; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public interface IBundledRedstoneBlock { - boolean getBundledRedstoneConnectivity( World world, BlockPos pos, EnumFacing side ); + boolean getBundledRedstoneConnectivity( World world, BlockPos pos, Direction side ); - int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ); + int getBundledRedstoneOutput( World world, BlockPos pos, Direction side ); } diff --git a/src/main/java/dan200/computercraft/shared/common/IColouredItem.java b/src/main/java/dan200/computercraft/shared/common/IColouredItem.java index 9fe5ca6cf..b87bc0779 100644 --- a/src/main/java/dan200/computercraft/shared/common/IColouredItem.java +++ b/src/main/java/dan200/computercraft/shared/common/IColouredItem.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.common; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; public interface IColouredItem { @@ -27,7 +27,7 @@ public interface IColouredItem static int getColourBasic( ItemStack stack ) { - NBTTagCompound tag = stack.getTag(); + CompoundNBT tag = stack.getTag(); return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1; } @@ -35,7 +35,7 @@ public interface IColouredItem { if( colour == -1 ) { - NBTTagCompound tag = stack.getTag(); + CompoundNBT tag = stack.getTag(); if( tag != null ) tag.remove( NBT_COLOUR ); } else diff --git a/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java b/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java index 0898a3844..6ab51aec3 100644 --- a/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java +++ b/src/main/java/dan200/computercraft/shared/common/ServerTerminal.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.common; import dan200.computercraft.core.terminal.Terminal; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import java.util.concurrent.atomic.AtomicBoolean; @@ -86,12 +86,12 @@ public class ServerTerminal implements ITerminal // Networking stuff - public void writeDescription( NBTTagCompound nbt ) + public void writeDescription( CompoundNBT nbt ) { nbt.putBoolean( "colour", m_colour ); if( m_terminal != null ) { - NBTTagCompound terminal = new NBTTagCompound(); + CompoundNBT terminal = new CompoundNBT(); terminal.putInt( "term_width", m_terminal.getWidth() ); terminal.putInt( "term_height", m_terminal.getHeight() ); m_terminal.writeToNBT( terminal ); diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index 2b01a2be1..9efbd3e56 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -6,16 +6,16 @@ package dan200.computercraft.shared.common; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.NetworkManager; -import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import javax.annotation.Nonnull; @@ -34,12 +34,12 @@ public abstract class TileGeneric extends TileEntity { markDirty(); BlockPos pos = getPos(); - IBlockState state = getBlockState(); - getWorld().markBlockRangeForRenderUpdate( pos, pos ); + BlockState state = getBlockState(); + getWorld().markForRerender( pos ); getWorld().notifyBlockUpdate( pos, state, state, 3 ); } - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { return false; } @@ -56,12 +56,12 @@ public abstract class TileGeneric extends TileEntity { } - protected double getInteractRange( EntityPlayer player ) + protected double getInteractRange( PlayerEntity player ) { return 8.0; } - public boolean isUsable( EntityPlayer player, boolean ignoreRange ) + public boolean isUsable( PlayerEntity player, boolean ignoreRange ) { if( player == null || !player.isAlive() || getWorld().getTileEntity( getPos() ) != this ) return false; if( ignoreRange ) return true; @@ -72,40 +72,40 @@ public abstract class TileGeneric extends TileEntity player.getDistanceSq( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ) <= range * range; } - protected void writeDescription( @Nonnull NBTTagCompound nbt ) + protected void writeDescription( @Nonnull CompoundNBT nbt ) { } - protected void readDescription( @Nonnull NBTTagCompound nbt ) + protected void readDescription( @Nonnull CompoundNBT nbt ) { } @Nonnull @Override - public final SPacketUpdateTileEntity getUpdatePacket() + public final SUpdateTileEntityPacket getUpdatePacket() { - NBTTagCompound nbt = new NBTTagCompound(); + CompoundNBT nbt = new CompoundNBT(); writeDescription( nbt ); - return new SPacketUpdateTileEntity( pos, 0, nbt ); + return new SUpdateTileEntityPacket( pos, 0, nbt ); } @Override - public final void onDataPacket( NetworkManager net, SPacketUpdateTileEntity packet ) + public final void onDataPacket( NetworkManager net, SUpdateTileEntityPacket packet ) { if( packet.getTileEntityType() == 0 ) readDescription( packet.getNbtCompound() ); } @Nonnull @Override - public NBTTagCompound getUpdateTag() + public CompoundNBT getUpdateTag() { - NBTTagCompound tag = super.getUpdateTag(); + CompoundNBT tag = super.getUpdateTag(); writeDescription( tag ); return tag; } @Override - public void handleUpdateTag( @Nonnull NBTTagCompound tag ) + public void handleUpdateTag( @Nonnull CompoundNBT tag ) { super.handleUpdateTag( tag ); readDescription( tag ); 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 136188323..de52751fc 100644 --- a/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java +++ b/src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java @@ -16,10 +16,10 @@ import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.shared.computer.blocks.TileCommandComputer; import dan200.computercraft.shared.util.NBTUtil; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.server.MinecraftServer; import net.minecraft.state.IProperty; import net.minecraft.tileentity.TileEntity; @@ -97,7 +97,7 @@ public class CommandAPI implements ILuaAPI private static Object getBlockInfo( World world, BlockPos pos ) { // Get the details of the block - IBlockState state = world.getBlockState( pos ); + BlockState state = world.getBlockState( pos ); Block block = state.getBlock(); Map table = new HashMap<>(); @@ -112,7 +112,7 @@ public class CommandAPI implements ILuaAPI table.put( "state", stateTable ); TileEntity tile = world.getTileEntity( pos ); - if( tile != null ) table.put( "nbt", NBTUtil.toLua( tile.write( new NBTTagCompound() ) ) ); + if( tile != null ) table.put( "nbt", NBTUtil.toLua( tile.write( new CompoundNBT() ) ) ); return table; } 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 41b68cd8c..034693764 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputer.java @@ -9,16 +9,16 @@ package dan200.computercraft.shared.computer.blocks; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.items.ComputerItemFactory; +import dan200.computercraft.shared.util.NamedTileEntityType; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.DirectionProperty; import net.minecraft.state.EnumProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -28,24 +28,24 @@ public class BlockComputer extends BlockComputerBase public static final EnumProperty STATE = EnumProperty.create( "state", ComputerState.class ); public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; - public BlockComputer( Properties settings, ComputerFamily family, TileEntityType type ) + public BlockComputer( Properties settings, ComputerFamily family, NamedTileEntityType type ) { super( settings, family, type ); setDefaultState( getDefaultState() - .with( FACING, EnumFacing.NORTH ) + .with( FACING, Direction.NORTH ) .with( STATE, ComputerState.OFF ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void fillStateContainer( StateContainer.Builder builder ) { builder.add( FACING, STATE ); } @Nullable @Override - public IBlockState getStateForPlacement( BlockItemUseContext placement ) + public BlockState getStateForPlacement( BlockItemUseContext placement ) { return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); } 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 2ff6df99b..0050377bd 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/BlockComputerBase.java @@ -12,15 +12,14 @@ import dan200.computercraft.shared.common.IBundledRedstoneBlock; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.items.IComputerItem; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; +import dan200.computercraft.shared.util.NamedTileEntityType; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.IFluidState; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.IBlockReader; @@ -32,7 +31,7 @@ public abstract class BlockComputerBase extends Bloc { private final ComputerFamily family; - protected BlockComputerBase( Properties settings, ComputerFamily family, TileEntityType type ) + protected BlockComputerBase( Properties settings, ComputerFamily family, NamedTileEntityType type ) { super( settings, type ); this.family = family; @@ -40,9 +39,9 @@ public abstract class BlockComputerBase extends Bloc @Override @Deprecated - public void onBlockAdded( IBlockState state, World world, BlockPos pos, IBlockState oldState ) + public void onBlockAdded( BlockState state, World world, BlockPos pos, BlockState oldState, boolean isMoving ) { - super.onBlockAdded( state, world, pos, oldState ); + super.onBlockAdded( state, world, pos, oldState, isMoving ); TileEntity tile = world.getTileEntity( pos ); if( tile instanceof TileComputerBase ) ((TileComputerBase) tile).updateInput(); @@ -50,14 +49,14 @@ public abstract class BlockComputerBase extends Bloc @Override @Deprecated - public boolean canProvidePower( IBlockState state ) + public boolean canProvidePower( BlockState state ) { return true; } @Override @Deprecated - public int getStrongPower( IBlockState state, IBlockReader world, BlockPos pos, EnumFacing incomingSide ) + public int getStrongPower( BlockState state, IBlockReader world, BlockPos pos, Direction incomingSide ) { TileEntity entity = world.getTileEntity( pos ); if( !(entity instanceof TileComputerBase) ) return 0; @@ -80,19 +79,19 @@ public abstract class BlockComputerBase extends Bloc @Override @Deprecated - public int getWeakPower( IBlockState state, IBlockReader world, BlockPos pos, EnumFacing incomingSide ) + public int getWeakPower( BlockState state, IBlockReader world, BlockPos pos, Direction incomingSide ) { return getStrongPower( state, world, pos, incomingSide ); } @Override - public boolean getBundledRedstoneConnectivity( World world, BlockPos pos, EnumFacing side ) + public boolean getBundledRedstoneConnectivity( World world, BlockPos pos, Direction side ) { return true; } @Override - public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ) + public int getBundledRedstoneOutput( World world, BlockPos pos, Direction side ) { TileEntity entity = world.getTileEntity( pos ); if( !(entity instanceof TileComputerBase) ) return 0; @@ -107,7 +106,7 @@ public abstract class BlockComputerBase extends Bloc @Nonnull @Override - public ItemStack getPickBlock( IBlockState state, RayTraceResult target, IBlockReader world, BlockPos pos, EntityPlayer player ) + public ItemStack getPickBlock( BlockState state, RayTraceResult target, IBlockReader world, BlockPos pos, PlayerEntity player ) { TileEntity tile = world.getTileEntity( pos ); if( tile instanceof TileComputerBase ) @@ -119,14 +118,15 @@ public abstract class BlockComputerBase extends Bloc return super.getPickBlock( state, target, world, pos, player ); } + /* TODO: THIS!! @Override @Deprecated - public final void dropBlockAsItemWithChance( @Nonnull IBlockState state, World world, @Nonnull BlockPos pos, float change, int fortune ) + public final void dropBlockAsItemWithChance( @Nonnull BlockState state, World world, @Nonnull BlockPos pos, float change, int fortune ) { } @Override - public final void getDrops( IBlockState state, NonNullList drops, World world, BlockPos pos, int fortune ) + public final void getDrops( BlockState state, NonNullList drops, World world, BlockPos pos, int fortune ) { TileEntity tile = world.getTileEntity( pos ); if( tile instanceof TileComputerBase ) @@ -135,9 +135,10 @@ public abstract class BlockComputerBase extends Bloc if( !stack.isEmpty() ) drops.add( stack ); } } + */ @Override - public boolean removedByPlayer( IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest, IFluidState fluid ) + public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid ) { if( !world.isRemote ) { @@ -147,7 +148,7 @@ public abstract class BlockComputerBase extends Bloc if( tile instanceof TileComputerBase ) { TileComputerBase computer = (TileComputerBase) tile; - if( !player.abilities.isCreativeMode || computer.getLabel() != null ) + if( !player.playerAbilities.isCreativeMode || computer.getLabel() != null ) { spawnAsEntity( world, pos, getItem( computer ) ); } @@ -158,7 +159,7 @@ public abstract class BlockComputerBase extends Bloc } @Override - public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack ) + public void onBlockPlacedBy( World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack ) { super.onBlockPlacedBy( world, pos, state, placer, stack ); 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 8a203ce45..dcd476592 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileCommandComputer.java @@ -10,19 +10,19 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.apis.CommandAPI; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.util.NamedBlockEntityType; +import dan200.computercraft.shared.util.NamedTileEntityType; import net.minecraft.command.CommandSource; import net.minecraft.command.ICommandSource; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec2f; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.world.WorldServer; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.ServerWorld; import javax.annotation.Nonnull; import java.util.HashMap; @@ -30,7 +30,7 @@ import java.util.Map; public class TileCommandComputer extends TileComputer { - public static final NamedBlockEntityType FACTORY = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "command_computer" ), f -> new TileCommandComputer( ComputerFamily.Command, f ) ); @@ -104,8 +104,8 @@ 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, - (WorldServer) getWorld(), 2, - name, new TextComponentString( name ), + (ServerWorld) getWorld(), 2, + name, new StringTextComponent( name ), getWorld().getServer(), null ); } @@ -119,17 +119,17 @@ public class TileCommandComputer extends TileComputer } @Override - public boolean isUsable( EntityPlayer player, boolean ignoreRange ) + public boolean isUsable( PlayerEntity player, boolean ignoreRange ) { MinecraftServer server = player.getServer(); if( server == null || !server.isCommandBlockEnabled() ) { - player.sendStatusMessage( new TextComponentTranslation( "advMode.notEnabled" ), true ); + player.sendStatusMessage( new TranslationTextComponent( "advMode.notEnabled" ), true ); return false; } else if( !player.canUseCommandBlock() ) { - player.sendStatusMessage( new TextComponentTranslation( "advMode.notAllowed" ), true ); + player.sendStatusMessage( new TranslationTextComponent( "advMode.notAllowed" ), true ); return false; } else 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 4af198b10..ab1826888 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java @@ -11,22 +11,21 @@ import dan200.computercraft.core.computer.ComputerSide; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.network.Containers; -import dan200.computercraft.shared.util.NamedBlockEntityType; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; +import dan200.computercraft.shared.util.NamedTileEntityType; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; public class TileComputer extends TileComputerBase { - public static final NamedBlockEntityType FACTORY_NORMAL = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_NORMAL = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "computer_normal" ), f -> new TileComputer( ComputerFamily.Normal, f ) ); - public static final NamedBlockEntityType FACTORY_ADVANCED = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_ADVANCED = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "computer_advanced" ), f -> new TileComputer( ComputerFamily.Advanced, f ) ); @@ -69,18 +68,18 @@ public class TileComputer extends TileComputerBase } @Override - public void openGUI( EntityPlayer player ) + public void openGUI( PlayerEntity player ) { - Containers.openComputerGUI( player, this ); + // TODO: Containers.openComputerGUI( player, this ); } - public boolean isUsableByPlayer( EntityPlayer player ) + public boolean isUsableByPlayer( PlayerEntity player ) { return isUsable( player, false ); } @Override - public EnumFacing getDirection() + public Direction getDirection() { return getBlockState().get( BlockComputer.FACING ); } @@ -88,7 +87,7 @@ public class TileComputer extends TileComputerBase @Override protected void updateBlockState( ComputerState newState ) { - IBlockState existing = getBlockState(); + BlockState existing = getBlockState(); if( existing.get( BlockComputer.STATE ) != newState ) { getWorld().setBlockState( getPos(), existing.with( 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 a79a53f21..b54c99551 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputerBase.java @@ -20,28 +20,30 @@ import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.RedstoneUtil; import joptsimple.internal.Strings; -import net.minecraft.block.BlockRedstoneWire; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.RedstoneDiodeBlock; +import net.minecraft.block.RedstoneWireBlock; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.item.Items; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.INameable; -import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Objects; -public abstract class TileComputerBase extends TileGeneric implements IComputerTile, ITickable, IPeripheralTile, INameable +public abstract class TileComputerBase extends TileGeneric implements IComputerTile, ITickableTileEntity, IPeripheralTile, INameable { private static final String NBT_ID = "ComputerId"; private static final String NBT_LABEL = "Label"; @@ -76,7 +78,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT public void destroy() { unload(); - for( EnumFacing dir : DirectionUtil.FACINGS ) + for( Direction dir : DirectionUtil.FACINGS ) { RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); } @@ -95,15 +97,15 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT super.remove(); } - public abstract void openGUI( EntityPlayer player ); + public abstract void openGUI( PlayerEntity player ); - protected boolean canNameWithTag( EntityPlayer player ) + protected boolean canNameWithTag( PlayerEntity player ) { return false; } @Override - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { ItemStack currentItem = player.getHeldItem( hand ); if( !currentItem.isEmpty() && currentItem.getItem() == Items.NAME_TAG && canNameWithTag( player ) && currentItem.hasDisplayName() ) @@ -182,7 +184,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Nonnull @Override - public NBTTagCompound write( NBTTagCompound nbt ) + public CompoundNBT write( CompoundNBT nbt ) { // Save ID, label and power state if( m_computerID >= 0 ) nbt.putInt( NBT_ID, m_computerID ); @@ -193,7 +195,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT } @Override - public void read( NBTTagCompound nbt ) + public void read( CompoundNBT nbt ) { super.read( nbt ); @@ -208,9 +210,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT return false; } - protected abstract EnumFacing getDirection(); + protected abstract Direction getDirection(); - protected ComputerSide remapToLocalSide( EnumFacing globalSide ) + protected ComputerSide remapToLocalSide( Direction globalSide ) { return remapLocalSide( DirectionUtil.toLocal( getDirection(), globalSide ) ); } @@ -220,9 +222,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT return localSide; } - private void updateSideInput( ServerComputer computer, EnumFacing dir, BlockPos offset ) + private void updateSideInput( ServerComputer computer, Direction dir, BlockPos offset ) { - EnumFacing offsetSide = dir.getOpposite(); + Direction offsetSide = dir.getOpposite(); ComputerSide localDir = remapToLocalSide( dir ); computer.setRedstoneInput( localDir, getRedstoneInput( world, offset, dir ) ); @@ -240,16 +242,16 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT * @param pos The position of the neighbour * @param side The side we are reading from * @return The effective redstone power - * @see net.minecraft.block.BlockRedstoneDiode#calculateInputStrength(World, BlockPos, IBlockState) + * @see RedstoneDiodeBlock#calculateInputStrength(World, BlockPos, BlockState) */ - protected static int getRedstoneInput( World world, BlockPos pos, EnumFacing side ) + protected static int getRedstoneInput( World world, BlockPos pos, Direction side ) { int power = world.getRedstonePower( pos, side ); if( power >= 15 ) return power; - IBlockState neighbour = world.getBlockState( pos ); + BlockState neighbour = world.getBlockState( pos ); return neighbour.getBlock() == Blocks.REDSTONE_WIRE - ? Math.max( power, neighbour.get( BlockRedstoneWire.POWER ) ) + ? Math.max( power, neighbour.get( RedstoneWireBlock.POWER ) ) : power; } @@ -262,7 +264,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT if( computer == null ) return; BlockPos pos = computer.getPosition(); - for( EnumFacing dir : DirectionUtil.FACINGS ) + for( Direction dir : DirectionUtil.FACINGS ) { updateSideInput( computer, dir, pos.offset( dir ) ); } @@ -276,7 +278,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT if( computer == null ) return; BlockPos pos = computer.getPosition(); - for( EnumFacing dir : DirectionUtil.FACINGS ) + for( Direction dir : DirectionUtil.FACINGS ) { BlockPos offset = pos.offset( dir ); if( offset.equals( neighbour ) ) @@ -294,7 +296,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT { // Update redstone updateBlock(); - for( EnumFacing dir : DirectionUtil.FACINGS ) + for( Direction dir : DirectionUtil.FACINGS ) { RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); } @@ -394,7 +396,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT // Networking stuff @Override - protected void writeDescription( @Nonnull NBTTagCompound nbt ) + protected void writeDescription( @Nonnull CompoundNBT nbt ) { super.writeDescription( nbt ); @@ -404,7 +406,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT } @Override - protected void readDescription( @Nonnull NBTTagCompound nbt ) + protected void readDescription( @Nonnull CompoundNBT nbt ) { super.readDescription( nbt ); m_instanceID = nbt.contains( NBT_INSTANCE ) ? nbt.getInt( NBT_INSTANCE ) : -1; @@ -429,7 +431,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Nullable @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { return new ComputerPeripheral( "computer", createProxy() ); } @@ -438,7 +440,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Override public ITextComponent getName() { - return hasCustomName() ? new TextComponentString( m_label ) : getBlockState().getBlock().getNameTextComponent(); + return hasCustomName() ? new StringTextComponent( m_label ) : getBlockState().getBlock().getNameTextComponent(); } @Override @@ -451,6 +453,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT @Override public ITextComponent getCustomName() { - return hasCustomName() ? new TextComponentString( m_label ) : null; + return hasCustomName() ? new StringTextComponent( m_label ) : null; } } diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java index 7c029380d..6675f6b4d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ClientComputer.java @@ -10,7 +10,7 @@ import com.google.common.base.Objects; import dan200.computercraft.shared.common.ClientTerminal; import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.server.*; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; public class ClientComputer extends ClientTerminal implements IComputer { @@ -19,7 +19,7 @@ public class ClientComputer extends ClientTerminal implements IComputer private boolean m_on = false; private boolean m_blinking = false; private boolean m_changed = true; - private NBTTagCompound m_userData = null; + private CompoundNBT m_userData = null; private boolean m_changedLastFrame = false; @@ -40,7 +40,7 @@ public class ClientComputer extends ClientTerminal implements IComputer return m_changedLastFrame; } - public NBTTagCompound getUserData() + public CompoundNBT getUserData() { return m_userData; } @@ -135,11 +135,11 @@ public class ClientComputer extends ClientTerminal implements IComputer NetworkHandler.sendToServer( new MouseEventServerMessage( m_instanceID, MouseEventServerMessage.TYPE_SCROLL, direction, x, y ) ); } - public void setState( ComputerState state, NBTTagCompound userData ) + public void setState( ComputerState state, CompoundNBT userData ) { boolean oldOn = m_on; boolean oldBlinking = m_blinking; - NBTTagCompound oldUserData = m_userData; + CompoundNBT oldUserData = m_userData; m_on = state != ComputerState.OFF; m_blinking = state == ComputerState.BLINKING; diff --git a/src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java index 85acfbae0..a6cdebcf1 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/IContainerComputer.java @@ -6,11 +6,13 @@ package dan200.computercraft.shared.computer.core; +import net.minecraft.inventory.container.Container; + import javax.annotation.Nonnull; import javax.annotation.Nullable; /** - * An instance of {@link net.minecraft.inventory.Container} which provides a computer. You should implement this + * An instance of {@link Container} which provides a computer. You should implement this * if you provide custom computers/GUIs to interact with them. */ @FunctionalInterface 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 9b02735a8..2edcc9c7c 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java @@ -22,9 +22,9 @@ import dan200.computercraft.shared.network.NetworkMessage; import dan200.computercraft.shared.network.client.ComputerDataClientMessage; import dan200.computercraft.shared.network.client.ComputerDeletedClientMessage; import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.Container; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.server.MinecraftServer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -43,7 +43,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput private final ComputerFamily m_family; private final Computer m_computer; - private NBTTagCompound m_userData; + private CompoundNBT m_userData; private boolean m_changed; private boolean m_changedLastFrame; @@ -134,11 +134,11 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput m_computer.unload(); } - public NBTTagCompound getUserData() + public CompoundNBT getUserData() { if( m_userData == null ) { - m_userData = new NBTTagCompound(); + m_userData = new CompoundNBT(); } return m_userData; } @@ -155,7 +155,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput protected NetworkMessage createTerminalPacket() { - NBTTagCompound tagCompound = new NBTTagCompound(); + CompoundNBT tagCompound = new CompoundNBT(); writeDescription( tagCompound ); return new ComputerTerminalClientMessage( getInstanceID(), tagCompound ); } @@ -174,7 +174,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); NetworkMessage packet = null; - for( EntityPlayer player : server.getPlayerList().getPlayers() ) + for( PlayerEntity player : server.getPlayerList().getPlayers() ) { if( isInteracting( player ) ) { @@ -185,13 +185,13 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput } } - public void sendComputerState( EntityPlayer player ) + public void sendComputerState( PlayerEntity player ) { // Send state to client NetworkHandler.sendToPlayer( player, createComputerPacket() ); } - public void sendTerminalState( EntityPlayer player ) + public void sendTerminalState( PlayerEntity player ) { // Send terminal state to client NetworkHandler.sendToPlayer( player, createTerminalPacket() ); @@ -357,7 +357,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput } @Nullable - public IContainerComputer getContainer( EntityPlayer player ) + public IContainerComputer getContainer( PlayerEntity player ) { if( player == null ) return null; @@ -368,7 +368,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput return computerContainer.getComputer() != this ? null : computerContainer; } - protected boolean isInteracting( EntityPlayer player ) + protected boolean isInteracting( PlayerEntity player ) { return getContainer( player ) != null; } diff --git a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java index deb1f596f..28faa109d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerComputer.java @@ -10,8 +10,8 @@ import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.core.InputState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.Container; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -21,13 +21,14 @@ public class ContainerComputer extends Container implements IContainerComputer private final TileComputer computer; private final InputState input = new InputState( this ); - public ContainerComputer( TileComputer computer ) + public ContainerComputer( int id, TileComputer computer ) { + super( null, id ); this.computer = computer; } @Override - public boolean canInteractWith( @Nonnull EntityPlayer player ) + public boolean canInteractWith( @Nonnull PlayerEntity player ) { return computer.isUsableByPlayer( player ); } @@ -47,7 +48,7 @@ public class ContainerComputer extends Container implements IContainerComputer } @Override - public void onContainerClosed( EntityPlayer player ) + public void onContainerClosed( PlayerEntity player ) { super.onContainerClosed( player ); input.close(); diff --git a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java index 098fc2959..c6f7d8576 100644 --- a/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/inventory/ContainerViewComputer.java @@ -8,21 +8,27 @@ package dan200.computercraft.shared.computer.inventory; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.core.*; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; +import dan200.computercraft.shared.network.container.ContainerData; +import dan200.computercraft.shared.network.container.ViewComputerContainerData; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TranslationTextComponent; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class ContainerViewComputer extends Container implements IContainerComputer { + public static final ContainerType TYPE = ContainerData.create( ViewComputerContainerData::new ); + private final IComputer computer; private final InputState input = new InputState( this ); - public ContainerViewComputer( IComputer computer ) + public ContainerViewComputer( int id, IComputer computer ) { + super( TYPE, id ); this.computer = computer; } @@ -34,7 +40,7 @@ public class ContainerViewComputer extends Container implements IContainerComput } @Override - public boolean canInteractWith( @Nonnull EntityPlayer player ) + public boolean canInteractWith( @Nonnull PlayerEntity player ) { if( computer instanceof ServerComputer ) { @@ -52,18 +58,18 @@ public class ContainerViewComputer extends Container implements IContainerComput MinecraftServer server = player.getServer(); if( server == null || !server.isCommandBlockEnabled() ) { - player.sendStatusMessage( new TextComponentTranslation( "advMode.notEnabled" ), false ); + player.sendStatusMessage( new TranslationTextComponent( "advMode.notEnabled" ), false ); return false; } else if( !player.canUseCommandBlock() ) { - player.sendStatusMessage( new TextComponentTranslation( "advMode.notAllowed" ), false ); + player.sendStatusMessage( new TranslationTextComponent( "advMode.notAllowed" ), false ); return false; } } } - return true; + return computer != null; } @Nonnull @@ -74,7 +80,7 @@ public class ContainerViewComputer extends Container implements IContainerComput } @Override - public void onContainerClosed( EntityPlayer player ) + public void onContainerClosed( PlayerEntity player ) { super.onContainerClosed( 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 d243dc50a..72a9e54cd 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/IComputerItem.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.computer.items; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import javax.annotation.Nonnull; @@ -18,7 +18,7 @@ public interface IComputerItem default int getComputerID( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; } 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 6c36c8ae5..3c113bd9e 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java @@ -9,7 +9,7 @@ package dan200.computercraft.shared.computer.items; import dan200.computercraft.shared.computer.blocks.BlockComputer; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.item.ItemStack; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import javax.annotation.Nonnull; @@ -24,7 +24,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 TextComponentString( label ) ); + if( label != null ) result.setDisplayName( new StringTextComponent( label ) ); 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 377e41959..c082cc443 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java @@ -13,19 +13,19 @@ import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.computer.blocks.BlockComputerBase; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.ItemBlock; +import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; -public abstract class ItemComputerBase extends ItemBlock implements IComputerItem, IMedia +public abstract class ItemComputerBase extends BlockItem implements IComputerItem, IMedia { private final ComputerFamily family; @@ -43,7 +43,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte int id = getComputerID( stack ); if( id >= 0 ) { - list.add( new TextComponentTranslation( "gui.computercraft.tooltip.computer_id", id ) + list.add( new TranslationTextComponent( "gui.computercraft.tooltip.computer_id", id ) .applyTextStyle( TextFormatting.GRAY ) ); } } @@ -68,7 +68,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte { if( label != null ) { - stack.setDisplayName( new TextComponentString( label ) ); + stack.setDisplayName( new StringTextComponent( label ) ); } else { 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 e93f77260..fe319d162 100644 --- a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerConvertRecipe.java +++ b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerConvertRecipe.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.computer.recipe; import dan200.computercraft.shared.computer.items.IComputerItem; -import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.ShapedRecipe; @@ -34,7 +34,7 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe protected abstract ItemStack convert( @Nonnull IComputerItem item, @Nonnull ItemStack stack ); @Override - public boolean matches( @Nonnull IInventory inventory, @Nonnull World world ) + public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world ) { if( !super.matches( inventory, world ) ) return false; @@ -48,7 +48,7 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull IInventory inventory ) + public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) { // Find our computer item and convert it. for( int i = 0; i < inventory.getSizeInventory(); i++ ) 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 3911c3534..fee97cd68 100644 --- a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerFamilyRecipe.java +++ b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerFamilyRecipe.java @@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.Ingredient; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.JsonUtils; +import net.minecraft.util.JSONUtils; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; @@ -42,11 +42,11 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe @Override public T read( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json ) { - String group = JsonUtils.getString( json, "group", "" ); + String group = JSONUtils.getString( json, "group", "" ); ComputerFamily family = RecipeUtil.getFamily( json, "family" ); RecipeUtil.ShapedTemplate template = RecipeUtil.getTemplate( json ); - ItemStack result = deserializeItem( JsonUtils.getJsonObject( json, "result" ) ); + ItemStack result = deserializeItem( JSONUtils.getJsonObject( json, "result" ) ); return create( identifier, group, template.width, template.height, template.ingredients, result, family ); } 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 e7604f2df..6799bc784 100644 --- a/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/computer/recipe/ComputerUpgradeRecipe.java @@ -6,7 +6,6 @@ package dan200.computercraft.shared.computer.recipe; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.IComputerItem; import net.minecraft.item.ItemStack; @@ -38,7 +37,6 @@ public class ComputerUpgradeRecipe extends ComputerFamilyRecipe return SERIALIZER; } - private static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "computer_upgrade" ); public static final IRecipeSerializer SERIALIZER = new Serializer() { @Override @@ -46,12 +44,5 @@ public class ComputerUpgradeRecipe extends ComputerFamilyRecipe { return new ComputerUpgradeRecipe( identifier, group, width, height, ingredients, result, family ); } - - @Nonnull - @Override - public ResourceLocation getName() - { - return ID; - } }; } diff --git a/src/main/java/dan200/computercraft/shared/integration/charset/BundledCapabilityProvider.java b/src/main/java/dan200/computercraft/shared/integration/charset/BundledCapabilityProvider.java index fe478f7c2..6fab2ce31 100644 --- a/src/main/java/dan200/computercraft/shared/integration/charset/BundledCapabilityProvider.java +++ b/src/main/java/dan200/computercraft/shared/integration/charset/BundledCapabilityProvider.java @@ -6,7 +6,7 @@ package dan200.computercraft.shared.integration.charset; import dan200.computercraft.shared.common.TileGeneric; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; import pl.asie.charset.api.wires.IBundledEmitter; @@ -30,14 +30,14 @@ final class BundledCapabilityProvider implements ICapabilityProvider } @Override - public boolean hasCapability( @Nonnull Capability capability, @Nullable EnumFacing side ) + public boolean hasCapability( @Nonnull Capability capability, @Nullable Direction side ) { return capability == CAPABILITY_EMITTER || capability == CAPABILITY_RECEIVER; } @Nullable @Override - public T getCapability( @Nonnull Capability capability, @Nullable EnumFacing side ) + public T getCapability( @Nonnull Capability capability, @Nullable Direction side ) { if( capability == CAPABILITY_RECEIVER ) { @@ -62,7 +62,7 @@ final class BundledCapabilityProvider implements ICapabilityProvider { emitter = emitters[index] = () -> { int flags = 0; - for( EnumFacing facing : EnumFacing.VALUES ) flags |= tile.getBundledRedstoneOutput( facing ); + for( Direction facing : Direction.VALUES ) flags |= tile.getBundledRedstoneOutput( facing ); return toBytes( flags ); }; } diff --git a/src/main/java/dan200/computercraft/shared/integration/charset/BundledRedstoneProvider.java b/src/main/java/dan200/computercraft/shared/integration/charset/BundledRedstoneProvider.java index e7ac4768a..a2a857025 100644 --- a/src/main/java/dan200/computercraft/shared/integration/charset/BundledRedstoneProvider.java +++ b/src/main/java/dan200/computercraft/shared/integration/charset/BundledRedstoneProvider.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.integration.charset; import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -18,7 +18,7 @@ import static dan200.computercraft.shared.integration.charset.IntegrationCharset public class BundledRedstoneProvider implements IBundledRedstoneProvider { @Override - public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) + public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) { TileEntity tile = world.getTileEntity( pos ); if( tile == null || !tile.hasCapability( CAPABILITY_EMITTER, side ) ) return -1; diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPHooks.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPHooks.java index 35c0b47fe..f659971fa 100644 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPHooks.java +++ b/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPHooks.java @@ -8,13 +8,11 @@ package dan200.computercraft.shared.integration.mcmp; import mcmultipart.MCMultiPart; import mcmultipart.api.item.ItemBlockMultipart; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemBlock; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.util.ActionResultType; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.Loader; @@ -27,9 +25,9 @@ public final class MCMPHooks { } - public static EnumActionResult onItemUse( ItemBlock itemBlock, EntityPlayer player, World world, @Nonnull BlockPos pos, @Nonnull EnumHand hand, @Nonnull EnumFacing facing, float hitX, float hitY, float hitZ ) + public static ActionResultType onItemUse( BlockItem itemBlock, PlayerEntity player, World world, @Nonnull BlockPos pos, @Nonnull Hand hand, @Nonnull Direction facing, float hitX, float hitY, float hitZ ) { - if( !Loader.isModLoaded( MCMultiPart.MODID ) ) return EnumActionResult.PASS; + if( !Loader.isModLoaded( MCMultiPart.MODID ) ) return ActionResultType.PASS; return ItemBlockMultipart.place( player, world, pos, hand, facing, hitX, hitY, hitZ, itemBlock, @@ -37,8 +35,8 @@ public final class MCMPHooks MCMPIntegration.multipartMap.get( itemBlock.getBlock() ), ( - ItemStack stack, EntityPlayer thisPlayer, World thisWorld, BlockPos thisPos, EnumFacing thisFacing, - float thisX, float thisY, float thisZ, IBlockState thisState + ItemStack stack, PlayerEntity thisPlayer, World thisWorld, BlockPos thisPos, Direction thisFacing, + float thisX, float thisY, float thisZ, BlockState thisState ) -> thisPlayer.canPlayerEdit( thisPos, thisFacing, stack ) && thisWorld.getBlockState( thisPos ).getBlock().isReplaceable( thisWorld, thisPos ) && diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPIntegration.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPIntegration.java index 358fcda92..d3031c695 100644 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPIntegration.java +++ b/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPIntegration.java @@ -24,7 +24,7 @@ import mcmultipart.api.ref.MCMPCapabilities; import mcmultipart.api.slot.EnumFaceSlot; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.Capability; @@ -105,14 +105,14 @@ public class MCMPIntegration implements IMCMPAddon } @Override - public boolean hasCapability( @Nonnull Capability capability, @Nullable EnumFacing facing ) + public boolean hasCapability( @Nonnull Capability capability, @Nullable Direction facing ) { return capability == MCMPCapabilities.MULTIPART_TILE; } @Nullable @Override - public T getCapability( @Nonnull Capability capability, @Nullable EnumFacing facing ) + public T getCapability( @Nonnull Capability capability, @Nullable Direction facing ) { if( capability == MCMPCapabilities.MULTIPART_TILE ) { diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartAdvancedModem.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/PartAdvancedModem.java index 603ab9575..b220d33e9 100644 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartAdvancedModem.java +++ b/src/main/java/dan200/computercraft/shared/integration/mcmp/PartAdvancedModem.java @@ -12,9 +12,9 @@ import mcmultipart.api.multipart.IMultipart; import mcmultipart.api.slot.EnumFaceSlot; import mcmultipart.api.slot.IPartSlot; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.EnumFacing; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -22,13 +22,13 @@ import net.minecraft.world.World; public class PartAdvancedModem implements IMultipart { @Override - public IPartSlot getSlotForPlacement( World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer ) + public IPartSlot getSlotForPlacement( World world, BlockPos pos, BlockState state, Direction facing, float hitX, float hitY, float hitZ, LivingEntity placer ) { return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) ); } @Override - public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, IBlockState state ) + public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, BlockState state ) { return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) ); } diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartPeripheral.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/PartPeripheral.java index daf25450b..f96572caa 100644 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/integration/mcmp/PartPeripheral.java @@ -14,9 +14,9 @@ import mcmultipart.api.slot.EnumCenterSlot; import mcmultipart.api.slot.EnumFaceSlot; import mcmultipart.api.slot.IPartSlot; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.EnumFacing; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; @@ -26,19 +26,19 @@ import javax.annotation.Nonnull; public class PartPeripheral implements IMultipart { @Override - public IPartSlot getSlotForPlacement( World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer ) + public IPartSlot getSlotForPlacement( World world, BlockPos pos, BlockState state, Direction facing, float hitX, float hitY, float hitZ, LivingEntity placer ) { return getSlot( state ); } @Override - public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, IBlockState state ) + public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, BlockState state ) { return getSlot( state ); } @Nonnull - private static IPartSlot getSlot( IBlockState state ) + private static IPartSlot getSlot( BlockState state ) { BlockPeripheralVariant type = state.getValue( BlockPeripheral.VARIANT ); if( type == BlockPeripheralVariant.WirelessModemUpOn || type == BlockPeripheralVariant.WirelessModemUpOff ) 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 93ff17333..9dce5d77d 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDisk.java @@ -13,17 +13,17 @@ import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.util.Colour; import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; @@ -68,14 +68,14 @@ public class ItemDisk extends Item implements IMedia, IColouredItem int id = getDiskID( stack ); if( id >= 0 ) { - list.add( new TextComponentTranslation( "gui.computercraft.tooltip.disk_id", id ) + list.add( new TranslationTextComponent( "gui.computercraft.tooltip.disk_id", id ) .applyTextStyle( TextFormatting.GRAY ) ); } } } @Override - public boolean doesSneakBypassUse( ItemStack stack, IWorldReader world, BlockPos pos, EntityPlayer player ) + public boolean doesSneakBypassUse( ItemStack stack, IWorldReader world, BlockPos pos, PlayerEntity player ) { return true; } @@ -91,7 +91,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem { if( label != null ) { - stack.setDisplayName( new TextComponentString( label ) ); + stack.setDisplayName( new StringTextComponent( label ) ); } else { @@ -114,7 +114,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem public static int getDiskID( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1; } 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 5c12e84d2..b0a38d1a6 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java @@ -7,17 +7,17 @@ package dan200.computercraft.shared.media.items; import dan200.computercraft.ComputerCraft; -import dan200.computercraft.shared.network.Containers; +import dan200.computercraft.shared.network.container.PrintoutContainerData; import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Hand; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import javax.annotation.Nonnull; @@ -53,15 +53,15 @@ public class ItemPrintout extends Item public void addInformation( @Nonnull ItemStack stack, World world, List list, ITooltipFlag options ) { String title = getTitle( stack ); - if( title != null && !title.isEmpty() ) list.add( new TextComponentString( title ) ); + if( title != null && !title.isEmpty() ) list.add( new StringTextComponent( title ) ); } @Nonnull @Override - public ActionResult onItemRightClick( World world, EntityPlayer player, @Nonnull EnumHand hand ) + public ActionResult onItemRightClick( World world, PlayerEntity player, @Nonnull Hand hand ) { - if( !world.isRemote ) Containers.openPrintoutGUI( player, hand ); - return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) ); + if( !world.isRemote ) new PrintoutContainerData( hand ).open( player ); + return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) ); } @Nonnull @@ -73,7 +73,7 @@ public class ItemPrintout extends Item if( title != null ) stack.getOrCreateTag().putString( NBT_TITLE, title ); if( text != null ) { - NBTTagCompound tag = stack.getOrCreateTag(); + CompoundNBT tag = stack.getOrCreateTag(); tag.putInt( NBT_PAGES, text.length / LINES_PER_PAGE ); for( int i = 0; i < text.length; i++ ) { @@ -82,7 +82,7 @@ public class ItemPrintout extends Item } if( colours != null ) { - NBTTagCompound tag = stack.getOrCreateTag(); + CompoundNBT tag = stack.getOrCreateTag(); for( int i = 0; i < colours.length; i++ ) { if( colours[i] != null ) tag.putString( NBT_LINE_COLOUR + i, colours[i] ); @@ -118,13 +118,13 @@ public class ItemPrintout extends Item public static String getTitle( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : null; } public static int getPageCount( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_PAGES ) ? nbt.getInt( NBT_PAGES ) : 1; } @@ -140,7 +140,7 @@ public class ItemPrintout extends Item private static String[] getLines( @Nonnull ItemStack stack, String prefix ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); int numLines = getPageCount( stack ) * LINES_PER_PAGE; String[] lines = new String[numLines]; for( int i = 0; i < lines.length; i++ ) 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 106d8968e..66251a061 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java @@ -13,15 +13,15 @@ import dan200.computercraft.api.media.IMedia; import dan200.computercraft.core.filesystem.SubMount; import dan200.computercraft.shared.util.Colour; import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; @@ -50,11 +50,11 @@ public class ItemTreasureDisk extends Item implements IMedia public void addInformation( ItemStack stack, @Nullable World world, List list, ITooltipFlag tooltipOptions ) { String label = getTitle( stack ); - if( !label.isEmpty() ) list.add( new TextComponentString( label ) ); + if( !label.isEmpty() ) list.add( new StringTextComponent( label ) ); } @Override - public boolean doesSneakBypassUse( @Nonnull ItemStack stack, IWorldReader world, BlockPos pos, EntityPlayer player ) + public boolean doesSneakBypassUse( @Nonnull ItemStack stack, IWorldReader world, BlockPos pos, PlayerEntity player ) { return true; } @@ -94,7 +94,7 @@ public class ItemTreasureDisk extends Item implements IMedia public static ItemStack create( String subPath, int colourIndex ) { ItemStack result = new ItemStack( ComputerCraft.Items.treasureDisk ); - NBTTagCompound nbt = result.getOrCreateTag(); + CompoundNBT nbt = result.getOrCreateTag(); nbt.putString( NBT_SUB_PATH, subPath ); int slash = subPath.indexOf( '/' ); @@ -121,20 +121,20 @@ public class ItemTreasureDisk extends Item implements IMedia @Nonnull private static String getTitle( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : "'alongtimeago' by dan200"; } @Nonnull private static String getSubPath( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_SUB_PATH ) ? nbt.getString( NBT_SUB_PATH ) : "dan200/alongtimeago"; } public static int getColour( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : Colour.Blue.getHex(); } } 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 c6341bc61..243f57625 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java +++ b/src/main/java/dan200/computercraft/shared/media/items/RecordMedia.java @@ -8,8 +8,8 @@ package dan200.computercraft.shared.media.items; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.util.RecordUtil; -import net.minecraft.item.ItemRecord; import net.minecraft.item.ItemStack; +import net.minecraft.item.MusicDiscItem; import net.minecraft.util.SoundEvent; import javax.annotation.Nonnull; @@ -40,6 +40,6 @@ public final class RecordMedia implements IMedia @Override public SoundEvent getAudio( @Nonnull ItemStack stack ) { - return ((ItemRecord) stack.getItem()).getSound(); + return ((MusicDiscItem) stack.getItem()).getSound(); } } 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 f28bb8f2f..21e8de7d7 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java @@ -6,26 +6,25 @@ package dan200.computercraft.shared.media.recipes; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.media.items.ItemDisk; -import dan200.computercraft.shared.util.AbstractRecipe; import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.ColourTracker; import dan200.computercraft.shared.util.ColourUtils; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.EnumDyeColor; +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.item.DyeColor; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.RecipeSerializers; +import net.minecraft.item.crafting.SpecialRecipe; +import net.minecraft.item.crafting.SpecialRecipeSerializer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.common.Tags; import javax.annotation.Nonnull; -public class DiskRecipe extends AbstractRecipe +public class DiskRecipe extends SpecialRecipe { private final Ingredient paper = Ingredient.fromItems( Items.PAPER ); private final Ingredient redstone = Ingredient.fromTag( Tags.Items.DUSTS_REDSTONE ); @@ -36,7 +35,7 @@ public class DiskRecipe extends AbstractRecipe } @Override - public boolean matches( @Nonnull IInventory inv, @Nonnull World world ) + public boolean matches( @Nonnull CraftingInventory inv, @Nonnull World world ) { boolean paperFound = false; boolean redstoneFound = false; @@ -69,7 +68,7 @@ public class DiskRecipe extends AbstractRecipe @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull IInventory inv ) + public ItemStack getCraftingResult( @Nonnull CraftingInventory inv ) { ColourTracker tracker = new ColourTracker(); @@ -81,7 +80,7 @@ public class DiskRecipe extends AbstractRecipe if( !paper.test( stack ) && !redstone.test( stack ) ) { - EnumDyeColor dye = ColourUtils.getStackColour( stack ); + DyeColor dye = ColourUtils.getStackColour( stack ); if( dye == null ) continue; Colour colour = Colour.VALUES[dye.getId()]; @@ -112,7 +111,5 @@ public class DiskRecipe extends AbstractRecipe return SERIALIZER; } - public static final IRecipeSerializer SERIALIZER = new RecipeSerializers.SimpleSerializer<>( - ComputerCraft.MOD_ID + ":disk", DiskRecipe::new - ); + public static final IRecipeSerializer SERIALIZER = new SpecialRecipeSerializer<>( DiskRecipe::new ); } 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 12c7c3a16..1bd0ddf52 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java @@ -6,24 +6,23 @@ package dan200.computercraft.shared.media.recipes; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.media.items.ItemPrintout; -import dan200.computercraft.shared.util.AbstractRecipe; -import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.RecipeSerializers; +import net.minecraft.item.crafting.SpecialRecipe; +import net.minecraft.item.crafting.SpecialRecipeSerializer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import javax.annotation.Nonnull; -public final class PrintoutRecipe extends AbstractRecipe +public final class PrintoutRecipe extends SpecialRecipe { - private final Ingredient paper = Ingredient.fromItems( Items.PAPER ); - private final Ingredient leather = Ingredient.fromItems( Items.LEATHER ); + 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 PrintoutRecipe( ResourceLocation id ) @@ -45,14 +44,14 @@ public final class PrintoutRecipe extends AbstractRecipe } @Override - public boolean matches( @Nonnull IInventory inventory, @Nonnull World world ) + public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world ) { return !getCraftingResult( inventory ).isEmpty(); } @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull IInventory inventory ) + public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) { // See if we match the recipe, and extract the input disk ID and dye colour int numPages = 0; @@ -165,7 +164,5 @@ public final class PrintoutRecipe extends AbstractRecipe return SERIALIZER; } - public static final IRecipeSerializer SERIALIZER = new RecipeSerializers.SimpleSerializer<>( - ComputerCraft.MOD_ID + ":printout", PrintoutRecipe::new - ); + public static final IRecipeSerializer SERIALIZER = new SpecialRecipeSerializer<>( PrintoutRecipe::new ); } diff --git a/src/main/java/dan200/computercraft/shared/network/Containers.java b/src/main/java/dan200/computercraft/shared/network/Containers.java deleted file mode 100644 index b59b45d16..000000000 --- a/src/main/java/dan200/computercraft/shared/network/Containers.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.network; - -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.shared.common.ContainerHeldItem; -import dan200.computercraft.shared.computer.blocks.TileComputer; -import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.computer.inventory.ContainerComputer; -import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; -import dan200.computercraft.shared.media.items.ItemPrintout; -import dan200.computercraft.shared.network.container.*; -import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; -import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive; -import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; -import dan200.computercraft.shared.peripheral.printer.TilePrinter; -import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; -import dan200.computercraft.shared.pocket.items.ItemPocketComputer; -import dan200.computercraft.shared.turtle.blocks.TileTurtle; -import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumHand; - -public final class Containers -{ - private Containers() - { - } - - public static void openDiskDriveGUI( EntityPlayer player, TileDiskDrive drive ) - { - TileEntityContainerType.diskDrive( drive.getPos() ).open( player ); - } - - public static void openComputerGUI( EntityPlayer player, TileComputer computer ) - { - TileEntityContainerType.computer( computer.getPos() ).open( player ); - } - - public static void openPrinterGUI( EntityPlayer player, TilePrinter printer ) - { - TileEntityContainerType.printer( printer.getPos() ).open( player ); - } - - public static void openTurtleGUI( EntityPlayer player, TileTurtle turtle ) - { - TileEntityContainerType.turtle( turtle.getPos() ).open( player ); - } - - public static void openPrintoutGUI( EntityPlayer player, EnumHand hand ) - { - ItemStack stack = player.getHeldItem( hand ); - Item item = stack.getItem(); - if( !(item instanceof ItemPrintout) ) return; - - new PrintoutContainerType( hand ).open( player ); - } - - public static void openPocketComputerGUI( EntityPlayer player, EnumHand hand ) - { - ItemStack stack = player.getHeldItem( hand ); - Item item = stack.getItem(); - if( !(item instanceof ItemPocketComputer) ) return; - - new PocketComputerContainerType( hand ).open( player ); - } - - public static void openComputerGUI( EntityPlayer player, ServerComputer computer ) - { - new ViewComputerContainerType( computer ).open( player ); - } - - public static void setup() - { - ContainerType.register( TileEntityContainerType::computer, ( packet, player ) -> - new ContainerComputer( (TileComputer) packet.getTileEntity( player ) ) ); - ContainerType.register( TileEntityContainerType::turtle, ( packet, player ) -> { - TileTurtle turtle = (TileTurtle) packet.getTileEntity( player ); - return new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getServerComputer() ); - } ); - ContainerType.register( TileEntityContainerType::diskDrive, ( packet, player ) -> - new ContainerDiskDrive( player.inventory, (TileDiskDrive) packet.getTileEntity( player ) ) ); - ContainerType.register( TileEntityContainerType::printer, ( packet, player ) -> - new ContainerPrinter( player.inventory, (TilePrinter) packet.getTileEntity( player ) ) ); - - ContainerType.register( PocketComputerContainerType::new, ( packet, player ) -> new ContainerPocketComputer( player, packet.hand ) ); - ContainerType.register( PrintoutContainerType::new, ( packet, player ) -> new ContainerHeldItem( player, packet.hand ) ); - ContainerType.register( ViewComputerContainerType::new, ( packet, player ) -> new ContainerViewComputer( ComputerCraft.serverComputerRegistry.get( packet.instanceId ) ) ); - } -} diff --git a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java index 4afe60ce5..fb628b11c 100644 --- a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java +++ b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java @@ -9,8 +9,8 @@ package dan200.computercraft.shared.network; import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.network.client.*; import dan200.computercraft.shared.network.server.*; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec3d; @@ -55,14 +55,14 @@ public final class NetworkHandler registerMainThread( 14, PlayRecordClientMessage.class, PlayRecordClientMessage::new ); } - public static void sendToPlayer( EntityPlayer player, NetworkMessage packet ) + public static void sendToPlayer( PlayerEntity player, NetworkMessage packet ) { - network.sendTo( packet, ((EntityPlayerMP) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT ); + network.sendTo( packet, ((ServerPlayerEntity) player).connection.netManager, NetworkDirection.PLAY_TO_CLIENT ); } public static void sendToAllPlayers( NetworkMessage packet ) { - for( EntityPlayerMP player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() ) + for( ServerPlayerEntity player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() ) { sendToPlayer( player, packet ); } @@ -75,7 +75,7 @@ public final class NetworkHandler public static void sendToAllAround( NetworkMessage packet, World world, Vec3d pos, double range ) { - for( EntityPlayerMP player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() ) + for( ServerPlayerEntity player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() ) { if( player.getEntityWorld() != world ) continue; 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 77cf5605e..bc0420947 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/ComputerDataClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/ComputerDataClientMessage.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.network.client; import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ServerComputer; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent; @@ -20,7 +20,7 @@ import javax.annotation.Nonnull; public class ComputerDataClientMessage extends ComputerClientMessage { private ComputerState state; - private NBTTagCompound userData; + private CompoundNBT userData; public ComputerDataClientMessage( ServerComputer computer ) { diff --git a/src/main/java/dan200/computercraft/shared/network/client/ComputerTerminalClientMessage.java b/src/main/java/dan200/computercraft/shared/network/client/ComputerTerminalClientMessage.java index 914101143..ac3d0495a 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/ComputerTerminalClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/ComputerTerminalClientMessage.java @@ -6,7 +6,7 @@ package dan200.computercraft.shared.network.client; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent; @@ -14,9 +14,9 @@ import javax.annotation.Nonnull; public class ComputerTerminalClientMessage extends ComputerClientMessage { - private NBTTagCompound tag; + private CompoundNBT tag; - public ComputerTerminalClientMessage( int instanceId, NBTTagCompound tag ) + public ComputerTerminalClientMessage( int instanceId, CompoundNBT tag ) { super( instanceId ); this.tag = tag; 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 737468d09..822d6fe29 100644 --- a/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java +++ b/src/main/java/dan200/computercraft/shared/network/client/PlayRecordClientMessage.java @@ -82,7 +82,7 @@ public class PlayRecordClientMessage implements NetworkMessage public void handle( NetworkEvent.Context context ) { Minecraft mc = Minecraft.getInstance(); - mc.world.playRecord( pos, soundEvent ); - if( name != null ) mc.ingameGUI.setRecordPlayingMessage( name ); + mc.worldRenderer.playRecord( soundEvent, pos ); + if( name != null ) mc.field_71456_v.setRecordPlayingMessage( name ); } } diff --git a/src/main/java/dan200/computercraft/shared/network/container/ContainerData.java b/src/main/java/dan200/computercraft/shared/network/container/ContainerData.java new file mode 100644 index 000000000..edfa91965 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/network/container/ContainerData.java @@ -0,0 +1,41 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.network.container; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.fml.network.NetworkHooks; + +import javax.annotation.Nonnull; +import java.util.function.Function; + +/** + * A horrible hack to allow opening GUIs until Forge adds a built-in system. + */ +public interface ContainerData extends INamedContainerProvider +{ + void toBytes( PacketBuffer buf ); + + default void open( PlayerEntity player ) + { + NetworkHooks.openGui( (ServerPlayerEntity) player, this, this::toBytes ); + } + + @Nonnull + T createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player ); + + static > net.minecraft.inventory.container.ContainerType create( Function reader ) + { + return new net.minecraft.inventory.container.ContainerType<>( + ( id, player ) -> reader.apply( null ).createMenu( id, player, player.player ) + ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/network/container/ContainerType.java b/src/main/java/dan200/computercraft/shared/network/container/ContainerType.java deleted file mode 100644 index 27ca78681..000000000 --- a/src/main/java/dan200/computercraft/shared/network/container/ContainerType.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.network.container; - -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.world.IInteractionObject; -import net.minecraftforge.fml.network.NetworkHooks; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * A horrible hack to allow opening GUIs until Forge adds a built-in system. - */ -public interface ContainerType extends IInteractionObject -{ - @Nonnull - ResourceLocation getId(); - - void toBytes( PacketBuffer buf ); - - void fromBytes( PacketBuffer buf ); - - @Nonnull - @Override - @SuppressWarnings( "unchecked" ) - default T createContainer( @Nonnull InventoryPlayer inventoryPlayer, @Nonnull EntityPlayer entityPlayer ) - { - return ((BiFunction, EntityPlayer, T>) containerFactories.get( getId() )).apply( this, entityPlayer ); - } - - @Nonnull - @Override - default String getGuiID() - { - return getId().toString(); - } - - @Nonnull - @Override - default ITextComponent getName() - { - return new TextComponentString( "" ); - } - - @Override - default boolean hasCustomName() - { - return false; - } - - @Nullable - @Override - default ITextComponent getCustomName() - { - return null; - } - - default void open( EntityPlayer player ) - { - NetworkHooks.openGui( (EntityPlayerMP) player, this, this::toBytes ); - } - - static > void register( Supplier containerType, BiFunction factory ) - { - factories.put( containerType.get().getId(), containerType ); - containerFactories.put( containerType.get().getId(), factory ); - } - - static > void registerGui( Supplier containerType, BiFunction factory ) - { - guiFactories.put( containerType.get().getId(), factory ); - } - - static > void registerGui( Supplier containerType, Function factory ) - { - registerGui( containerType, ( type, player ) -> { - @SuppressWarnings( "unchecked" ) - C container = ((BiFunction) containerFactories.get( type.getId() )).apply( type, player ); - return container == null ? null : factory.apply( container ); - } ); - } - - Map>> factories = new HashMap<>(); - Map, EntityPlayer, GuiContainer>> guiFactories = new HashMap<>(); - Map, EntityPlayer, ? extends Container>> containerFactories = new HashMap<>(); -} diff --git a/src/main/java/dan200/computercraft/shared/network/container/PocketComputerContainerData.java b/src/main/java/dan200/computercraft/shared/network/container/PocketComputerContainerData.java new file mode 100644 index 000000000..b1cc11093 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/network/container/PocketComputerContainerData.java @@ -0,0 +1,57 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.network.container; + +import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.Hand; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; + +import javax.annotation.Nonnull; + +/** + * Opens a pocket computer GUI based on the held item + * + * @see dan200.computercraft.shared.pocket.items.ItemPocketComputer + */ +public class PocketComputerContainerData implements ContainerData +{ + private final Hand hand; + + public PocketComputerContainerData( Hand hand ) + { + this.hand = hand; + } + + public PocketComputerContainerData( PacketBuffer buffer ) + { + hand = buffer.readEnumValue( Hand.class ); + } + + @Override + public void toBytes( @Nonnull PacketBuffer buf ) + { + buf.writeEnumValue( hand ); + } + + @Nonnull + @Override + public ITextComponent getDisplayName() + { + return new TranslationTextComponent( "gui.computercraft.pocket" ); + } + + @Nonnull + @Override + public ContainerPocketComputer createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player ) + { + return new ContainerPocketComputer( id, player, hand ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/network/container/PocketComputerContainerType.java b/src/main/java/dan200/computercraft/shared/network/container/PocketComputerContainerType.java deleted file mode 100644 index 859b369aa..000000000 --- a/src/main/java/dan200/computercraft/shared/network/container/PocketComputerContainerType.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.network.container; - -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; - -import javax.annotation.Nonnull; - -/** - * Opens a pocket computer GUI based on the held item - * - * @see dan200.computercraft.shared.pocket.items.ItemPocketComputer - */ -public class PocketComputerContainerType implements ContainerType -{ - public static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "pocket_computer_gui" ); - - public EnumHand hand; - - public PocketComputerContainerType( EnumHand hand ) - { - this.hand = hand; - } - - public PocketComputerContainerType() - { - } - - @Nonnull - @Override - public ResourceLocation getId() - { - return ID; - } - - @Override - public void toBytes( @Nonnull PacketBuffer buf ) - { - buf.writeEnumValue( hand ); - } - - @Override - public void fromBytes( @Nonnull PacketBuffer buf ) - { - hand = buf.readEnumValue( EnumHand.class ); - } -} diff --git a/src/main/java/dan200/computercraft/shared/network/container/PrintoutContainerData.java b/src/main/java/dan200/computercraft/shared/network/container/PrintoutContainerData.java new file mode 100644 index 000000000..48d58c74d --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/network/container/PrintoutContainerData.java @@ -0,0 +1,57 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.network.container; + +import dan200.computercraft.shared.common.ContainerHeldItem; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.Hand; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; + +import javax.annotation.Nonnull; + +/** + * Opens a printout GUI based on the currently held item + * + * @see dan200.computercraft.shared.media.items.ItemPrintout + */ +public class PrintoutContainerData implements ContainerData +{ + private final Hand hand; + + public PrintoutContainerData( Hand hand ) + { + this.hand = hand; + } + + public PrintoutContainerData( PacketBuffer buffer ) + { + hand = buffer.readEnumValue( Hand.class ); + } + + @Override + public void toBytes( PacketBuffer buf ) + { + buf.writeEnumValue( hand ); + } + + @Nonnull + @Override + public ITextComponent getDisplayName() + { + return new TranslationTextComponent( "gui.computercraft.printout" ); + } + + @Nonnull + @Override + public ContainerHeldItem createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player ) + { + return new ContainerHeldItem( ContainerHeldItem.PRINTOUT_TYPE, id, player, hand ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/network/container/PrintoutContainerType.java b/src/main/java/dan200/computercraft/shared/network/container/PrintoutContainerType.java deleted file mode 100644 index b89244d75..000000000 --- a/src/main/java/dan200/computercraft/shared/network/container/PrintoutContainerType.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.network.container; - -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.shared.common.ContainerHeldItem; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.EnumHand; -import net.minecraft.util.ResourceLocation; - -import javax.annotation.Nonnull; - -/** - * Opens a printout GUI based on the currently held item - * - * @see dan200.computercraft.shared.media.items.ItemPrintout - */ -public class PrintoutContainerType implements ContainerType -{ - public static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "printout_gui" ); - - public EnumHand hand; - - public PrintoutContainerType( EnumHand hand ) - { - this.hand = hand; - } - - public PrintoutContainerType() - { - } - - @Nonnull - @Override - public ResourceLocation getId() - { - return ID; - } - - @Override - public void toBytes( @Nonnull PacketBuffer buf ) - { - buf.writeEnumValue( hand ); - } - - @Override - public void fromBytes( @Nonnull PacketBuffer buf ) - { - hand = buf.readEnumValue( EnumHand.class ); - } -} diff --git a/src/main/java/dan200/computercraft/shared/network/container/TileEntityContainerType.java b/src/main/java/dan200/computercraft/shared/network/container/TileEntityContainerType.java deleted file mode 100644 index 48185e1b5..000000000 --- a/src/main/java/dan200/computercraft/shared/network/container/TileEntityContainerType.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.network.container; - -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.shared.computer.inventory.ContainerComputer; -import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; -import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; -import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; - -import javax.annotation.Nonnull; - -/** - * Opens a GUI on a specific ComputerCraft TileEntity - * - * @see dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive - * @see dan200.computercraft.shared.peripheral.printer.TilePrinter - * @see dan200.computercraft.shared.computer.blocks.TileComputer - */ -public final class TileEntityContainerType implements ContainerType -{ - private static final ResourceLocation DISK_DRIVE = new ResourceLocation( ComputerCraft.MOD_ID, "disk_drive" ); - private static final ResourceLocation PRINTER = new ResourceLocation( ComputerCraft.MOD_ID, "printer" ); - private static final ResourceLocation COMPUTER = new ResourceLocation( ComputerCraft.MOD_ID, "computer" ); - private static final ResourceLocation TURTLE = new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ); - - public BlockPos pos; - private final ResourceLocation id; - - private TileEntityContainerType( ResourceLocation id, BlockPos pos ) - { - this.id = id; - this.pos = pos; - } - - private TileEntityContainerType( ResourceLocation id ) - { - this.id = id; - } - - @Nonnull - @Override - public ResourceLocation getId() - { - return id; - } - - @Override - public void toBytes( PacketBuffer buf ) - { - buf.writeBlockPos( pos ); - } - - @Override - public void fromBytes( PacketBuffer buf ) - { - pos = buf.readBlockPos(); - } - - public TileEntity getTileEntity( EntityPlayer entity ) - { - return entity.world.getTileEntity( pos ); - } - - public static TileEntityContainerType diskDrive() - { - return new TileEntityContainerType<>( DISK_DRIVE ); - } - - public static TileEntityContainerType diskDrive( BlockPos pos ) - { - return new TileEntityContainerType<>( DISK_DRIVE, pos ); - } - - public static TileEntityContainerType printer() - { - return new TileEntityContainerType<>( PRINTER ); - } - - public static TileEntityContainerType printer( BlockPos pos ) - { - return new TileEntityContainerType<>( PRINTER, pos ); - } - - public static TileEntityContainerType computer() - { - return new TileEntityContainerType<>( COMPUTER ); - } - - public static TileEntityContainerType computer( BlockPos pos ) - { - return new TileEntityContainerType<>( COMPUTER, pos ); - } - - public static TileEntityContainerType turtle() - { - return new TileEntityContainerType<>( TURTLE ); - } - - public static TileEntityContainerType turtle( BlockPos pos ) - { - return new TileEntityContainerType<>( TURTLE, pos ); - } -} diff --git a/src/main/java/dan200/computercraft/shared/network/container/ViewComputerContainerType.java b/src/main/java/dan200/computercraft/shared/network/container/ViewComputerContainerData.java similarity index 54% rename from src/main/java/dan200/computercraft/shared/network/container/ViewComputerContainerType.java rename to src/main/java/dan200/computercraft/shared/network/container/ViewComputerContainerData.java index ff541796a..adadcc8e7 100644 --- a/src/main/java/dan200/computercraft/shared/network/container/ViewComputerContainerType.java +++ b/src/main/java/dan200/computercraft/shared/network/container/ViewComputerContainerData.java @@ -9,10 +9,15 @@ package dan200.computercraft.shared.network.container; import dan200.computercraft.ComputerCraft; import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TranslationTextComponent; import javax.annotation.Nonnull; @@ -21,16 +26,16 @@ import javax.annotation.Nonnull; * * @see dan200.computercraft.shared.command.CommandComputerCraft */ -public class ViewComputerContainerType implements ContainerType +public class ViewComputerContainerData implements ContainerData { public static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "view_computer_gui" ); - public int instanceId; - public int width; - public int height; - public ComputerFamily family; + private final int instanceId; + private final int width; + private final int height; + private final ComputerFamily family; - public ViewComputerContainerType( ServerComputer computer ) + public ViewComputerContainerData( ServerComputer computer ) { instanceId = computer.getInstanceID(); Terminal terminal = computer.getTerminal(); @@ -39,18 +44,19 @@ public class ViewComputerContainerType implements ContainerType properties ) + protected void fillStateContainer( StateContainer.Builder properties ) { properties.add( FACING, STATE ); } @Nullable @Override - public IBlockState getStateForPlacement( BlockItemUseContext placement ) + public BlockState getStateForPlacement( BlockItemUseContext placement ) { return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); } @Override - public void harvestBlock( @Nonnull World world, EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nullable TileEntity te, ItemStack stack ) + public void harvestBlock( @Nonnull World world, PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, ItemStack stack ) { if( te instanceof INameable && ((INameable) te).hasCustomName() ) { - player.addStat( StatList.BLOCK_MINED.get( this ) ); + player.addStat( Stats.BLOCK_MINED.get( this ) ); player.addExhaustion( 0.005F ); ItemStack result = new ItemStack( this ); @@ -73,7 +73,7 @@ public class BlockDiskDrive extends BlockGeneric } @Override - public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack ) + public void onBlockPlacedBy( World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack ) { if( stack.hasDisplayName() ) { 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 bde384e18..dcef9ae3d 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/ContainerDiskDrive.java @@ -6,51 +6,59 @@ package dan200.computercraft.shared.peripheral.diskdrive; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; +import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; public class ContainerDiskDrive extends Container { - private final TileDiskDrive m_diskDrive; + public static final ContainerType TYPE = new ContainerType<>( ContainerDiskDrive::new ); - public ContainerDiskDrive( IInventory playerInventory, TileDiskDrive diskDrive ) + private final IInventory inventory; + + public ContainerDiskDrive( int id, PlayerInventory player, IInventory inventory ) { - m_diskDrive = diskDrive; - addSlot( new Slot( m_diskDrive, 0, 8 + 4 * 18, 35 ) ); + super( TYPE, id ); + + this.inventory = inventory; + + addSlot( new Slot( this.inventory, 0, 8 + 4 * 18, 35 ) ); for( int y = 0; y < 3; y++ ) { for( int x = 0; x < 9; x++ ) { - addSlot( new Slot( playerInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18 ) ); + addSlot( new Slot( player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18 ) ); } } for( int x = 0; x < 9; x++ ) { - addSlot( new Slot( playerInventory, x, 8 + x * 18, 142 ) ); + addSlot( new Slot( player, x, 8 + x * 18, 142 ) ); } } - public TileDiskDrive getDiskDrive() + private ContainerDiskDrive( int id, PlayerInventory player ) { - return m_diskDrive; + this( id, player, new Inventory( 1 ) ); } @Override - public boolean canInteractWith( @Nonnull EntityPlayer player ) + public boolean canInteractWith( @Nonnull PlayerEntity player ) { - return m_diskDrive.isUsableByPlayer( player ); + return inventory.isUsableByPlayer( player ); } @Nonnull @Override - public ItemStack transferStackInSlot( EntityPlayer player, int slotIndex ) + public ItemStack transferStackInSlot( PlayerEntity player, int slotIndex ) { Slot slot = inventorySlots.get( slotIndex ); if( slot == null || !slot.getHasStack() ) return ItemStack.EMPTY; 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 09f534730..2eb317d78 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/TileDiskDrive.java @@ -15,21 +15,27 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheralTile; import dan200.computercraft.shared.MediaProviders; import dan200.computercraft.shared.common.TileGeneric; -import dan200.computercraft.shared.network.Containers; import dan200.computercraft.shared.util.DefaultInventory; import dan200.computercraft.shared.util.InventoryUtil; -import dan200.computercraft.shared.util.NamedBlockEntityType; +import dan200.computercraft.shared.util.NamedTileEntityType; import dan200.computercraft.shared.util.RecordUtil; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.block.BlockState; +import net.minecraft.entity.item.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.wrapper.InvWrapper; @@ -41,12 +47,12 @@ import java.util.Set; import static net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; -public final class TileDiskDrive extends TileGeneric implements DefaultInventory, ITickable, IPeripheralTile +public final class TileDiskDrive extends TileGeneric implements DefaultInventory, ITickableTileEntity, IPeripheralTile, INameable, INamedContainerProvider { private static final String NBT_NAME = "CustomName"; private static final String NBT_ITEM = "Item"; - public static final NamedBlockEntityType FACTORY = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "disk_drive" ), TileDiskDrive::new ); @@ -94,7 +100,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory } @Override - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { if( player.isSneaking() ) { @@ -111,24 +117,24 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory else { // Open the GUI - if( !getWorld().isRemote ) Containers.openDiskDriveGUI( player, this ); + if( !getWorld().isRemote ) NetworkHooks.openGui( (ServerPlayerEntity) player, this ); return true; } } - public EnumFacing getDirection() + public Direction getDirection() { return getBlockState().get( BlockDiskDrive.FACING ); } @Override - public void read( NBTTagCompound nbt ) + public void read( CompoundNBT nbt ) { super.read( nbt ); customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; if( nbt.contains( NBT_ITEM ) ) { - NBTTagCompound item = nbt.getCompound( NBT_ITEM ); + CompoundNBT item = nbt.getCompound( NBT_ITEM ); m_diskStack = ItemStack.read( item ); m_diskMount = null; } @@ -136,13 +142,13 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory @Nonnull @Override - public NBTTagCompound write( NBTTagCompound nbt ) + public CompoundNBT write( CompoundNBT nbt ) { if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); if( !m_diskStack.isEmpty() ) { - NBTTagCompound item = new NBTTagCompound(); + CompoundNBT item = new CompoundNBT(); m_diskStack.write( item ); nbt.put( NBT_ITEM, item ); } @@ -295,7 +301,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory } @Override - public boolean isUsableByPlayer( @Nonnull EntityPlayer player ) + public boolean isUsableByPlayer( @Nonnull PlayerEntity player ) { return isUsable( player, false ); } @@ -307,7 +313,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory } @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { return new DiskDrivePeripheral( this ); } @@ -467,7 +473,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory private void updateBlockState( DiskDriveState state ) { - IBlockState blockState = getBlockState(); + BlockState blockState = getBlockState(); if( blockState.get( BlockDiskDrive.STATE ) == state ) return; getWorld().setBlockState( getPos(), blockState.with( BlockDiskDrive.STATE, state ) ); @@ -486,7 +492,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory int zOff = 0; if( !destroyed ) { - EnumFacing dir = getDirection(); + Direction dir = getDirection(); xOff = dir.getXOffset(); zOff = dir.getZOffset(); } @@ -495,17 +501,15 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory double x = pos.getX() + 0.5 + xOff * 0.5; double y = pos.getY() + 0.75; double z = pos.getZ() + 0.5 + zOff * 0.5; - EntityItem entityitem = new EntityItem( getWorld(), x, y, z, disks ); - entityitem.motionX = xOff * 0.15; - entityitem.motionY = 0.0; - entityitem.motionZ = zOff * 0.15; + ItemEntity entityitem = new ItemEntity( getWorld(), x, y, z, disks ); + entityitem.setVelocity( xOff * 0.15, 0, zOff * 0.15 ); - getWorld().spawnEntity( entityitem ); + getWorld().func_217376_c( entityitem ); if( !destroyed ) getWorld().playBroadcastSound( 1000, getPos(), 0 ); } @Override - protected void readDescription( @Nonnull NBTTagCompound nbt ) + protected void readDescription( @Nonnull CompoundNBT nbt ) { super.readDescription( nbt ); customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; @@ -514,13 +518,13 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory } @Override - protected void writeDescription( @Nonnull NBTTagCompound nbt ) + protected void writeDescription( @Nonnull CompoundNBT nbt ) { super.writeDescription( nbt ); if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); if( !m_diskStack.isEmpty() ) { - NBTTagCompound item = new NBTTagCompound(); + CompoundNBT item = new CompoundNBT(); m_diskStack.write( item ); nbt.put( NBT_ITEM, item ); } @@ -549,7 +553,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory @Nonnull @Override - public LazyOptional getCapability( @Nonnull Capability cap, @Nullable final EnumFacing side ) + public LazyOptional getCapability( @Nonnull Capability cap, @Nullable final Direction side ) { if( cap == ITEM_HANDLER_CAPABILITY ) { @@ -578,4 +582,17 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory { return customName != null ? customName : getBlockState().getBlock().getNameTextComponent(); } + + @Override + public ITextComponent getDisplayName() + { + return getName(); + } + + @Nonnull + @Override + public Container createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player ) + { + return new ContainerDiskDrive( id, inventory, this ); + } } 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 697ab044c..4aab12684 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemShapes.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/ModemShapes.java @@ -6,7 +6,7 @@ package dan200.computercraft.shared.peripheral.modem; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; @@ -24,7 +24,7 @@ public final class ModemShapes }; @Nonnull - public static VoxelShape getBounds( EnumFacing facing ) + public static VoxelShape getBounds( Direction facing ) { int direction = facing.ordinal(); return direction < BOXES.length ? BOXES[direction] : VoxelShapes.fullCube(); 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 3de458af3..e0f5d8e83 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 @@ -10,13 +10,12 @@ import com.google.common.collect.ImmutableMap; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.shared.common.BlockGeneric; -import dan200.computercraft.shared.util.WaterloggableBlock; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.block.Block; -import net.minecraft.block.state.BlockFaceShape; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.block.BlockState; +import net.minecraft.block.IWaterLoggable; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.IFluidState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; @@ -24,21 +23,25 @@ import net.minecraft.state.BooleanProperty; import net.minecraft.state.EnumProperty; import net.minecraft.state.StateContainer; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.RayTraceContext; import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; -import net.minecraft.world.IWorldReaderBase; +import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.EnumMap; -public class BlockCable extends BlockGeneric implements WaterloggableBlock +import static dan200.computercraft.shared.util.WaterloggableHelpers.*; + +public class BlockCable extends BlockGeneric implements IWaterLoggable { public static final EnumProperty MODEM = EnumProperty.create( "modem", CableModemVariant.class ); public static final BooleanProperty CABLE = BooleanProperty.create( "cable" ); @@ -50,11 +53,11 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock private static final BooleanProperty UP = BooleanProperty.create( "up" ); private static final BooleanProperty DOWN = BooleanProperty.create( "down" ); - static final EnumMap CONNECTIONS = - new EnumMap<>( new ImmutableMap.Builder() - .put( EnumFacing.DOWN, DOWN ).put( EnumFacing.UP, UP ) - .put( EnumFacing.NORTH, NORTH ).put( EnumFacing.SOUTH, SOUTH ) - .put( EnumFacing.WEST, WEST ).put( EnumFacing.EAST, EAST ) + static final EnumMap CONNECTIONS = + new EnumMap<>( new ImmutableMap.Builder() + .put( Direction.DOWN, DOWN ).put( Direction.UP, UP ) + .put( Direction.NORTH, NORTH ).put( Direction.SOUTH, SOUTH ) + .put( Direction.WEST, WEST ).put( Direction.EAST, EAST ) .build() ); public BlockCable( Properties settings ) @@ -72,17 +75,17 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void fillStateContainer( StateContainer.Builder builder ) { builder.add( MODEM, CABLE, NORTH, SOUTH, EAST, WEST, UP, DOWN, WATERLOGGED ); } - public static boolean canConnectIn( IBlockState state, EnumFacing direction ) + public static boolean canConnectIn( BlockState state, Direction direction ) { return state.get( BlockCable.CABLE ) && state.get( BlockCable.MODEM ).getFacing() != direction; } - public static boolean doesConnectVisually( IBlockState state, IBlockReader world, BlockPos pos, EnumFacing 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; @@ -92,18 +95,21 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock @Nonnull @Override @Deprecated - public VoxelShape getShape( IBlockState state, IBlockReader world, BlockPos pos ) + public VoxelShape getShape( BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context ) { return CableShapes.getShape( state ); } @Override - public boolean removedByPlayer( IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest, IFluidState fluid ) + public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid ) { if( state.get( CABLE ) && state.get( MODEM ).getFacing() != null ) { - RayTraceResult hit = Block.collisionRayTrace( state, world, pos, WorldUtil.getRayStart( player ), WorldUtil.getRayEnd( player ) ); - if( hit != null ) + BlockRayTraceResult hit = world.func_217299_a( 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() ) @@ -111,9 +117,9 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock TileCable cable = (TileCable) tile; ItemStack item; - IBlockState newState; + BlockState newState; - if( WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ) + if( WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ) { newState = state.with( MODEM, CableModemVariant.None ); item = new ItemStack( ComputerCraft.Items.wiredModem ); @@ -128,7 +134,7 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock cable.modemChanged(); cable.connectionsChanged(); - if( !world.isRemote && !player.abilities.isCreativeMode ) + if( !world.isRemote && !player.playerAbilities.isCreativeMode ) { Block.spawnAsEntity( world, pos, item ); } @@ -141,18 +147,11 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock return super.removedByPlayer( state, world, pos, player, willHarvest, fluid ); } - @Override - public void getDrops( IBlockState state, NonNullList drops, World world, BlockPos pos, int fortune ) - { - if( state.get( CABLE ) ) drops.add( new ItemStack( ComputerCraft.Items.cable ) ); - if( state.get( MODEM ) != CableModemVariant.None ) drops.add( new ItemStack( ComputerCraft.Items.cable ) ); - } - @Nonnull @Override - public ItemStack getPickBlock( IBlockState state, RayTraceResult hit, IBlockReader world, BlockPos pos, EntityPlayer player ) + public ItemStack getPickBlock( BlockState state, RayTraceResult hit, IBlockReader world, BlockPos pos, PlayerEntity player ) { - EnumFacing modem = state.get( MODEM ).getFacing(); + Direction modem = state.get( MODEM ).getFacing(); boolean cable = state.get( CABLE ); // If we've only got one, just use that. @@ -160,14 +159,14 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock if( modem == null ) return new ItemStack( ComputerCraft.Items.cable ); // 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.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) + return hit != null && WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) ) ? new ItemStack( ComputerCraft.Items.wiredModem ) : new ItemStack( ComputerCraft.Items.cable ); } @Override - public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack ) + public void onBlockPlacedBy( World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack ) { TileEntity tile = world.getTileEntity( pos ); if( tile instanceof TileCable ) @@ -182,7 +181,7 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock @Nonnull @Override @Deprecated - public IFluidState getFluidState( IBlockState state ) + public IFluidState getFluidState( BlockState state ) { return getWaterloggedFluidState( state ); } @@ -190,7 +189,7 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock @Nonnull @Override @Deprecated - public IBlockState updatePostPlacement( @Nonnull IBlockState state, EnumFacing side, IBlockState otherState, IWorld world, BlockPos pos, BlockPos otherPos ) + public BlockState updatePostPlacement( @Nonnull BlockState state, Direction side, BlockState otherState, IWorld world, BlockPos pos, BlockPos otherPos ) { updateWaterloggedPostPlacement( state, world, pos ); // Should never happen, but handle the case where we've no modem or cable. @@ -204,21 +203,21 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock @Override @Deprecated - public boolean isValidPosition( IBlockState state, IWorldReaderBase world, BlockPos pos ) + public boolean isValidPosition( BlockState state, IWorldReader world, BlockPos pos ) { - EnumFacing facing = state.get( MODEM ).getFacing(); + Direction facing = state.get( MODEM ).getFacing(); if( facing == null ) return true; BlockPos offsetPos = pos.offset( facing ); - IBlockState offsetState = world.getBlockState( offsetPos ); - return offsetState.getBlockFaceShape( world, offsetPos, facing.getOpposite() ) == BlockFaceShape.SOLID; + BlockState offsetState = world.getBlockState( offsetPos ); + return Block.func_220056_d( offsetState, world, offsetPos, facing.getOpposite() ); // hasSolidTop ?? } @Nullable @Override - public IBlockState getStateForPlacement( BlockItemUseContext context ) + public BlockState getStateForPlacement( BlockItemUseContext context ) { - IBlockState state = getDefaultState() + BlockState state = getDefaultState() .with( WATERLOGGED, getWaterloggedStateForPlacement( context ) ); if( context.getItem().getItem() instanceof ItemBlockCable.Cable ) @@ -233,17 +232,17 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock } } - public static IBlockState correctConnections( World world, BlockPos pos, IBlockState state ) + public static BlockState correctConnections( World world, BlockPos pos, BlockState state ) { if( state.get( CABLE ) ) { return state - .with( NORTH, doesConnectVisually( state, world, pos, EnumFacing.NORTH ) ) - .with( SOUTH, doesConnectVisually( state, world, pos, EnumFacing.SOUTH ) ) - .with( EAST, doesConnectVisually( state, world, pos, EnumFacing.EAST ) ) - .with( WEST, doesConnectVisually( state, world, pos, EnumFacing.WEST ) ) - .with( UP, doesConnectVisually( state, world, pos, EnumFacing.UP ) ) - .with( DOWN, doesConnectVisually( state, world, pos, EnumFacing.DOWN ) ); + .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 ) ); } else { @@ -255,23 +254,7 @@ public class BlockCable extends BlockGeneric implements WaterloggableBlock @Override @Deprecated - public final boolean isFullCube( IBlockState state ) - { - return false; - } - - - @Nonnull - @Override - @Deprecated - public BlockFaceShape getBlockFaceShape( IBlockReader worldIn, IBlockState state, BlockPos pos, EnumFacing face ) - { - return BlockFaceShape.UNDEFINED; - } - - @Override - @Deprecated - public boolean hasCustomBreakingProgress( IBlockState state ) + public boolean hasCustomBreakingProgress( BlockState state ) { return true; } 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 3cfc9e5b2..561f57f36 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 @@ -8,7 +8,7 @@ package dan200.computercraft.shared.peripheral.modem.wired; import dan200.computercraft.shared.common.BlockGeneric; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer; @@ -27,7 +27,7 @@ public class BlockWiredModemFull extends BlockGeneric } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void fillStateContainer( 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 de2ff52e7..a22148fe2 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 @@ -6,7 +6,7 @@ package dan200.computercraft.shared.peripheral.modem.wired; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.IStringSerializable; import javax.annotation.Nonnull; @@ -14,50 +14,50 @@ import javax.annotation.Nonnull; public enum CableModemVariant implements IStringSerializable { None( "none", null ), - DownOff( "down_off", EnumFacing.DOWN ), - UpOff( "up_off", EnumFacing.UP ), - NorthOff( "north_off", EnumFacing.NORTH ), - SouthOff( "south_off", EnumFacing.SOUTH ), - WestOff( "west_off", EnumFacing.WEST ), - EastOff( "east_off", EnumFacing.EAST ), - DownOn( "down_on", EnumFacing.DOWN ), - UpOn( "up_on", EnumFacing.UP ), - NorthOn( "north_on", EnumFacing.NORTH ), - SouthOn( "south_on", EnumFacing.SOUTH ), - WestOn( "west_on", EnumFacing.WEST ), - EastOn( "east_on", EnumFacing.EAST ), - DownOffPeripheral( "down_off_peripheral", EnumFacing.DOWN ), - UpOffPeripheral( "up_off_peripheral", EnumFacing.UP ), - NorthOffPeripheral( "north_off_peripheral", EnumFacing.NORTH ), - SouthOffPeripheral( "south_off_peripheral", EnumFacing.SOUTH ), - WestOffPeripheral( "west_off_peripheral", EnumFacing.WEST ), - EastOffPeripheral( "east_off_peripheral", EnumFacing.EAST ), - DownOnPeripheral( "down_on_peripheral", EnumFacing.DOWN ), - UpOnPeripheral( "up_on_peripheral", EnumFacing.UP ), - NorthOnPeripheral( "north_on_peripheral", EnumFacing.NORTH ), - SouthOnPeripheral( "south_on_peripheral", EnumFacing.SOUTH ), - WestOnPeripheral( "west_on_peripheral", EnumFacing.WEST ), - EastOnPeripheral( "east_on_peripheral", EnumFacing.EAST ); + DownOff( "down_off", Direction.DOWN ), + UpOff( "up_off", Direction.UP ), + NorthOff( "north_off", Direction.NORTH ), + SouthOff( "south_off", Direction.SOUTH ), + WestOff( "west_off", Direction.WEST ), + EastOff( "east_off", Direction.EAST ), + DownOn( "down_on", Direction.DOWN ), + UpOn( "up_on", Direction.UP ), + NorthOn( "north_on", Direction.NORTH ), + SouthOn( "south_on", Direction.SOUTH ), + WestOn( "west_on", Direction.WEST ), + EastOn( "east_on", Direction.EAST ), + DownOffPeripheral( "down_off_peripheral", Direction.DOWN ), + UpOffPeripheral( "up_off_peripheral", Direction.UP ), + NorthOffPeripheral( "north_off_peripheral", Direction.NORTH ), + SouthOffPeripheral( "south_off_peripheral", Direction.SOUTH ), + WestOffPeripheral( "west_off_peripheral", Direction.WEST ), + EastOffPeripheral( "east_off_peripheral", Direction.EAST ), + DownOnPeripheral( "down_on_peripheral", Direction.DOWN ), + UpOnPeripheral( "up_on_peripheral", Direction.UP ), + NorthOnPeripheral( "north_on_peripheral", Direction.NORTH ), + SouthOnPeripheral( "south_on_peripheral", Direction.SOUTH ), + WestOnPeripheral( "west_on_peripheral", Direction.WEST ), + EastOnPeripheral( "east_on_peripheral", Direction.EAST ); private static final CableModemVariant[] VALUES = values(); private final String name; - private final EnumFacing facing; + private final Direction facing; - CableModemVariant( String name, EnumFacing facing ) + CableModemVariant( String name, Direction facing ) { this.name = name; this.facing = facing; } @Nonnull - public static CableModemVariant from( EnumFacing facing ) + public static CableModemVariant from( Direction facing ) { return facing == null ? None : VALUES[1 + facing.getIndex()]; } @Nonnull - public static CableModemVariant from( EnumFacing facing, boolean modem, boolean peripheral ) + 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()]; @@ -70,7 +70,7 @@ public enum CableModemVariant implements IStringSerializable return name; } - public EnumFacing getFacing() + public Direction getFacing() { return facing; } 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 4f9810f44..013f7f0ff 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 @@ -9,8 +9,8 @@ package dan200.computercraft.shared.peripheral.modem.wired; import com.google.common.collect.ImmutableMap; import dan200.computercraft.shared.peripheral.modem.ModemShapes; import dan200.computercraft.shared.util.DirectionUtil; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.EnumFacing; +import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; @@ -24,14 +24,14 @@ public final class CableShapes 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 EnumMap SHAPE_CABLE_ARM = - new EnumMap<>( new ImmutableMap.Builder() - .put( EnumFacing.DOWN, VoxelShapes.create( MIN, 0, MIN, MAX, MIN, MAX ) ) - .put( EnumFacing.UP, VoxelShapes.create( MIN, MAX, MIN, MAX, 1, MAX ) ) - .put( EnumFacing.NORTH, VoxelShapes.create( MIN, MIN, 0, MAX, MAX, MIN ) ) - .put( EnumFacing.SOUTH, VoxelShapes.create( MIN, MIN, MAX, MAX, MAX, 1 ) ) - .put( EnumFacing.WEST, VoxelShapes.create( 0, MIN, MIN, MIN, MAX, MAX ) ) - .put( EnumFacing.EAST, VoxelShapes.create( MAX, MIN, MIN, 1, 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 ) ) .build() ); @@ -42,10 +42,10 @@ public final class CableShapes { } - private static int getCableIndex( IBlockState state ) + private static int getCableIndex( BlockState state ) { int index = 0; - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { if( state.get( CONNECTIONS.get( facing ) ) ) index |= 1 << facing.ordinal(); } @@ -59,7 +59,7 @@ public final class CableShapes if( shape != null ) return shape; shape = SHAPE_CABLE_CORE; - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { if( (index & (1 << facing.ordinal())) != 0 ) { @@ -70,21 +70,21 @@ public final class CableShapes return CABLE_SHAPES[index] = shape; } - public static VoxelShape getCableShape( IBlockState state ) + public static VoxelShape getCableShape( BlockState state ) { if( !state.get( CABLE ) ) return VoxelShapes.empty(); return getCableShape( getCableIndex( state ) ); } - public static VoxelShape getModemShape( IBlockState state ) + public static VoxelShape getModemShape( BlockState state ) { - EnumFacing facing = state.get( MODEM ).getFacing(); + Direction facing = state.get( MODEM ).getFacing(); return facing == null ? VoxelShapes.empty() : ModemShapes.getBounds( facing ); } - public static VoxelShape getShape( IBlockState state ) + public static VoxelShape getShape( BlockState state ) { - EnumFacing facing = state.get( MODEM ).getFacing(); + Direction facing = state.get( MODEM ).getFacing(); if( !state.get( CABLE ) ) return getModemShape( state ); int cableIndex = getCableIndex( state ); 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 d65ca60f0..32efb50a5 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 @@ -7,11 +7,11 @@ package dan200.computercraft.shared.peripheral.modem.wired; import dan200.computercraft.ComputerCraft; +import net.minecraft.block.BlockState; import net.minecraft.block.SoundType; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; -import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -24,7 +24,7 @@ import javax.annotation.Nonnull; import static dan200.computercraft.shared.peripheral.modem.wired.BlockCable.*; -public abstract class ItemBlockCable extends ItemBlock +public abstract class ItemBlockCable extends BlockItem { private String translationKey; @@ -33,7 +33,7 @@ public abstract class ItemBlockCable extends ItemBlock super( block, settings ); } - boolean placeAt( World world, BlockPos pos, IBlockState state, EntityPlayer player ) + boolean placeAt( World world, BlockPos pos, BlockState state, PlayerEntity player ) { // TODO: Check entity collision. if( !state.isValidPosition( world, pos ) ) return false; @@ -53,7 +53,7 @@ public abstract class ItemBlockCable extends ItemBlock return true; } - boolean placeAtCorrected( World world, BlockPos pos, IBlockState state ) + boolean placeAtCorrected( World world, BlockPos pos, BlockState state ) { return placeAt( world, pos, correctConnections( world, pos, state ), null ); } @@ -84,26 +84,26 @@ public abstract class ItemBlockCable extends ItemBlock @Nonnull @Override - public EnumActionResult tryPlace( BlockItemUseContext context ) + public ActionResultType tryPlace( BlockItemUseContext context ) { ItemStack stack = context.getItem(); - if( stack.isEmpty() ) return EnumActionResult.FAIL; + if( stack.isEmpty() ) return ActionResultType.FAIL; World world = context.getWorld(); BlockPos pos = context.getPos(); - IBlockState existingState = world.getBlockState( pos ); + BlockState existingState = world.getBlockState( pos ); // Try to add a modem to a cable if( existingState.getBlock() == ComputerCraft.Blocks.cable && existingState.get( MODEM ) == CableModemVariant.None ) { - EnumFacing side = context.getFace().getOpposite(); - IBlockState newState = existingState + Direction side = context.getFace().getOpposite(); + BlockState newState = existingState .with( MODEM, CableModemVariant.from( side ) ) .with( CONNECTIONS.get( side ), existingState.get( CABLE ) ); if( placeAt( world, pos, newState, context.getPlayer() ) ) { stack.shrink( 1 ); - return EnumActionResult.SUCCESS; + return ActionResultType.SUCCESS; } } @@ -120,31 +120,31 @@ public abstract class ItemBlockCable extends ItemBlock @Nonnull @Override - public EnumActionResult tryPlace( BlockItemUseContext context ) + public ActionResultType tryPlace( BlockItemUseContext context ) { ItemStack stack = context.getItem(); - if( stack.isEmpty() ) return EnumActionResult.FAIL; + if( stack.isEmpty() ) return ActionResultType.FAIL; World world = context.getWorld(); BlockPos pos = context.getPos(); // Try to add a cable to a modem inside the block we're clicking on. BlockPos insidePos = pos.offset( context.getFace().getOpposite() ); - IBlockState insideState = world.getBlockState( insidePos ); + BlockState insideState = world.getBlockState( insidePos ); if( insideState.getBlock() == ComputerCraft.Blocks.cable && !insideState.get( BlockCable.CABLE ) && placeAtCorrected( world, insidePos, insideState.with( BlockCable.CABLE, true ) ) ) { stack.shrink( 1 ); - return EnumActionResult.SUCCESS; + return ActionResultType.SUCCESS; } // Try to add a cable to a modem adjacent to this block - IBlockState existingState = world.getBlockState( pos ); + BlockState existingState = world.getBlockState( pos ); if( existingState.getBlock() == ComputerCraft.Blocks.cable && !existingState.get( BlockCable.CABLE ) && placeAtCorrected( world, pos, existingState.with( BlockCable.CABLE, true ) ) ) { stack.shrink( 1 ); - return EnumActionResult.SUCCESS; + return ActionResultType.SUCCESS; } return super.tryPlace( 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 e02c62f27..53fc60e7b 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 @@ -17,21 +17,21 @@ import dan200.computercraft.shared.command.CommandCopy; import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.peripheral.modem.ModemState; import dan200.computercraft.shared.util.DirectionUtil; -import dan200.computercraft.shared.util.NamedBlockEntityType; +import dan200.computercraft.shared.util.NamedTileEntityType; import dan200.computercraft.shared.util.TickScheduler; import dan200.computercraft.shared.wired.CapabilityWiredElement; import net.minecraft.block.Block; -import net.minecraft.block.state.BlockFaceShape; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; @@ -44,7 +44,7 @@ import java.util.Map; public class TileCable extends TileGeneric implements IPeripheralTile { - public static final NamedBlockEntityType FACTORY = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "cable" ), TileCable::new ); @@ -86,7 +86,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile private boolean m_destroyed = false; - private EnumFacing modemDirection = EnumFacing.NORTH; + private Direction modemDirection = Direction.NORTH; private boolean hasModemDirection = false; private boolean m_connectionsFormed = false; @@ -194,20 +194,19 @@ public class TileCable extends TileGeneric implements IPeripheralTile } } - private EnumFacing getDirection() + private Direction getDirection() { - IBlockState state = getBlockState(); - EnumFacing facing = state.get( BlockCable.MODEM ).getFacing(); - return facing != null ? facing : EnumFacing.NORTH; + BlockState state = getBlockState(); + Direction facing = state.get( BlockCable.MODEM ).getFacing(); + return facing != null ? facing : Direction.NORTH; } @Override public void onNeighbourChange( @Nonnull BlockPos neighbour ) { - EnumFacing dir = getDirection(); + Direction dir = getDirection(); if( neighbour.equals( getPos().offset( dir ) ) && hasModem() - && getWorld().getBlockState( neighbour ).getBlockFaceShape( world, neighbour, dir.getOpposite() ) != BlockFaceShape.SOLID - ) + && getBlockState().isValidPosition( world, pos ) ) { if( hasCable() ) { @@ -221,7 +220,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile { // Drop everything and remove block Block.spawnAsEntity( getWorld(), getPos(), new ItemStack( ComputerCraft.Items.wiredModem ) ); - getWorld().removeBlock( getPos() ); + getWorld().removeBlock( getPos(), false ); // This'll call #destroy(), so we don't need to reset the network here. } @@ -237,7 +236,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile super.onNeighbourTileEntityChange( neighbour ); if( !world.isRemote && m_peripheralAccessAllowed ) { - EnumFacing facing = getDirection(); + Direction facing = getDirection(); if( getPos().offset( facing ).equals( neighbour ) ) { if( m_peripheral.attach( world, getPos(), facing ) ) updateConnectedPeripherals(); @@ -246,7 +245,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile } @Override - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { if( !canAttachPeripheral() || player.isSneaking() ) return false; @@ -259,12 +258,12 @@ public class TileCable extends TileGeneric implements IPeripheralTile { if( oldName != null ) { - player.sendStatusMessage( new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_disconnected", + player.sendStatusMessage( new TranslationTextComponent( "chat.computercraft.wired_modem.peripheral_disconnected", CommandCopy.createCopyText( oldName ) ), false ); } if( newName != null ) { - player.sendStatusMessage( new TextComponentTranslation( "chat.computercraft.wired_modem.peripheral_connected", + player.sendStatusMessage( new TranslationTextComponent( "chat.computercraft.wired_modem.peripheral_connected", CommandCopy.createCopyText( newName ) ), false ); } } @@ -273,7 +272,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile } @Override - public void read( NBTTagCompound nbt ) + public void read( CompoundNBT nbt ) { super.read( nbt ); m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); @@ -282,7 +281,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile @Nonnull @Override - public NBTTagCompound write( NBTTagCompound nbt ) + public CompoundNBT write( CompoundNBT nbt ) { nbt.putBoolean( NBT_PERIPHERAL_ENABLED, m_peripheralAccessAllowed ); m_peripheral.write( nbt, "" ); @@ -291,7 +290,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile private void updateBlockState() { - IBlockState state = getBlockState(); + BlockState state = getBlockState(); CableModemVariant oldVariant = state.get( BlockCable.MODEM ); CableModemVariant newVariant = CableModemVariant .from( oldVariant.getFacing(), m_modem.getModemState().isOpen(), m_peripheralAccessAllowed ); @@ -328,10 +327,10 @@ public class TileCable extends TileGeneric implements IPeripheralTile { if( getWorld().isRemote ) return; - IBlockState state = getBlockState(); + BlockState state = getBlockState(); World world = getWorld(); BlockPos current = getPos(); - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { BlockPos offset = current.offset( facing ); if( !world.isBlockLoaded( offset ) ) continue; @@ -419,7 +418,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile @Nonnull @Override - public LazyOptional getCapability( @Nonnull Capability capability, @Nullable EnumFacing facing ) + public LazyOptional getCapability( @Nonnull Capability capability, @Nullable Direction facing ) { if( capability == CapabilityWiredElement.CAPABILITY ) { @@ -432,7 +431,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile } @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { return !m_destroyed && hasModem() && side == getDirection() ? m_modem : null; } 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 510cb6fee..d7199e837 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 @@ -17,19 +17,20 @@ import dan200.computercraft.shared.command.CommandCopy; import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.peripheral.modem.ModemState; import dan200.computercraft.shared.util.DirectionUtil; -import dan200.computercraft.shared.util.NamedBlockEntityType; +import dan200.computercraft.shared.util.NamedTileEntityType; import dan200.computercraft.shared.util.TickScheduler; import dan200.computercraft.shared.wired.CapabilityWiredElement; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; @@ -44,7 +45,7 @@ import static dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModem public class TileWiredModemFull extends TileGeneric implements IPeripheralTile { - public static final NamedBlockEntityType FACTORY = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full" ), TileWiredModemFull::new ); @@ -173,7 +174,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile { if( !world.isRemote && m_peripheralAccessAllowed ) { - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { if( getPos().offset( facing ).equals( neighbour ) ) { @@ -185,7 +186,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile } @Override - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { if( getWorld().isRemote ) return true; @@ -203,25 +204,25 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile return true; } - private static void sendPeripheralChanges( EntityPlayer player, String kind, Collection peripherals ) + private static void sendPeripheralChanges( PlayerEntity player, String kind, Collection peripherals ) { if( peripherals.isEmpty() ) return; List names = new ArrayList<>( peripherals ); names.sort( Comparator.naturalOrder() ); - TextComponentString base = new TextComponentString( "" ); + StringTextComponent base = new StringTextComponent( "" ); for( int i = 0; i < names.size(); i++ ) { if( i > 0 ) base.appendText( ", " ); base.appendSibling( CommandCopy.createCopyText( names.get( i ) ) ); } - player.sendStatusMessage( new TextComponentTranslation( kind, base ), false ); + player.sendStatusMessage( new TranslationTextComponent( kind, base ), false ); } @Override - public void read( NBTTagCompound nbt ) + public void read( CompoundNBT nbt ) { super.read( nbt ); m_peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED ); @@ -230,7 +231,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile @Nonnull @Override - public NBTTagCompound write( NBTTagCompound nbt ) + public CompoundNBT write( 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 ) ); @@ -239,7 +240,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile private void updateBlockState() { - IBlockState state = getBlockState(); + BlockState state = getBlockState(); boolean modemOn = m_modemState.isOpen(), peripheralOn = m_peripheralAccessAllowed; if( state.get( MODEM_ON ) == modemOn && state.get( PERIPHERAL_ON ) == peripheralOn ) return; @@ -267,7 +268,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile connectionsChanged(); if( m_peripheralAccessAllowed ) { - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { m_peripherals[facing.ordinal()].attach( world, getPos(), facing ); } @@ -282,7 +283,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile World world = getWorld(); BlockPos current = getPos(); - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { BlockPos offset = current.offset( facing ); if( !world.isBlockLoaded( offset ) ) continue; @@ -300,7 +301,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile if( !m_peripheralAccessAllowed ) { boolean hasAny = false; - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { WiredModemLocalPeripheral peripheral = m_peripherals[facing.ordinal()]; peripheral.attach( world, getPos(), facing ); @@ -360,7 +361,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile @Nonnull @Override - public LazyOptional getCapability( @Nonnull Capability capability, @Nullable EnumFacing facing ) + public LazyOptional getCapability( @Nonnull Capability capability, @Nullable Direction facing ) { if( capability == CapabilityWiredElement.CAPABILITY ) { @@ -378,7 +379,7 @@ public class TileWiredModemFull extends TileGeneric implements IPeripheralTile // IPeripheralTile @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { if( m_destroyed ) return null; 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 7159aa5d8..840c4dc5e 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 @@ -11,8 +11,8 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.shared.Peripherals; import dan200.computercraft.shared.util.IDAssigner; import net.minecraft.block.Block; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; @@ -46,7 +46,7 @@ public final class WiredModemLocalPeripheral * @param direction The direction so search in * @return Whether the peripheral changed. */ - public boolean attach( @Nonnull World world, @Nonnull BlockPos origin, @Nonnull EnumFacing direction ) + public boolean attach( @Nonnull World world, @Nonnull BlockPos origin, @Nonnull Direction direction ) { IPeripheral oldPeripheral = peripheral; IPeripheral peripheral = this.peripheral = getPeripheralFrom( world, origin, direction ); @@ -116,13 +116,13 @@ public final class WiredModemLocalPeripheral : Collections.singletonMap( type + "_" + id, peripheral ); } - public void write( @Nonnull NBTTagCompound tag, @Nonnull String suffix ) + public void write( @Nonnull CompoundNBT tag, @Nonnull String suffix ) { if( id >= 0 ) tag.putInt( NBT_PERIPHERAL_ID + suffix, id ); if( type != null ) tag.putString( NBT_PERIPHERAL_TYPE + suffix, type ); } - public void read( @Nonnull NBTTagCompound tag, @Nonnull String suffix ) + public void read( @Nonnull CompoundNBT tag, @Nonnull String suffix ) { id = tag.contains( NBT_PERIPHERAL_ID + suffix, Constants.NBT.TAG_ANY_NUMERIC ) ? tag.getInt( NBT_PERIPHERAL_ID + suffix ) : -1; @@ -131,7 +131,7 @@ public final class WiredModemLocalPeripheral ? tag.getString( NBT_PERIPHERAL_TYPE + suffix ) : null; } - private static IPeripheral getPeripheralFrom( World world, BlockPos pos, EnumFacing direction ) + private static IPeripheral getPeripheralFrom( World world, BlockPos pos, Direction direction ) { BlockPos offset = pos.offset( direction ); 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 208df3b0e..d5f643868 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 @@ -8,43 +8,45 @@ package dan200.computercraft.shared.peripheral.modem.wireless; import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.peripheral.modem.ModemShapes; -import dan200.computercraft.shared.util.WaterloggableBlock; +import dan200.computercraft.shared.util.NamedTileEntityType; import net.minecraft.block.Block; -import net.minecraft.block.state.BlockFaceShape; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; +import net.minecraft.block.IWaterLoggable; import net.minecraft.fluid.IFluidState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.BooleanProperty; import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; -import net.minecraft.world.IWorldReaderBase; +import net.minecraft.world.IWorldReader; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BlockWirelessModem extends BlockGeneric implements WaterloggableBlock +import static dan200.computercraft.shared.util.WaterloggableHelpers.*; + +public class BlockWirelessModem extends BlockGeneric implements IWaterLoggable { public static final DirectionProperty FACING = BlockStateProperties.FACING; public static final BooleanProperty ON = BooleanProperty.create( "on" ); - public BlockWirelessModem( Properties settings, TileEntityType type ) + public BlockWirelessModem( Properties settings, NamedTileEntityType type ) { super( settings, type ); setDefaultState( getStateContainer().getBaseState() - .with( FACING, EnumFacing.NORTH ) + .with( FACING, Direction.NORTH ) .with( ON, false ) .with( WATERLOGGED, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void fillStateContainer( StateContainer.Builder builder ) { builder.add( FACING, ON, WATERLOGGED ); } @@ -52,7 +54,7 @@ public class BlockWirelessModem extends BlockGeneric implements WaterloggableBlo @Nonnull @Override @Deprecated - public VoxelShape getShape( IBlockState blockState, IBlockReader blockView, BlockPos blockPos ) + public VoxelShape getShape( BlockState blockState, IBlockReader blockView, BlockPos blockPos, ISelectionContext context ) { return ModemShapes.getBounds( blockState.get( FACING ) ); } @@ -60,7 +62,7 @@ public class BlockWirelessModem extends BlockGeneric implements WaterloggableBlo @Nonnull @Override @Deprecated - public IFluidState getFluidState( IBlockState state ) + public IFluidState getFluidState( BlockState state ) { return getWaterloggedFluidState( state ); } @@ -68,7 +70,7 @@ public class BlockWirelessModem extends BlockGeneric implements WaterloggableBlo @Nonnull @Override @Deprecated - public IBlockState updatePostPlacement( @Nonnull IBlockState state, EnumFacing side, IBlockState otherState, IWorld world, BlockPos pos, BlockPos otherPos ) + public BlockState updatePostPlacement( @Nonnull BlockState state, Direction side, BlockState otherState, IWorld world, BlockPos pos, BlockPos otherPos ) { updateWaterloggedPostPlacement( state, world, pos ); return side == state.get( FACING ) && !state.isValidPosition( world, pos ) @@ -78,35 +80,20 @@ public class BlockWirelessModem extends BlockGeneric implements WaterloggableBlo @Override @Deprecated - public boolean isValidPosition( IBlockState state, IWorldReaderBase world, BlockPos pos ) + public boolean isValidPosition( BlockState state, IWorldReader world, BlockPos pos ) { - EnumFacing facing = state.get( FACING ); + Direction facing = state.get( FACING ); BlockPos offsetPos = pos.offset( facing ); - IBlockState offsetState = world.getBlockState( offsetPos ); - return offsetState.getBlockFaceShape( world, offsetPos, facing.getOpposite() ) == BlockFaceShape.SOLID; + BlockState offsetState = world.getBlockState( offsetPos ); + return func_220056_d( offsetState, world, offsetPos, facing.getOpposite() ); } @Nullable @Override - public IBlockState getStateForPlacement( BlockItemUseContext placement ) + public BlockState getStateForPlacement( BlockItemUseContext placement ) { return getDefaultState() .with( FACING, placement.getFace().getOpposite() ) .with( WATERLOGGED, getWaterloggedStateForPlacement( placement ) ); } - - @Override - @Deprecated - public final boolean isFullCube( IBlockState state ) - { - return false; - } - - @Nonnull - @Override - @Deprecated - public BlockFaceShape getBlockFaceShape( IBlockReader worldIn, IBlockState state, BlockPos pos, EnumFacing face ) - { - return BlockFaceShape.UNDEFINED; - } } 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 d3fb3d195..9da297f52 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 @@ -12,11 +12,11 @@ import dan200.computercraft.api.peripheral.IPeripheralTile; import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.peripheral.modem.ModemPeripheral; import dan200.computercraft.shared.peripheral.modem.ModemState; -import dan200.computercraft.shared.util.NamedBlockEntityType; +import dan200.computercraft.shared.util.NamedTileEntityType; import dan200.computercraft.shared.util.TickScheduler; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -27,12 +27,12 @@ import javax.annotation.Nullable; public class TileWirelessModem extends TileGeneric implements IPeripheralTile { - public static final NamedBlockEntityType FACTORY_NORMAL = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_NORMAL = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "wireless_modem_normal" ), f -> new TileWirelessModem( f, false ) ); - public static final NamedBlockEntityType FACTORY_ADVANCED = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_ADVANCED = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "wireless_modem_advanced" ), f -> new TileWirelessModem( f, true ) ); @@ -72,7 +72,7 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile private final boolean advanced; private boolean hasModemDirection = false; - private EnumFacing modemDirection = EnumFacing.DOWN; + private Direction modemDirection = Direction.DOWN; private final ModemPeripheral modem; private boolean destroyed = false; @@ -142,7 +142,7 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile private void updateBlockState() { boolean on = modem.getModemState().isOpen(); - IBlockState state = getBlockState(); + BlockState state = getBlockState(); if( state.get( BlockWirelessModem.ON ) != on ) { getWorld().setBlockState( getPos(), state.with( BlockWirelessModem.ON, on ) ); @@ -152,7 +152,7 @@ public class TileWirelessModem extends TileGeneric implements IPeripheralTile @Nullable @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { updateDirection(); return side == modemDirection ? modem : null; 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 2ff323829..f924fb530 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 @@ -51,7 +51,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.func_217301_I() - 1) - 96.0)); } return minRange; } 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 40e389323..104ef94cc 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/BlockMonitor.java @@ -8,9 +8,10 @@ package dan200.computercraft.shared.peripheral.monitor; import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.TileGeneric; +import dan200.computercraft.shared.util.NamedTileEntityType; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.DirectionProperty; @@ -18,9 +19,8 @@ import net.minecraft.state.EnumProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.BlockRenderLayer; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -30,18 +30,18 @@ import javax.annotation.Nullable; public class BlockMonitor extends BlockGeneric { public static final DirectionProperty ORIENTATION = DirectionProperty.create( "orientation", - EnumFacing.UP, EnumFacing.DOWN, EnumFacing.NORTH ); + Direction.UP, Direction.DOWN, Direction.NORTH ); public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; static final EnumProperty STATE = EnumProperty.create( "state", MonitorEdgeState.class ); - public BlockMonitor( Properties settings, TileEntityType type ) + public BlockMonitor( Properties settings, NamedTileEntityType type ) { super( settings, type ); setDefaultState( getStateContainer().getBaseState() - .with( ORIENTATION, EnumFacing.NORTH ) - .with( FACING, EnumFacing.NORTH ) + .with( ORIENTATION, Direction.NORTH ) + .with( FACING, Direction.NORTH ) .with( STATE, MonitorEdgeState.NONE ) ); } @@ -53,30 +53,30 @@ public class BlockMonitor extends BlockGeneric } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void fillStateContainer( StateContainer.Builder builder ) { builder.add( ORIENTATION, FACING, STATE ); } @Override @Nullable - public IBlockState getStateForPlacement( BlockItemUseContext context ) + public BlockState getStateForPlacement( BlockItemUseContext context ) { float pitch = context.getPlayer() == null ? 0 : context.getPlayer().rotationPitch; - EnumFacing orientation; + Direction orientation; if( pitch > 66.5f ) { // If the player is looking down, place it facing upwards - orientation = EnumFacing.UP; + orientation = Direction.UP; } else if( pitch < -66.5f ) { // If they're looking up, place it down. - orientation = EnumFacing.DOWN; + orientation = Direction.DOWN; } else { - orientation = EnumFacing.NORTH; + orientation = Direction.NORTH; } return getDefaultState() @@ -85,7 +85,7 @@ public class BlockMonitor extends BlockGeneric } @Override - public void onBlockPlacedBy( World world, BlockPos pos, IBlockState blockState, @Nullable EntityLivingBase livingEntity, ItemStack itemStack ) + public void onBlockPlacedBy( World world, BlockPos pos, BlockState blockState, @Nullable LivingEntity livingEntity, ItemStack itemStack ) { super.onBlockPlacedBy( world, pos, blockState, livingEntity, itemStack ); 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 d2fb79675..2571f55a0 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/ClientMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/ClientMonitor.java @@ -6,8 +6,8 @@ package dan200.computercraft.shared.peripheral.monitor; +import com.mojang.blaze3d.platform.GlStateManager; import dan200.computercraft.shared.common.ClientTerminal; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.math.BlockPos; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; 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 7ad5836da..f461fb7a1 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/TileMonitor.java @@ -13,15 +13,16 @@ import dan200.computercraft.api.peripheral.IPeripheralTile; import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.shared.common.ServerTerminal; import dan200.computercraft.shared.common.TileGeneric; -import dan200.computercraft.shared.util.NamedBlockEntityType; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; +import dan200.computercraft.shared.util.NamedTileEntityType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.World; import javax.annotation.Nonnull; @@ -30,12 +31,12 @@ import java.util.Set; public class TileMonitor extends TileGeneric implements IPeripheralTile { - public static final NamedBlockEntityType FACTORY_NORMAL = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_NORMAL = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "monitor_normal" ), f -> new TileMonitor( f, false ) ); - public static final NamedBlockEntityType FACTORY_ADVANCED = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_ADVANCED = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "monitor_advanced" ), f -> new TileMonitor( f, true ) ); @@ -104,11 +105,18 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile } @Override - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { - if( !player.isSneaking() && getFront() == side ) + if( !player.isSneaking() && getFront() == hit.getFace() ) { - if( !getWorld().isRemote ) monitorTouched( hitX, hitY, hitZ ); + if( !getWorld().isRemote ) + { + monitorTouched( + (float) (hit.getHitVec().x - hit.getPos().getX()), + (float) (hit.getHitVec().y - hit.getPos().getY()), + (float) (hit.getHitVec().z - hit.getPos().getZ()) + ); + } return true; } @@ -117,7 +125,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile @Nonnull @Override - public NBTTagCompound write( NBTTagCompound tag ) + public CompoundNBT write( CompoundNBT tag ) { tag.putInt( NBT_X, m_xIndex ); tag.putInt( NBT_Y, m_yIndex ); @@ -127,7 +135,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile } @Override - public void read( NBTTagCompound tag ) + public void read( CompoundNBT tag ) { super.read( tag ); m_xIndex = tag.getInt( NBT_X ); @@ -168,7 +176,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile // IPeripheralTile implementation @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { createServerMonitor(); // Ensure the monitor is created before doing anything else. if( m_peripheral == null ) m_peripheral = new MonitorPeripheral( this ); @@ -238,7 +246,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile // Networking stuff @Override - protected void writeDescription( @Nonnull NBTTagCompound nbt ) + protected void writeDescription( @Nonnull CompoundNBT nbt ) { super.writeDescription( nbt ); @@ -254,7 +262,7 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile } @Override - protected final void readDescription( @Nonnull NBTTagCompound nbt ) + protected final void readDescription( @Nonnull CompoundNBT nbt ) { super.readDescription( nbt ); @@ -300,32 +308,32 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile } // region Sizing and placement stuff - public EnumFacing getDirection() + public Direction getDirection() { return getBlockState().get( BlockMonitor.FACING ); } - public EnumFacing getOrientation() + public Direction getOrientation() { return getBlockState().get( BlockMonitor.ORIENTATION ); } - public EnumFacing getFront() + public Direction getFront() { - EnumFacing orientation = getOrientation(); - return orientation == EnumFacing.NORTH ? getDirection() : orientation; + Direction orientation = getOrientation(); + return orientation == Direction.NORTH ? getDirection() : orientation; } - public EnumFacing getRight() + public Direction getRight() { return getDirection().rotateYCCW(); } - public EnumFacing getDown() + public Direction getDown() { - EnumFacing orientation = getOrientation(); - if( orientation == EnumFacing.NORTH ) return EnumFacing.UP; - return orientation == EnumFacing.DOWN ? getDirection() : getDirection().getOpposite(); + Direction orientation = getOrientation(); + if( orientation == Direction.NORTH ) return Direction.UP; + return orientation == Direction.DOWN ? getDirection() : getDirection().getOpposite(); } public int getWidth() @@ -368,8 +376,8 @@ public class TileMonitor extends TileGeneric implements IPeripheralTile private TileMonitor getNeighbour( int x, int y ) { BlockPos pos = getPos(); - EnumFacing right = getRight(); - EnumFacing down = getDown(); + 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 ) ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/monitor/XYPair.java b/src/main/java/dan200/computercraft/shared/peripheral/monitor/XYPair.java index 2fd92b142..2b1bf0f74 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/monitor/XYPair.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/monitor/XYPair.java @@ -6,7 +6,7 @@ package dan200.computercraft.shared.peripheral.monitor; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; public class XYPair { @@ -24,7 +24,7 @@ public class XYPair return new XYPair( this.x + x, this.y + y ); } - public static XYPair of( float xPos, float yPos, float zPos, EnumFacing facing, EnumFacing orientation ) + public static XYPair of( float xPos, float yPos, float zPos, Direction facing, Direction orientation ) { switch( orientation ) { 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 47d538c97..ef53a5f72 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/BlockPrinter.java @@ -8,18 +8,18 @@ package dan200.computercraft.shared.peripheral.printer; import dan200.computercraft.shared.common.BlockGeneric; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.BooleanProperty; import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.stats.StatList; +import net.minecraft.stats.Stats; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.INameable; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -37,30 +37,30 @@ public class BlockPrinter extends BlockGeneric { super( settings, TilePrinter.FACTORY ); setDefaultState( getStateContainer().getBaseState() - .with( FACING, EnumFacing.NORTH ) + .with( FACING, Direction.NORTH ) .with( TOP, false ) .with( BOTTOM, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder properties ) + protected void fillStateContainer( StateContainer.Builder properties ) { properties.add( FACING, TOP, BOTTOM ); } @Nullable @Override - public IBlockState getStateForPlacement( BlockItemUseContext placement ) + public BlockState getStateForPlacement( BlockItemUseContext placement ) { return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); } @Override - public void harvestBlock( @Nonnull World world, EntityPlayer player, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nullable TileEntity te, ItemStack stack ) + public void harvestBlock( @Nonnull World world, PlayerEntity player, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable TileEntity te, ItemStack stack ) { if( te instanceof INameable && ((INameable) te).hasCustomName() ) { - player.addStat( StatList.BLOCK_MINED.get( this ) ); + player.addStat( Stats.BLOCK_MINED.get( this ) ); player.addExhaustion( 0.005F ); ItemStack result = new ItemStack( this ); @@ -74,7 +74,7 @@ public class BlockPrinter extends BlockGeneric } @Override - public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack ) + public void onBlockPlacedBy( World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack ) { if( stack.hasDisplayName() ) { 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 7d6eae516..9ae869156 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java @@ -6,105 +6,85 @@ package dan200.computercraft.shared.peripheral.printer; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IContainerListener; +import dan200.computercraft.shared.util.SingleIntArray; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemDye; +import net.minecraft.inventory.Inventory; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.inventory.container.Slot; +import net.minecraft.item.DyeItem; import net.minecraft.item.ItemStack; +import net.minecraft.util.IIntArray; +import net.minecraft.util.IntArray; import javax.annotation.Nonnull; public class ContainerPrinter extends Container { - private static final int PROPERTY_PRINTING = 0; + public static final ContainerType TYPE = new ContainerType<>( ContainerPrinter::new ); - private final TilePrinter m_printer; - private boolean m_lastPrinting; + private final IInventory inventory; + private final IIntArray properties; - public ContainerPrinter( IInventory playerInventory, TilePrinter printer ) + private ContainerPrinter( int id, PlayerInventory player, IInventory inventory, IIntArray properties ) { - m_printer = printer; - m_lastPrinting = false; + super( TYPE, id ); + this.properties = properties; + this.inventory = inventory; + + func_216961_a( properties ); // Ink slot - addSlot( new Slot( printer, 0, 13, 35 ) ); + addSlot( new Slot( inventory, 0, 13, 35 ) ); // In-tray - for( int x = 0; x < 6; x++ ) addSlot( new Slot( printer, x + 1, 61 + x * 18, 22 ) ); + for( int x = 0; x < 6; x++ ) addSlot( new Slot( inventory, x + 1, 61 + x * 18, 22 ) ); // Out-tray - for( int x = 0; x < 6; x++ ) addSlot( new Slot( printer, x + 7, 61 + x * 18, 49 ) ); + for( int x = 0; x < 6; x++ ) addSlot( new Slot( inventory, x + 7, 61 + x * 18, 49 ) ); // Player inv for( int y = 0; y < 3; y++ ) { for( int x = 0; x < 9; x++ ) { - addSlot( new Slot( playerInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18 ) ); + addSlot( new Slot( player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18 ) ); } } // Player hotbar - for( int x = 0; x < 9; x++ ) addSlot( new Slot( playerInventory, x, 8 + x * 18, 142 ) ); + for( int x = 0; x < 9; x++ ) + { + addSlot( new Slot( player, x, 8 + x * 18, 142 ) ); + } + } + + private ContainerPrinter( int id, PlayerInventory player ) + { + this( id, player, new Inventory( TilePrinter.SLOTS ), new IntArray( TilePrinter.PROPERTIES ) ); + } + + public ContainerPrinter( int id, PlayerInventory player, TilePrinter printer ) + { + this( id, player, printer, (SingleIntArray) (() -> printer.isPrinting() ? 1 : 0) ); } public boolean isPrinting() { - return m_lastPrinting; - } - - public TilePrinter getPrinter() - { - return m_printer; + return properties.func_221476_a( 0 ) != 0; } @Override - public void addListener( IContainerListener listener ) + public boolean canInteractWith( @Nonnull PlayerEntity player ) { - super.addListener( listener ); - listener.sendWindowProperty( this, PROPERTY_PRINTING, m_printer.isPrinting() ? 1 : 0 ); - } - - @Override - public void detectAndSendChanges() - { - super.detectAndSendChanges(); - - if( !m_printer.getWorld().isRemote ) - { - // Push the printing state to the client if needed. - boolean printing = m_printer.isPrinting(); - if( printing != m_lastPrinting ) - { - for( IContainerListener listener : listeners ) - { - listener.sendWindowProperty( this, PROPERTY_PRINTING, printing ? 1 : 0 ); - } - m_lastPrinting = printing; - } - } - } - - @Override - public void updateProgressBar( int property, int value ) - { - if( m_printer.getWorld().isRemote ) - { - if( property == PROPERTY_PRINTING ) m_lastPrinting = value != 0; - } - } - - @Override - public boolean canInteractWith( @Nonnull EntityPlayer player ) - { - return m_printer.isUsableByPlayer( player ); + return inventory.isUsableByPlayer( player ); } @Nonnull @Override - public ItemStack transferStackInSlot( EntityPlayer player, int index ) + public ItemStack transferStackInSlot( PlayerEntity player, int index ) { Slot slot = inventorySlots.get( index ); if( slot == null || !slot.getHasStack() ) return ItemStack.EMPTY; @@ -118,7 +98,7 @@ public class ContainerPrinter extends Container else { // Transfer from inventory to printer - if( stack.getItem() instanceof ItemDye ) + if( stack.getItem() instanceof DyeItem ) { if( !mergeItemStack( stack, 0, 1, false ) ) 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 42f8b6e7a..16c99504c 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/TilePrinter.java @@ -12,28 +12,26 @@ import dan200.computercraft.api.peripheral.IPeripheralTile; import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.shared.common.TileGeneric; import dan200.computercraft.shared.media.items.ItemPrintout; -import dan200.computercraft.shared.network.Containers; import dan200.computercraft.shared.util.ColourUtils; import dan200.computercraft.shared.util.DefaultSidedInventory; -import dan200.computercraft.shared.util.NamedBlockEntityType; +import dan200.computercraft.shared.util.NamedTileEntityType; import dan200.computercraft.shared.util.WorldUtil; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.ItemStackHelper; -import net.minecraft.item.EnumDyeColor; -import net.minecraft.item.Item; -import net.minecraft.item.ItemDye; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.INamedContainerProvider; +import net.minecraft.item.*; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.LazyOptional; +import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.wrapper.InvWrapper; import net.minecraftforge.items.wrapper.SidedInvWrapper; @@ -43,9 +41,9 @@ import javax.annotation.Nullable; import static net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY; -public final class TilePrinter extends TileGeneric implements DefaultSidedInventory, IPeripheralTile +public final class TilePrinter extends TileGeneric implements DefaultSidedInventory, IPeripheralTile, INameable, INamedContainerProvider { - public static final NamedBlockEntityType FACTORY = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "printer" ), TilePrinter::new ); @@ -54,13 +52,16 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent private static final String NBT_PRINTING = "Printing"; private static final String NBT_PAGE_TITLE = "PageTitle"; + static final int SLOTS = 13; + static final int PROPERTIES = 1; + private static final int[] BOTTOM_SLOTS = new int[] { 7, 8, 9, 10, 11, 12 }; private static final int[] TOP_SLOTS = new int[] { 1, 2, 3, 4, 5, 6 }; private static final int[] SIDE_SLOTS = new int[] { 0 }; ITextComponent customName; - private final NonNullList m_inventory = NonNullList.withSize( 13, ItemStack.EMPTY ); + private final NonNullList m_inventory = NonNullList.withSize( SLOTS, ItemStack.EMPTY ); private LazyOptional[] itemHandlerCaps; private final Terminal m_page = new Terminal( ItemPrintout.LINE_MAX_LENGTH, ItemPrintout.LINES_PER_PAGE ); @@ -95,16 +96,16 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent } @Override - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { if( player.isSneaking() ) return false; - if( !getWorld().isRemote ) Containers.openPrinterGUI( player, this ); + if( !getWorld().isRemote ) NetworkHooks.openGui( (ServerPlayerEntity) player, this ); return true; } @Override - public void read( NBTTagCompound nbt ) + public void read( CompoundNBT nbt ) { super.read( nbt ); @@ -127,7 +128,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent @Nonnull @Override - public NBTTagCompound write( NBTTagCompound nbt ) + public CompoundNBT write( CompoundNBT nbt ) { if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); @@ -149,14 +150,14 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent } @Override - protected void writeDescription( @Nonnull NBTTagCompound nbt ) + protected void writeDescription( @Nonnull CompoundNBT nbt ) { super.writeDescription( nbt ); if( customName != null ) nbt.putString( NBT_NAME, ITextComponent.Serializer.toJson( customName ) ); } @Override - public void readDescription( @Nonnull NBTTagCompound nbt ) + public void readDescription( @Nonnull CompoundNBT nbt ) { super.readDescription( nbt ); customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null; @@ -274,7 +275,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent } @Override - public boolean isUsableByPlayer( @Nonnull EntityPlayer playerEntity ) + public boolean isUsableByPlayer( @Nonnull PlayerEntity playerEntity ) { return isUsable( playerEntity, false ); } @@ -283,7 +284,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent @Nonnull @Override - public int[] getSlotsForFace( @Nonnull EnumFacing side ) + public int[] getSlotsForFace( @Nonnull Direction side ) { switch( side ) { @@ -299,7 +300,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent // IPeripheralTile implementation @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { return new PrinterPeripheral( this ); } @@ -367,7 +368,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent private static boolean isInk( @Nonnull ItemStack stack ) { - return stack.getItem() instanceof ItemDye; + return stack.getItem() instanceof DyeItem; } private static boolean isPaper( @Nonnull ItemStack stack ) @@ -399,7 +400,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent if( !paperStack.isEmpty() && isPaper( paperStack ) ) { // Setup the new page - EnumDyeColor dye = ColourUtils.getStackColour( inkStack ); + DyeColor dye = ColourUtils.getStackColour( inkStack ); m_page.setTextColour( dye != null ? dye.getId() : 15 ); m_page.clear(); @@ -525,7 +526,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent { if( removed ) return; - IBlockState state = getBlockState(); + BlockState state = getBlockState(); if( state.get( BlockPrinter.TOP ) == top & state.get( BlockPrinter.BOTTOM ) == bottom ) return; getWorld().setBlockState( getPos(), state.with( BlockPrinter.TOP, top ).with( BlockPrinter.BOTTOM, bottom ) ); @@ -534,7 +535,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent @SuppressWarnings( { "unchecked", "rawtypes" } ) @Nonnull @Override - public LazyOptional getCapability( @Nonnull Capability capability, @Nullable EnumFacing facing ) + public LazyOptional getCapability( @Nonnull Capability capability, @Nullable Direction facing ) { if( capability == ITEM_HANDLER_CAPABILITY ) { @@ -575,4 +576,17 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent { return customName != null ? customName : getBlockState().getBlock().getNameTextComponent(); } + + @Override + public ITextComponent getDisplayName() + { + return getName(); + } + + @Nonnull + @Override + public Container createMenu( int id, @Nonnull PlayerInventory inventory, @Nonnull PlayerEntity player ) + { + return new ContainerPrinter( id, inventory, this ); + } } 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 d31169fab..60ef1f9df 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/BlockSpeaker.java @@ -8,12 +8,12 @@ package dan200.computercraft.shared.peripheral.speaker; import dan200.computercraft.shared.common.BlockGeneric; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import javax.annotation.Nullable; @@ -25,18 +25,18 @@ public class BlockSpeaker extends BlockGeneric { super( settings, TileSpeaker.FACTORY ); setDefaultState( getStateContainer().getBaseState() - .with( FACING, EnumFacing.NORTH ) ); + .with( FACING, Direction.NORTH ) ); } @Override - protected void fillStateContainer( StateContainer.Builder properties ) + protected void fillStateContainer( StateContainer.Builder properties ) { properties.add( FACING ); } @Nullable @Override - public IBlockState getStateForPlacement( BlockItemUseContext placement ) + public BlockState getStateForPlacement( BlockItemUseContext placement ) { return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().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 2b115e6f4..1bb93aa84 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/SpeakerPeripheral.java @@ -11,7 +11,7 @@ import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; -import net.minecraft.network.play.server.SPacketCustomSound; +import net.minecraft.network.play.server.SPlaySoundPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.state.properties.NoteBlockInstrument; import net.minecraft.util.ResourceLocation; @@ -146,7 +146,7 @@ public abstract class SpeakerPeripheral implements IPeripheral float adjVolume = Math.min( volume, 3.0f ); server.getPlayerList().sendToAllNearExcept( null, pos.x, pos.y, pos.z, adjVolume > 1.0f ? 16 * adjVolume : 16.0, world.dimension.getType(), - new SPacketCustomSound( name, SoundCategory.RECORDS, pos, adjVolume, pitch ) + new SPlaySoundPacket( name, SoundCategory.RECORDS, pos, adjVolume, pitch ) ); return null; } ); 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 667af245d..4c8d552ac 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/TileSpeaker.java @@ -10,9 +10,9 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheralTile; import dan200.computercraft.shared.common.TileGeneric; -import dan200.computercraft.shared.util.NamedBlockEntityType; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ITickable; +import dan200.computercraft.shared.util.NamedTileEntityType; +import net.minecraft.tileentity.ITickableTileEntity; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -21,11 +21,11 @@ import net.minecraft.world.World; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class TileSpeaker extends TileGeneric implements ITickable, IPeripheralTile +public class TileSpeaker extends TileGeneric implements ITickableTileEntity, IPeripheralTile { public static final int MIN_TICKS_BETWEEN_SOUNDS = 1; - public static final NamedBlockEntityType FACTORY = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "speaker" ), TileSpeaker::new ); @@ -45,7 +45,7 @@ public class TileSpeaker extends TileGeneric implements ITickable, IPeripheralTi } @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { return m_peripheral; } 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 fb8c88f3e..96d8d0840 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java +++ b/src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java @@ -15,8 +15,8 @@ import dan200.computercraft.shared.pocket.core.PocketServerComputer; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; import net.minecraftforge.items.wrapper.PlayerMainInvWrapper; @@ -58,9 +58,9 @@ public class PocketAPI implements ILuaAPI return context.executeMainThreadTask( () -> { Entity entity = m_computer.getEntity(); - if( !(entity instanceof EntityPlayer) ) return new Object[] { false, "Cannot find player" }; - EntityPlayer player = (EntityPlayer) entity; - InventoryPlayer inventory = player.inventory; + if( !(entity instanceof PlayerEntity) ) return new Object[] { false, "Cannot find player" }; + PlayerEntity player = (PlayerEntity) entity; + PlayerInventory inventory = player.inventory; IPocketUpgrade previousUpgrade = m_computer.getUpgrade(); // Attempt to find the upgrade, starting in the main segment, and then looking in the opposite @@ -97,9 +97,9 @@ public class PocketAPI implements ILuaAPI return context.executeMainThreadTask( () -> { Entity entity = m_computer.getEntity(); - if( !(entity instanceof EntityPlayer) ) return new Object[] { false, "Cannot find player" }; - EntityPlayer player = (EntityPlayer) entity; - InventoryPlayer inventory = player.inventory; + if( !(entity instanceof PlayerEntity) ) return new Object[] { false, "Cannot find player" }; + PlayerEntity player = (PlayerEntity) entity; + PlayerInventory inventory = player.inventory; IPocketUpgrade previousUpgrade = m_computer.getUpgrade(); if( previousUpgrade == null ) return new Object[] { false, "Nothing to unequip" }; 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 264de4d48..2906a5a1d 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/core/PocketServerComputer.java @@ -17,12 +17,12 @@ import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.common.util.Constants; @@ -52,14 +52,14 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces Entity entity = m_entity; if( entity == null || m_stack == null || !entity.isAlive() ) return null; - if( entity instanceof EntityPlayer ) + if( entity instanceof PlayerEntity ) { - InventoryPlayer inventory = ((EntityPlayer) entity).inventory; + PlayerInventory inventory = ((PlayerEntity) entity).inventory; return inventory.mainInventory.contains( m_stack ) || inventory.offHandInventory.contains( m_stack ) ? entity : null; } - else if( entity instanceof EntityLivingBase ) + else if( entity instanceof LivingEntity ) { - EntityLivingBase living = (EntityLivingBase) entity; + LivingEntity living = (LivingEntity) entity; return living.getHeldItemMainhand() == m_stack || living.getHeldItemOffhand() == m_stack ? entity : null; } else @@ -84,14 +84,14 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces @Override public int getLight() { - NBTTagCompound tag = getUserData(); + CompoundNBT tag = getUserData(); return tag.contains( NBT_LIGHT, Constants.NBT.TAG_ANY_NUMERIC ) ? tag.getInt( NBT_LIGHT ) : -1; } @Override public void setLight( int colour ) { - NBTTagCompound tag = getUserData(); + CompoundNBT tag = getUserData(); if( colour >= 0 && colour <= 0xFFFFFF ) { if( !tag.contains( NBT_LIGHT, Constants.NBT.TAG_ANY_NUMERIC ) || tag.getInt( NBT_LIGHT ) != colour ) @@ -109,7 +109,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces @Nonnull @Override - public NBTTagCompound getUpgradeNBTData() + public CompoundNBT getUpgradeNBTData() { return ItemPocketComputer.getUpgradeInfo( m_stack ); } @@ -117,7 +117,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces @Override public void updateUpgradeNBTData() { - if( m_entity instanceof EntityPlayer ) ((EntityPlayer) m_entity).inventory.markDirty(); + if( m_entity instanceof PlayerEntity ) ((PlayerEntity) m_entity).inventory.markDirty(); } @Override @@ -168,7 +168,7 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces } // If a new entity has picked it up then rebroadcast the terminal to them - if( entity != m_entity && entity instanceof EntityPlayerMP ) markTerminalChanged(); + if( entity != m_entity && entity instanceof ServerPlayerEntity ) markTerminalChanged(); m_entity = entity; m_stack = stack; @@ -185,10 +185,10 @@ public class PocketServerComputer extends ServerComputer implements IPocketAcces { super.broadcastState( force ); - if( (hasTerminalChanged() || force) && m_entity instanceof EntityPlayerMP ) + if( (hasTerminalChanged() || force) && m_entity instanceof ServerPlayerEntity ) { // Broadcast the state to the current entity if they're not already interacting with it. - EntityPlayerMP player = (EntityPlayerMP) m_entity; + ServerPlayerEntity player = (ServerPlayerEntity) m_entity; if( player.connection != null && !isInteracting( player ) ) { NetworkHandler.sendToPlayer( player, createTerminalPacket() ); 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 9619ba9e3..4c3e9cb39 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/inventory/ContainerPocketComputer.java @@ -10,21 +10,26 @@ import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.core.InputState; +import dan200.computercraft.shared.network.container.ContainerData; +import dan200.computercraft.shared.network.container.PocketComputerContainerData; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumHand; +import net.minecraft.util.Hand; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class ContainerPocketComputer extends ContainerHeldItem implements IContainerComputer { + public static final ContainerType TYPE = ContainerData.create( PocketComputerContainerData::new ); + private final InputState input = new InputState( this ); - public ContainerPocketComputer( EntityPlayer player, EnumHand hand ) + public ContainerPocketComputer( int id, @Nonnull PlayerEntity player, Hand hand ) { - super( player, hand ); + super( TYPE, id, player, hand ); } @Nullable @@ -44,7 +49,7 @@ public class ContainerPocketComputer extends ContainerHeldItem implements IConta } @Override - public void onContainerClosed( EntityPlayer player ) + public void onContainerClosed( PlayerEntity player ) { super.onContainerClosed( player ); input.close(); 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 ab681c433..f81ac140e 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -20,23 +20,23 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.items.IComputerItem; -import dan200.computercraft.shared.network.Containers; +import dan200.computercraft.shared.network.container.PocketComputerContainerData; import dan200.computercraft.shared.pocket.apis.PocketAPI; import dan200.computercraft.shared.pocket.core.PocketServerComputer; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.IInventory; import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.*; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -68,7 +68,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I { ItemStack result = new ItemStack( this ); if( id >= 0 ) result.getOrCreateTag().putInt( NBT_ID, id ); - if( label != null ) result.setDisplayName( new TextComponentString( label ) ); + if( label != null ) result.setDisplayName( 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; @@ -91,7 +91,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I if( !world.isRemote ) { // Server side - IInventory inventory = entity instanceof EntityPlayer ? ((EntityPlayer) entity).inventory : null; + IInventory inventory = entity instanceof PlayerEntity ? ((PlayerEntity) entity).inventory : null; PocketServerComputer computer = createServerComputer( world, inventory, entity, stack ); if( computer != null ) { @@ -134,7 +134,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I @Nonnull @Override - public ActionResult onItemRightClick( World world, EntityPlayer player, @Nonnull EnumHand hand ) + public ActionResult onItemRightClick( World world, PlayerEntity player, @Nonnull Hand hand ) { ItemStack stack = player.getHeldItem( hand ); if( !world.isRemote ) @@ -154,9 +154,9 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I } } - if( !stop ) Containers.openPocketComputerGUI( player, hand ); + if( !stop ) new PocketComputerContainerData( hand ).open( player ); } - return new ActionResult<>( EnumActionResult.SUCCESS, stack ); + return new ActionResult<>( ActionResultType.SUCCESS, stack ); } @Nonnull @@ -167,8 +167,8 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I IPocketUpgrade upgrade = getUpgrade( stack ); if( upgrade != null ) { - return new TextComponentTranslation( baseString + ".upgraded", - new TextComponentTranslation( upgrade.getUnlocalisedAdjective() ) + return new TranslationTextComponent( baseString + ".upgraded", + new TranslationTextComponent( upgrade.getUnlocalisedAdjective() ) ); } else @@ -186,7 +186,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I int id = getComputerID( stack ); if( id >= 0 ) { - list.add( new TextComponentTranslation( "gui.computercraft.tooltip.computer_id", id ) + list.add( new TranslationTextComponent( "gui.computercraft.tooltip.computer_id", id ) .applyTextStyle( TextFormatting.GRAY ) ); } } @@ -313,7 +313,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I { if( label != null ) { - stack.setDisplayName( new TextComponentString( label ) ); + stack.setDisplayName( new StringTextComponent( label ) ); } else { @@ -335,7 +335,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I private static int getInstanceID( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_INSTANCE ) ? nbt.getInt( NBT_INSTANCE ) : -1; } @@ -346,7 +346,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I private static int getSessionID( @Nonnull ItemStack stack ) { - NBTTagCompound nbt = stack.getTag(); + CompoundNBT nbt = stack.getTag(); return nbt != null && nbt.contains( NBT_SESSION ) ? nbt.getInt( NBT_SESSION ) : -1; } @@ -368,7 +368,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I ClientComputer computer = getClientComputer( stack ); if( computer != null && computer.isOn() ) { - NBTTagCompound computerNBT = computer.getUserData(); + CompoundNBT computerNBT = computer.getUserData(); if( computerNBT != null && computerNBT.contains( NBT_LIGHT ) ) { return computerNBT.getInt( NBT_LIGHT ); @@ -379,7 +379,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I public static IPocketUpgrade getUpgrade( @Nonnull ItemStack stack ) { - NBTTagCompound compound = stack.getTag(); + CompoundNBT compound = stack.getTag(); return compound != null && compound.contains( NBT_UPGRADE ) ? PocketUpgrades.get( compound.getString( NBT_UPGRADE ) ) : null; @@ -387,7 +387,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I public static void setUpgrade( @Nonnull ItemStack stack, IPocketUpgrade upgrade ) { - NBTTagCompound compound = stack.getOrCreateTag(); + CompoundNBT compound = stack.getOrCreateTag(); if( upgrade == null ) { @@ -401,7 +401,7 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I compound.remove( NBT_UPGRADE_INFO ); } - public static NBTTagCompound getUpgradeInfo( @Nonnull ItemStack stack ) + public static CompoundNBT getUpgradeInfo( @Nonnull ItemStack stack ) { return stack.getOrCreateChildTag( NBT_UPGRADE_INFO ); } 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 76fbac517..381e7cc73 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java @@ -6,23 +6,22 @@ package dan200.computercraft.shared.pocket.recipes; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.shared.PocketUpgrades; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory; -import dan200.computercraft.shared.util.AbstractRecipe; -import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.RecipeSerializers; +import net.minecraft.item.crafting.SpecialRecipe; +import net.minecraft.item.crafting.SpecialRecipeSerializer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import javax.annotation.Nonnull; -public final class PocketComputerUpgradeRecipe extends AbstractRecipe +public final class PocketComputerUpgradeRecipe extends SpecialRecipe { private PocketComputerUpgradeRecipe( ResourceLocation identifier ) { @@ -43,14 +42,14 @@ public final class PocketComputerUpgradeRecipe extends AbstractRecipe } @Override - public boolean matches( @Nonnull IInventory inventory, @Nonnull World world ) + public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world ) { return !getCraftingResult( inventory ).isEmpty(); } @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull IInventory inventory ) + public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) { // Scan the grid for a pocket computer ItemStack computer = ItemStack.EMPTY; @@ -115,8 +114,5 @@ public final class PocketComputerUpgradeRecipe extends AbstractRecipe return SERIALIZER; } - public static final IRecipeSerializer SERIALIZER = new RecipeSerializers.SimpleSerializer<>( - ComputerCraft.MOD_ID + ":pocket_computer_upgrade", - PocketComputerUpgradeRecipe::new - ); + public static final IRecipeSerializer SERIALIZER = new SpecialRecipeSerializer<>( PocketComputerUpgradeRecipe::new ); } diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 66e749df6..cde8638db 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -16,30 +16,35 @@ import dan200.computercraft.shared.Config; import dan200.computercraft.shared.command.CommandComputerCraft; import dan200.computercraft.shared.command.arguments.ArgumentSerializers; import dan200.computercraft.shared.common.ColourableRecipe; +import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.core.ServerComputer; +import dan200.computercraft.shared.computer.inventory.ContainerViewComputer; import dan200.computercraft.shared.computer.recipe.ComputerUpgradeRecipe; import dan200.computercraft.shared.media.items.RecordMedia; import dan200.computercraft.shared.media.recipes.DiskRecipe; import dan200.computercraft.shared.media.recipes.PrintoutRecipe; -import dan200.computercraft.shared.network.Containers; import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheral; +import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork; +import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; +import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import dan200.computercraft.shared.pocket.recipes.PocketComputerUpgradeRecipe; import dan200.computercraft.shared.turtle.recipes.TurtleRecipe; import dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe; import dan200.computercraft.shared.util.ImpostorRecipe; import dan200.computercraft.shared.util.ImpostorShapelessRecipe; import dan200.computercraft.shared.wired.CapabilityWiredElement; -import net.minecraft.inventory.Container; +import net.minecraft.inventory.container.Container; import net.minecraft.item.Item; -import net.minecraft.item.ItemRecord; -import net.minecraft.item.crafting.RecipeSerializers; +import net.minecraft.item.MusicDiscItem; +import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.tileentity.CommandBlockTileEntity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityCommandBlock; +import net.minecraft.util.registry.Registry; import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.event.ConfigChangedEvent; @@ -57,19 +62,25 @@ public final class ComputerCraftProxyCommon public static void init( FMLCommonSetupEvent event ) { NetworkHandler.setup(); - Containers.setup(); registerProviders(); - RecipeSerializers.register( ColourableRecipe.SERIALIZER ); - RecipeSerializers.register( ComputerUpgradeRecipe.SERIALIZER ); - RecipeSerializers.register( PocketComputerUpgradeRecipe.SERIALIZER ); - RecipeSerializers.register( DiskRecipe.SERIALIZER ); - RecipeSerializers.register( PrintoutRecipe.SERIALIZER ); - RecipeSerializers.register( TurtleRecipe.SERIALIZER ); - RecipeSerializers.register( TurtleUpgradeRecipe.SERIALIZER ); - RecipeSerializers.register( ImpostorShapelessRecipe.SERIALIZER ); - RecipeSerializers.register( ImpostorRecipe.SERIALIZER ); + // Eww, eww, eww - can we move this to an event? + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":colour", ColourableRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":computer_upgrade", ComputerUpgradeRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":pocket_computer_upgrade", PocketComputerUpgradeRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":disk", DiskRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":printout", PrintoutRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":turtle", TurtleRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":turtle_upgrade", TurtleUpgradeRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":impostor_shapeless", ImpostorShapelessRecipe.SERIALIZER ); + IRecipeSerializer.func_222156_a( ComputerCraft.MOD_ID + ":impostor_shaped", ImpostorRecipe.SERIALIZER ); + + Registry.register( Registry.field_218366_G, ComputerCraft.MOD_ID + ":printer", ContainerPrinter.TYPE ); + Registry.register( Registry.field_218366_G, ComputerCraft.MOD_ID + ":disk_drive", ContainerDiskDrive.TYPE ); + Registry.register( Registry.field_218366_G, ComputerCraft.MOD_ID + ":pocket_computer", ContainerPocketComputer.TYPE ); + Registry.register( Registry.field_218366_G, ComputerCraft.MOD_ID + ":printout", ContainerHeldItem.PRINTOUT_TYPE ); + Registry.register( Registry.field_218366_G, ComputerCraft.MOD_ID + ":view_computer", ContainerViewComputer.TYPE ); ArgumentSerializers.register(); @@ -86,7 +97,7 @@ public final class ComputerCraftProxyCommon ComputerCraftAPI.registerPeripheralProvider( ( world, pos, side ) -> { TileEntity tile = world.getTileEntity( pos ); - return ComputerCraft.enableCommandBlock && tile instanceof TileEntityCommandBlock ? new CommandBlockPeripheral( (TileEntityCommandBlock) tile ) : null; + return ComputerCraft.enableCommandBlock && tile instanceof CommandBlockTileEntity ? new CommandBlockPeripheral( (CommandBlockTileEntity) tile ) : null; } ); // Register bundled power providers @@ -96,7 +107,7 @@ public final class ComputerCraftProxyCommon ComputerCraftAPI.registerMediaProvider( stack -> { Item item = stack.getItem(); if( item instanceof IMedia ) return (IMedia) item; - if( item instanceof ItemRecord ) return RecordMedia.INSTANCE; + if( item instanceof MusicDiscItem ) return RecordMedia.INSTANCE; return null; } ); diff --git a/src/main/java/dan200/computercraft/shared/turtle/FurnaceRefuelHandler.java b/src/main/java/dan200/computercraft/shared/turtle/FurnaceRefuelHandler.java index 1e99819b1..7927934f7 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/FurnaceRefuelHandler.java +++ b/src/main/java/dan200/computercraft/shared/turtle/FurnaceRefuelHandler.java @@ -12,7 +12,7 @@ import dan200.computercraft.api.turtle.event.TurtleRefuelEvent; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraft.tileentity.FurnaceTileEntity; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -54,7 +54,7 @@ public final class FurnaceRefuelHandler implements TurtleRefuelEvent.Handler int basicBurnTime = stack.getBurnTime(); int burnTime = ForgeEventFactory.getItemBurnTime( stack, - basicBurnTime == -1 ? TileEntityFurnace.getBurnTimes().getOrDefault( stack.getItem(), 0 ) : basicBurnTime + basicBurnTime == -1 ? FurnaceTileEntity.func_214001_f().getOrDefault( stack.getItem(), 0 ) : basicBurnTime ); return (burnTime * 5) / 100; } 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 d16515e3b..b5572b80c 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/BlockTurtle.java @@ -13,14 +13,15 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.turtle.items.ITurtleItem; import dan200.computercraft.shared.turtle.items.TurtleItemFactory; -import dan200.computercraft.shared.util.WaterloggableBlock; +import dan200.computercraft.shared.util.NamedTileEntityType; import net.minecraft.block.Block; -import net.minecraft.block.state.BlockFaceShape; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockRenderType; +import net.minecraft.block.BlockState; +import net.minecraft.block.IWaterLoggable; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.projectile.EntityFireball; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.DamagingProjectileEntity; import net.minecraft.fluid.IFluidState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; @@ -28,12 +29,11 @@ import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumBlockRenderType; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.*; @@ -41,7 +41,10 @@ import net.minecraft.world.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class BlockTurtle extends BlockComputerBase implements WaterloggableBlock +import static dan200.computercraft.shared.util.WaterloggableHelpers.*; +import static net.minecraft.state.properties.BlockStateProperties.WATERLOGGED; + +public class BlockTurtle extends BlockComputerBase implements IWaterLoggable { public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; @@ -50,17 +53,17 @@ public class BlockTurtle extends BlockComputerBase implements Waterl 0.875, 0.875, 0.875 ); - public BlockTurtle( Properties settings, ComputerFamily family, TileEntityType type ) + public BlockTurtle( Properties settings, ComputerFamily family, NamedTileEntityType type ) { super( settings, family, type ); setDefaultState( getStateContainer().getBaseState() - .with( FACING, EnumFacing.NORTH ) + .with( FACING, Direction.NORTH ) .with( WATERLOGGED, false ) ); } @Override - protected void fillStateContainer( StateContainer.Builder builder ) + protected void fillStateContainer( StateContainer.Builder builder ) { builder.add( FACING, WATERLOGGED ); } @@ -68,30 +71,15 @@ public class BlockTurtle extends BlockComputerBase implements Waterl @Nonnull @Override @Deprecated - public EnumBlockRenderType getRenderType( IBlockState state ) + public BlockRenderType getRenderType( BlockState state ) { - return EnumBlockRenderType.INVISIBLE; - } - - @Override - @Deprecated - public boolean isFullCube( IBlockState state ) - { - return false; + return BlockRenderType.INVISIBLE; } @Nonnull @Override @Deprecated - public BlockFaceShape getBlockFaceShape( IBlockReader world, IBlockState state, BlockPos pos, EnumFacing side ) - { - return BlockFaceShape.UNDEFINED; - } - - @Nonnull - @Override - @Deprecated - public VoxelShape getShape( IBlockState state, IBlockReader world, BlockPos pos ) + public VoxelShape getShape( BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context ) { TileEntity tile = world.getTileEntity( pos ); Vec3d offset = tile instanceof TileTurtle ? ((TileTurtle) tile).getRenderOffset( 1.0f ) : Vec3d.ZERO; @@ -100,7 +88,7 @@ public class BlockTurtle extends BlockComputerBase implements Waterl @Nullable @Override - public IBlockState getStateForPlacement( BlockItemUseContext placement ) + public BlockState getStateForPlacement( BlockItemUseContext placement ) { return getDefaultState() .with( FACING, placement.getPlacementHorizontalFacing() ) @@ -110,7 +98,7 @@ public class BlockTurtle extends BlockComputerBase implements Waterl @Nonnull @Override @Deprecated - public IFluidState getFluidState( IBlockState state ) + public IFluidState getFluidState( BlockState state ) { return getWaterloggedFluidState( state ); } @@ -118,14 +106,14 @@ public class BlockTurtle extends BlockComputerBase implements Waterl @Nonnull @Override @Deprecated - public IBlockState updatePostPlacement( @Nonnull IBlockState state, EnumFacing side, IBlockState otherState, IWorld world, BlockPos pos, BlockPos otherPos ) + public BlockState updatePostPlacement( @Nonnull BlockState state, Direction side, BlockState otherState, IWorld world, BlockPos pos, BlockPos otherPos ) { updateWaterloggedPostPlacement( state, world, pos ); return state; } @Override - public void onBlockPlacedBy( World world, BlockPos pos, IBlockState state, @Nullable EntityLivingBase player, @Nonnull ItemStack stack ) + public void onBlockPlacedBy( World world, BlockPos pos, BlockState state, @Nullable LivingEntity player, @Nonnull ItemStack stack ) { super.onBlockPlacedBy( world, pos, state, player, stack ); @@ -134,9 +122,9 @@ public class BlockTurtle extends BlockComputerBase implements Waterl { TileTurtle turtle = (TileTurtle) tile; - if( player instanceof EntityPlayer ) + if( player instanceof PlayerEntity ) { - ((TileTurtle) tile).setOwningPlayer( ((EntityPlayer) player).getGameProfile() ); + ((TileTurtle) tile).setOwningPlayer( ((PlayerEntity) player).getGameProfile() ); } if( stack.getItem() instanceof ITurtleItem ) @@ -163,9 +151,9 @@ public class BlockTurtle extends BlockComputerBase implements Waterl } @Override - public float getExplosionResistance( IBlockState state, IWorldReader world, BlockPos pos, @Nullable Entity exploder, Explosion explosion ) + public float getExplosionResistance( BlockState state, IWorldReader world, BlockPos pos, @Nullable Entity exploder, Explosion explosion ) { - if( getFamily() == ComputerFamily.Advanced && (exploder instanceof EntityLivingBase || exploder instanceof EntityFireball) ) + if( getFamily() == ComputerFamily.Advanced && (exploder instanceof LivingEntity || exploder instanceof DamagingProjectileEntity) ) { return 2000; } 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 59a396a9c..31933762e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -20,23 +20,23 @@ import dan200.computercraft.shared.computer.blocks.TileComputerBase; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ServerComputer; -import dan200.computercraft.shared.network.Containers; import dan200.computercraft.shared.turtle.apis.TurtleAPI; import dan200.computercraft.shared.turtle.core.TurtleBrain; import dan200.computercraft.shared.util.*; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Items; -import net.minecraft.item.EnumDyeColor; -import net.minecraft.item.ItemDye; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.DyeColor; +import net.minecraft.item.DyeItem; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.item.Items; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.nbt.ListNBT; import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants; @@ -57,12 +57,12 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default public static final int INVENTORY_WIDTH = 4; public static final int INVENTORY_HEIGHT = 4; - public static final NamedBlockEntityType FACTORY_NORMAL = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_NORMAL = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_normal" ), type -> new TileTurtle( type, ComputerFamily.Normal ) ); - public static final NamedBlockEntityType FACTORY_ADVANCED = NamedBlockEntityType.create( + public static final NamedTileEntityType FACTORY_ADVANCED = NamedTileEntityType.create( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ), type -> new TileTurtle( type, ComputerFamily.Advanced ) ); @@ -143,7 +143,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default else { // Just turn off any redstone we had on - for( EnumFacing dir : DirectionUtil.FACINGS ) + for( Direction dir : DirectionUtil.FACINGS ) { RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); } @@ -171,18 +171,18 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public boolean onActivate( EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ ) + public boolean onActivate( PlayerEntity player, Hand hand, BlockRayTraceResult hit ) { // Apply dye ItemStack currentItem = player.getHeldItem( hand ); if( !currentItem.isEmpty() ) { - if( currentItem.getItem() instanceof ItemDye ) + if( currentItem.getItem() instanceof DyeItem ) { // Dye to change turtle colour if( !getWorld().isRemote ) { - EnumDyeColor dye = ((ItemDye) currentItem.getItem()).getDyeColor(); + DyeColor dye = ((DyeItem) currentItem.getItem()).getDyeColor(); if( m_brain.getDyeColour() != dye ) { m_brain.setDyeColour( dye ); @@ -214,23 +214,23 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } // Open GUI or whatever - return super.onActivate( player, hand, side, hitX, hitY, hitZ ); + return super.onActivate( player, hand, hit ); } @Override - protected boolean canNameWithTag( EntityPlayer player ) + protected boolean canNameWithTag( PlayerEntity player ) { return true; } @Override - public void openGUI( EntityPlayer player ) + public void openGUI( PlayerEntity player ) { - Containers.openTurtleGUI( player, this ); + // TODO: Containers.openTurtleGUI( player, this ); } @Override - protected double getInteractRange( EntityPlayer player ) + protected double getInteractRange( PlayerEntity player ) { return 12.0; } @@ -285,17 +285,17 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public void read( NBTTagCompound nbt ) + public void read( CompoundNBT nbt ) { super.read( nbt ); // Read inventory - NBTTagList nbttaglist = nbt.getList( "Items", Constants.NBT.TAG_COMPOUND ); + ListNBT nbttaglist = nbt.getList( "Items", Constants.NBT.TAG_COMPOUND ); m_inventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY ); m_previousInventory = NonNullList.withSize( INVENTORY_SIZE, ItemStack.EMPTY ); for( int i = 0; i < nbttaglist.size(); i++ ) { - NBTTagCompound tag = nbttaglist.getCompound( i ); + CompoundNBT tag = nbttaglist.getCompound( i ); int slot = tag.getByte( "Slot" ) & 0xff; if( slot < getSizeInventory() ) { @@ -310,15 +310,15 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default @Nonnull @Override - public NBTTagCompound write( NBTTagCompound nbt ) + public CompoundNBT write( CompoundNBT nbt ) { // Write inventory - NBTTagList nbttaglist = new NBTTagList(); + ListNBT nbttaglist = new ListNBT(); for( int i = 0; i < INVENTORY_SIZE; i++ ) { if( !m_inventory.get( i ).isEmpty() ) { - NBTTagCompound tag = new NBTTagCompound(); + CompoundNBT tag = new CompoundNBT(); tag.putByte( "Slot", (byte) i ); m_inventory.get( i ).write( tag ); nbttaglist.add( tag ); @@ -341,14 +341,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default // IDirectionalTile @Override - public EnumFacing getDirection() + public Direction getDirection() { return getBlockState().get( BlockTurtle.FACING ); } - public void setDirection( EnumFacing dir ) + public void setDirection( Direction dir ) { - if( dir.getAxis() == EnumFacing.Axis.Y ) dir = EnumFacing.NORTH; + if( dir.getAxis() == Direction.Axis.Y ) dir = Direction.NORTH; world.setBlockState( pos, getBlockState().with( BlockTurtle.FACING, dir ) ); updateOutput(); updateInput(); @@ -536,7 +536,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default } @Override - public boolean isUsableByPlayer( @Nonnull EntityPlayer player ) + public boolean isUsableByPlayer( @Nonnull PlayerEntity player ) { return isUsable( player, false ); } @@ -555,14 +555,14 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default // Networking stuff @Override - protected void writeDescription( @Nonnull NBTTagCompound nbt ) + protected void writeDescription( @Nonnull CompoundNBT nbt ) { super.writeDescription( nbt ); m_brain.writeDescription( nbt ); } @Override - protected void readDescription( @Nonnull NBTTagCompound nbt ) + protected void readDescription( @Nonnull CompoundNBT nbt ) { super.readDescription( nbt ); m_brain.readDescription( nbt ); @@ -601,7 +601,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default @Nullable @Override - public IPeripheral getPeripheral( @Nonnull EnumFacing side ) + public IPeripheral getPeripheral( @Nonnull Direction side ) { return hasMoved() ? null : new ComputerPeripheral( "turtle", createProxy() ); } @@ -613,7 +613,7 @@ public class TileTurtle extends TileComputerBase implements ITurtleTile, Default @Nonnull @Override - public LazyOptional getCapability( @Nonnull Capability cap, @Nullable EnumFacing side ) + public LazyOptional getCapability( @Nonnull Capability cap, @Nullable Direction side ) { if( cap == ITEM_HANDLER_CAPABILITY ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java b/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java index 1e8a5175f..b102c1c53 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/InteractDirection.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.turtle.core; import dan200.computercraft.api.turtle.ITurtleAccess; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; public enum InteractDirection { @@ -15,7 +15,7 @@ public enum InteractDirection Up, Down; - public EnumFacing toWorldDir( ITurtleAccess turtle ) + public Direction toWorldDir( ITurtleAccess turtle ) { switch( this ) { @@ -23,9 +23,9 @@ public enum InteractDirection default: return turtle.getDirection(); case Up: - return EnumFacing.UP; + return Direction.UP; case Down: - return EnumFacing.DOWN; + return Direction.DOWN; } } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java b/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java index 26c6d9681..2be874562 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/MoveDirection.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.turtle.core; import dan200.computercraft.api.turtle.ITurtleAccess; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; public enum MoveDirection { @@ -16,7 +16,7 @@ public enum MoveDirection Up, Down; - public EnumFacing toWorldDir( ITurtleAccess turtle ) + public Direction toWorldDir( ITurtleAccess turtle ) { switch( this ) { @@ -26,9 +26,9 @@ public enum MoveDirection case Back: return turtle.getDirection().getOpposite(); case Up: - return EnumFacing.UP; + return Direction.UP; case Down: - return EnumFacing.DOWN; + return Direction.DOWN; } } } 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 b21c5e763..0920f28b5 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -24,18 +24,18 @@ import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Holiday; import dan200.computercraft.shared.util.HolidayUtil; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.MoverType; import net.minecraft.fluid.IFluidState; -import net.minecraft.init.Particles; import net.minecraft.inventory.IInventory; -import net.minecraft.item.EnumDyeColor; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.item.DyeColor; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.particles.ParticleTypes; import net.minecraft.tags.FluidTags; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EntitySelectors; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; +import net.minecraft.util.EntityPredicates; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; @@ -49,7 +49,7 @@ import java.util.*; import java.util.concurrent.TimeUnit; import static dan200.computercraft.shared.common.IColouredItem.NBT_COLOUR; -import static dan200.computercraft.shared.util.WaterloggableBlock.WATERLOGGED; +import static dan200.computercraft.shared.util.WaterloggableHelpers.WATERLOGGED; public class TurtleBrain implements ITurtleAccess { @@ -73,7 +73,7 @@ public class TurtleBrain implements ITurtleAccess private Map m_upgrades = new EnumMap<>( TurtleSide.class ); private Map peripherals = new EnumMap<>( TurtleSide.class ); - private Map m_upgradeNBTData = new EnumMap<>( TurtleSide.class ); + private Map m_upgradeNBTData = new EnumMap<>( TurtleSide.class ); private int m_selectedSlot = 0; private int m_fuelLevel = 0; @@ -154,7 +154,7 @@ public class TurtleBrain implements ITurtleAccess * * @param nbt The tag to read from */ - private void readCommon( NBTTagCompound nbt ) + private void readCommon( CompoundNBT nbt ) { // Read fields m_colourHex = nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : -1; @@ -177,7 +177,7 @@ public class TurtleBrain implements ITurtleAccess } } - private void writeCommon( NBTTagCompound nbt ) + private void writeCommon( CompoundNBT nbt ) { nbt.putInt( NBT_FUEL, m_fuelLevel ); if( m_colourHex != -1 ) nbt.putInt( NBT_COLOUR, m_colourHex ); @@ -200,7 +200,7 @@ public class TurtleBrain implements ITurtleAccess } } - public void readFromNBT( NBTTagCompound nbt ) + public void readFromNBT( CompoundNBT nbt ) { readCommon( nbt ); @@ -210,7 +210,7 @@ public class TurtleBrain implements ITurtleAccess // Read owner if( nbt.contains( "Owner", Constants.NBT.TAG_COMPOUND ) ) { - NBTTagCompound owner = nbt.getCompound( "Owner" ); + CompoundNBT owner = nbt.getCompound( "Owner" ); m_owningPlayer = new GameProfile( new UUID( owner.getLong( "UpperId" ), owner.getLong( "LowerId" ) ), owner.getString( "Name" ) @@ -222,7 +222,7 @@ public class TurtleBrain implements ITurtleAccess } } - public NBTTagCompound writeToNBT( NBTTagCompound nbt ) + public CompoundNBT writeToNBT( CompoundNBT nbt ) { writeCommon( nbt ); @@ -232,7 +232,7 @@ public class TurtleBrain implements ITurtleAccess // Write owner if( m_owningPlayer != null ) { - NBTTagCompound owner = new NBTTagCompound(); + CompoundNBT owner = new CompoundNBT(); nbt.put( "Owner", owner ); owner.putLong( "UpperId", m_owningPlayer.getId().getMostSignificantBits() ); @@ -248,7 +248,7 @@ public class TurtleBrain implements ITurtleAccess return upgrade != null ? upgrade.getUpgradeID().toString() : null; } - public void readDescription( NBTTagCompound nbt ) + public void readDescription( CompoundNBT nbt ) { readCommon( nbt ); @@ -265,7 +265,7 @@ public class TurtleBrain implements ITurtleAccess } } - public void writeDescription( NBTTagCompound nbt ) + public void writeDescription( CompoundNBT nbt ) { writeCommon( nbt ); nbt.putInt( "Animation", m_animation.ordinal() ); @@ -297,7 +297,7 @@ public class TurtleBrain implements ITurtleAccess World oldWorld = getWorld(); TileTurtle oldOwner = m_owner; BlockPos oldPos = m_owner.getPos(); - IBlockState oldBlock = m_owner.getBlockState(); + BlockState oldBlock = m_owner.getBlockState(); if( oldWorld == world && oldPos.equals( pos ) ) { @@ -312,7 +312,7 @@ public class TurtleBrain implements ITurtleAccess if( !world.getWorldBorder().contains( pos ) ) return false; IFluidState existingFluid = world.getBlockState( pos ).getFluidState(); - IBlockState newState = oldBlock + 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. @@ -340,7 +340,7 @@ public class TurtleBrain implements ITurtleAccess newTurtle.createServerComputer().setPosition( pos ); // Remove the old turtle - oldWorld.removeBlock( oldPos ); + oldWorld.removeBlock( oldPos, false ); // Make sure everybody knows about it newTurtle.updateBlock(); @@ -351,7 +351,7 @@ public class TurtleBrain implements ITurtleAccess } // Something went wrong, remove the newly created turtle - world.removeBlock( pos ); + world.removeBlock( pos, false ); } } finally @@ -406,13 +406,13 @@ public class TurtleBrain implements ITurtleAccess @Nonnull @Override - public EnumFacing getDirection() + public Direction getDirection() { return m_owner.getDirection(); } @Override - public void setDirection( @Nonnull EnumFacing dir ) + public void setDirection( @Nonnull Direction dir ) { m_owner.setDirection( dir ); } @@ -570,14 +570,14 @@ public class TurtleBrain implements ITurtleAccess } } - public EnumDyeColor getDyeColour() + public DyeColor getDyeColour() { if( m_colourHex == -1 ) return null; Colour colour = Colour.fromHex( m_colourHex ); - return colour == null ? null : EnumDyeColor.byId( 15 - colour.ordinal() ); + return colour == null ? null : DyeColor.byId( 15 - colour.ordinal() ); } - public void setDyeColour( EnumDyeColor dyeColour ) + public void setDyeColour( DyeColor dyeColour ) { int newColour = -1; if( dyeColour != null ) @@ -668,10 +668,10 @@ public class TurtleBrain implements ITurtleAccess @Nonnull @Override - public NBTTagCompound getUpgradeNBTData( TurtleSide side ) + public CompoundNBT getUpgradeNBTData( TurtleSide side ) { - NBTTagCompound nbt = m_upgradeNBTData.get( side ); - if( nbt == null ) m_upgradeNBTData.put( side, nbt = new NBTTagCompound() ); + CompoundNBT nbt = m_upgradeNBTData.get( side ); + if( nbt == null ) m_upgradeNBTData.put( side, nbt = new CompoundNBT() ); return nbt; } @@ -691,7 +691,7 @@ public class TurtleBrain implements ITurtleAccess case MoveDown: { // Get direction - EnumFacing dir; + Direction dir; switch( m_animation ) { case MoveForward: @@ -702,10 +702,10 @@ public class TurtleBrain implements ITurtleAccess dir = getDirection().getOpposite(); break; case MoveUp: - dir = EnumFacing.UP; + dir = Direction.UP; break; case MoveDown: - dir = EnumFacing.DOWN; + dir = Direction.DOWN; break; } @@ -838,7 +838,7 @@ public class TurtleBrain implements ITurtleAccess m_animation == TurtleAnimation.MoveDown ) { BlockPos pos = getPosition(); - EnumFacing moveDir; + Direction moveDir; switch( m_animation ) { case MoveForward: @@ -849,10 +849,10 @@ public class TurtleBrain implements ITurtleAccess moveDir = getDirection().getOpposite(); break; case MoveUp: - moveDir = EnumFacing.UP; + moveDir = Direction.UP; break; case MoveDown: - moveDir = EnumFacing.DOWN; + moveDir = Direction.DOWN; break; } @@ -893,7 +893,7 @@ public class TurtleBrain implements ITurtleAccess } AxisAlignedBB aabb = new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ ); - List list = world.getEntitiesWithinAABB( Entity.class, aabb, EntitySelectors.NOT_SPECTATING ); + List list = world.getEntitiesWithinAABB( Entity.class, aabb, EntityPredicates.NOT_SPECTATING ); if( !list.isEmpty() ) { double pushStep = 1.0f / ANIM_DURATION; @@ -902,7 +902,7 @@ public class TurtleBrain implements ITurtleAccess double pushStepZ = moveDir.getZOffset() * pushStep; for( Entity entity : list ) { - entity.move( MoverType.PISTON, pushStepX, pushStepY, pushStepZ ); + entity.move( MoverType.PISTON, new Vec3d( pushStepX, pushStepY, pushStepZ ) ); } } } @@ -922,7 +922,7 @@ public class TurtleBrain implements ITurtleAccess double y = position.y + 0.5 + world.rand.nextGaussian() * 0.1; double z = position.z + world.rand.nextGaussian() * 0.1; world.addParticle( - Particles.HEART, x, y, z, + ParticleTypes.HEART, x, y, z, world.rand.nextGaussian() * 0.02, world.rand.nextGaussian() * 0.02, world.rand.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 7e14655e1..3d143019d 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java @@ -10,16 +10,17 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleCommandResult; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.NonNullList; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.ServerWorld; import net.minecraft.world.World; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import javax.annotation.Nonnull; import java.lang.reflect.Method; +import java.util.List; public class TurtleCompareCommand implements ITurtleCommand { @@ -35,7 +36,7 @@ public class TurtleCompareCommand implements ITurtleCommand public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get world direction from direction - EnumFacing direction = m_direction.toWorldDir( turtle ); + Direction direction = m_direction.toWorldDir( turtle ); // Get currently selected stack ItemStack selectedStack = turtle.getInventory().getStackInSlot( turtle.getSelectedSlot() ); @@ -48,7 +49,7 @@ public class TurtleCompareCommand implements ITurtleCommand ItemStack lookAtStack = ItemStack.EMPTY; if( !world.isAirBlock( newPosition ) ) { - IBlockState lookAtState = world.getBlockState( newPosition ); + BlockState lookAtState = world.getBlockState( newPosition ); Block lookAtBlock = lookAtState.getBlock(); if( !lookAtBlock.isAir( lookAtState, world, newPosition ) ) { @@ -57,7 +58,7 @@ public class TurtleCompareCommand implements ITurtleCommand { try { - Method method = ObfuscationReflectionHelper.findMethod( Block.class, "func_180643_i", IBlockState.class ); + Method method = ObfuscationReflectionHelper.findMethod( Block.class, "func_180643_i", BlockState.class ); lookAtStack = (ItemStack) method.invoke( lookAtBlock, lookAtState ); } catch( ReflectiveOperationException | RuntimeException ignored ) @@ -69,8 +70,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++ ) { - NonNullList drops = NonNullList.create(); - lookAtState.getDrops( drops, world, newPosition, 0 ); + List drops = Block.getDrops( lookAtState, (ServerWorld) world, newPosition, world.getTileEntity( newPosition ) ); if( !drops.isEmpty() ) { for( ItemStack drop : drops ) 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 ab89ae6b0..f450d3b5a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDetectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDetectCommand.java @@ -10,7 +10,7 @@ import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.shared.util.WorldUtil; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -30,7 +30,7 @@ public class TurtleDetectCommand implements ITurtleCommand public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get world direction from direction - EnumFacing direction = m_direction.toWorldDir( turtle ); + Direction direction = m_direction.toWorldDir( turtle ); // Check if thing in front is air or not World world = turtle.getWorld(); 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 21de8bab1..44297639b 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleDropCommand.java @@ -14,7 +14,7 @@ import dan200.computercraft.api.turtle.event.TurtleInventoryEvent; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; @@ -45,7 +45,7 @@ public class TurtleDropCommand implements ITurtleCommand } // Get world direction from direction - EnumFacing direction = m_direction.toWorldDir( turtle ); + Direction direction = m_direction.toWorldDir( turtle ); // Get things to drop ItemStack stack = InventoryUtil.takeItems( m_quantity, turtle.getItemHandler(), turtle.getSelectedSlot(), 1, turtle.getSelectedSlot() ); @@ -58,7 +58,7 @@ public class TurtleDropCommand implements ITurtleCommand World world = turtle.getWorld(); BlockPos oldPosition = turtle.getPosition(); BlockPos newPosition = oldPosition.offset( direction ); - EnumFacing side = direction.getOpposite(); + Direction side = direction.getOpposite(); IItemHandler inventory = InventoryUtil.getInventory( world, newPosition, side ); 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 d1f75e761..3a39bac20 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java @@ -12,9 +12,9 @@ import dan200.computercraft.api.turtle.ITurtleCommand; import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.state.IProperty; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; @@ -38,14 +38,14 @@ public class TurtleInspectCommand implements ITurtleCommand public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get world direction from direction - EnumFacing direction = this.direction.toWorldDir( turtle ); + Direction direction = this.direction.toWorldDir( turtle ); // Check if thing in front is air or not World world = turtle.getWorld(); BlockPos oldPosition = turtle.getPosition(); BlockPos newPosition = oldPosition.offset( direction ); - IBlockState state = world.getBlockState( newPosition ); + BlockState state = world.getBlockState( newPosition ); if( state.getBlock().isAir( state, world, newPosition ) ) { return TurtleCommandResult.failure( "No block to inspect" ); 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 dfe3dd5c1..d6d639523 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleMoveCommand.java @@ -14,12 +14,13 @@ import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.api.turtle.event.TurtleBlockEvent; import dan200.computercraft.shared.TurtlePermissions; import dan200.computercraft.shared.util.WorldUtil; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; @@ -40,7 +41,7 @@ public class TurtleMoveCommand implements ITurtleCommand public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle ) { // Get world direction from direction - EnumFacing direction = m_direction.toWorldDir( turtle ); + Direction direction = m_direction.toWorldDir( turtle ); // Check if we can move World oldWorld = turtle.getWorld(); @@ -55,7 +56,7 @@ public class TurtleMoveCommand implements ITurtleCommand } // Check existing block is air or replaceable - IBlockState state = oldWorld.getBlockState( newPosition ); + BlockState state = oldWorld.getBlockState( newPosition ); if( !oldWorld.isAirBlock( newPosition ) && !WorldUtil.isLiquidBlock( oldWorld, newPosition ) && !state.getMaterial().isReplaceable() ) @@ -64,14 +65,13 @@ public class TurtleMoveCommand implements ITurtleCommand } // Check there isn't anything in the way - AxisAlignedBB aabb = getBox( state.getCollisionShape( oldWorld, oldPosition ) ); - aabb = aabb.offset( + VoxelShape collision = state.getCollisionShape( oldWorld, oldPosition ).withOffset( newPosition.getX(), newPosition.getY(), newPosition.getZ() ); - if( !oldWorld.checkNoEntityCollision( null, aabb ) ) + if( !oldWorld.checkNoEntityCollision( null, collision ) ) { if( !ComputerCraft.turtlesCanPush || m_direction == MoveDirection.Up || m_direction == MoveDirection.Down ) { @@ -79,19 +79,15 @@ public class TurtleMoveCommand implements ITurtleCommand } // Check there is space for all the pushable entities to be pushed - List list = oldWorld.getEntitiesWithinAABB( Entity.class, aabb, x -> x != null && x.isAlive() && x.preventEntitySpawning ); + List list = oldWorld.getEntitiesWithinAABB( Entity.class, getBox( collision ), x -> x != null && x.isAlive() && x.preventEntitySpawning ); for( Entity entity : list ) { - AxisAlignedBB entityBB = entity.getBoundingBox(); - if( entityBB == null ) entityBB = entity.getCollisionBoundingBox(); - if( entityBB == null ) continue; - - AxisAlignedBB pushedBB = entityBB.offset( + AxisAlignedBB pushedBB = entity.getBoundingBox().offset( direction.getXOffset(), direction.getYOffset(), direction.getZOffset() ); - if( !oldWorld.checkNoEntityCollision( null, pushedBB ) ) + if( !oldWorld.checkNoEntityCollision( null, VoxelShapes.create( pushedBB ) ) ) { return TurtleCommandResult.failure( "Movement obstructed" ); } 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 22e65a5eb..b1896cec2 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java @@ -17,19 +17,20 @@ import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.DropConsumer; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.LivingEntity; import net.minecraft.item.*; +import net.minecraft.tileentity.SignTileEntity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.util.ActionResultType; +import net.minecraft.util.Direction; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; @@ -63,7 +64,7 @@ public class TurtlePlaceCommand implements ITurtleCommand } // Remember old block - EnumFacing direction = m_direction.toWorldDir( turtle ); + Direction direction = m_direction.toWorldDir( turtle ); BlockPos coordinates = turtle.getPosition().offset( direction ); // Create a fake player, and orient it appropriately @@ -95,7 +96,7 @@ public class TurtlePlaceCommand implements ITurtleCommand { return TurtleCommandResult.failure( errorMessage[0] ); } - else if( stack.getItem() instanceof ItemBlock ) + else if( stack.getItem() instanceof BlockItem ) { return TurtleCommandResult.failure( "Cannot place block here" ); } @@ -106,7 +107,7 @@ public class TurtlePlaceCommand implements ITurtleCommand } } - public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, EnumFacing direction, Object[] extraArguments, String[] outErrorMessage ) + 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 ); @@ -115,7 +116,7 @@ public class TurtlePlaceCommand implements ITurtleCommand return deploy( stack, turtle, turtlePlayer, direction, extraArguments, outErrorMessage ); } - public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] outErrorMessage ) + public static ItemStack deploy( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, Direction direction, Object[] extraArguments, String[] outErrorMessage ) { // Deploy on an entity ItemStack remainder = deployOnEntity( stack, turtle, turtlePlayer, direction, extraArguments, outErrorMessage ); @@ -140,10 +141,10 @@ public class TurtlePlaceCommand implements ITurtleCommand return remainder; } - if( direction.getAxis() != EnumFacing.Axis.Y ) + if( direction.getAxis() != Direction.Axis.Y ) { // Deploy down on the block in front - remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.down(), EnumFacing.UP, extraArguments, false, outErrorMessage ); + remainder = deployOnBlock( stack, turtle, turtlePlayer, newPosition.down(), Direction.UP, extraArguments, false, outErrorMessage ); if( remainder != stack ) { return remainder; @@ -161,14 +162,14 @@ public class TurtlePlaceCommand implements ITurtleCommand return stack; } - public static TurtlePlayer createPlayer( ITurtleAccess turtle, BlockPos position, EnumFacing direction ) + public static TurtlePlayer createPlayer( ITurtleAccess turtle, BlockPos position, Direction direction ) { TurtlePlayer turtlePlayer = TurtlePlayer.get( turtle ); orientPlayer( turtle, turtlePlayer, position, direction ); return turtlePlayer; } - private static void orientPlayer( ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, EnumFacing direction ) + private static void orientPlayer( ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, Direction direction ) { turtlePlayer.posX = position.getX() + 0.5; turtlePlayer.posY = position.getY() + 0.5; @@ -182,7 +183,7 @@ public class TurtlePlaceCommand implements ITurtleCommand turtlePlayer.posZ += 0.48 * direction.getZOffset(); } - if( direction.getAxis() != EnumFacing.Axis.Y ) + if( direction.getAxis() != Direction.Axis.Y ) { turtlePlayer.rotationYaw = direction.getHorizontalAngle(); turtlePlayer.rotationPitch = 0.0f; @@ -204,7 +205,7 @@ public class TurtlePlaceCommand implements ITurtleCommand } @Nonnull - private static ItemStack deployOnEntity( @Nonnull ItemStack stack, final ITurtleAccess turtle, TurtlePlayer turtlePlayer, EnumFacing direction, Object[] extraArguments, String[] outErrorMessage ) + private static ItemStack deployOnEntity( @Nonnull ItemStack stack, final ITurtleAccess turtle, TurtlePlayer turtlePlayer, Direction direction, Object[] extraArguments, String[] outErrorMessage ) { // See if there is an entity present final World world = turtle.getWorld(); @@ -231,33 +232,33 @@ public class TurtlePlaceCommand implements ITurtleCommand // Place on the entity boolean placed = false; - EnumActionResult cancelResult = ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, EnumHand.MAIN_HAND ); + ActionResultType cancelResult = ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, Hand.MAIN_HAND ); if( cancelResult == null ) { - cancelResult = hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, EnumHand.MAIN_HAND ); + cancelResult = hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, Hand.MAIN_HAND ); } - if( cancelResult == EnumActionResult.SUCCESS ) + if( cancelResult == ActionResultType.SUCCESS ) { placed = true; } else { // See EntityPlayer.interactOn - cancelResult = ForgeHooks.onInteractEntity( turtlePlayer, hitEntity, EnumHand.MAIN_HAND ); - if( cancelResult == EnumActionResult.SUCCESS ) + cancelResult = ForgeHooks.onInteractEntity( turtlePlayer, hitEntity, Hand.MAIN_HAND ); + if( cancelResult == ActionResultType.SUCCESS ) { placed = true; } else if( cancelResult == null ) { - if( hitEntity.processInitialInteract( turtlePlayer, EnumHand.MAIN_HAND ) ) + if( hitEntity.processInitialInteract( turtlePlayer, Hand.MAIN_HAND ) ) { placed = true; } - else if( hitEntity instanceof EntityLivingBase ) + else if( hitEntity instanceof LivingEntity ) { - placed = stackCopy.interactWithEntity( turtlePlayer, (EntityLivingBase) hitEntity, EnumHand.MAIN_HAND ); + placed = stackCopy.interactWithEntity( turtlePlayer, (LivingEntity) hitEntity, Hand.MAIN_HAND ); if( placed ) turtlePlayer.loadInventory( stackCopy ); } } @@ -286,17 +287,17 @@ public class TurtlePlaceCommand implements ITurtleCommand } } - private static boolean canDeployOnBlock( @Nonnull BlockItemUseContext context, ITurtleAccess turtle, TurtlePlayer player, BlockPos position, EnumFacing side, boolean allowReplaceable, String[] outErrorMessage ) + 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 ItemBlock && WorldUtil.isLiquidBlock( world, position )) ) + !(context.getItem().getItem() instanceof BlockItem && WorldUtil.isLiquidBlock( world, position )) ) { return false; } - IBlockState state = world.getBlockState( position ); + BlockState state = world.getBlockState( position ); boolean replaceable = state.isReplaceable( context ); if( !allowReplaceable && replaceable ) return false; @@ -318,10 +319,10 @@ public class TurtlePlaceCommand implements ITurtleCommand } @Nonnull - private static ItemStack deployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, EnumFacing side, Object[] extraArguments, boolean allowReplace, String[] outErrorMessage ) + private static ItemStack deployOnBlock( @Nonnull ItemStack stack, ITurtleAccess turtle, TurtlePlayer turtlePlayer, BlockPos position, Direction side, Object[] extraArguments, boolean allowReplace, String[] outErrorMessage ) { // Re-orient the fake player - EnumFacing playerDir = side.getOpposite(); + Direction playerDir = side.getOpposite(); BlockPos playerPosition = position.offset( side ); orientPlayer( turtle, turtlePlayer, playerPosition, playerDir ); @@ -338,7 +339,8 @@ public class TurtlePlaceCommand implements ITurtleCommand } // Check if there's something suitable to place onto - ItemUseContext context = new ItemUseContext( turtlePlayer, stackCopy, position, side, hitX, hitY, hitZ ); + BlockRayTraceResult hit = new BlockRayTraceResult( new Vec3d( hitX, hitY, hitZ ), side, position, false ); + ItemUseContext context = new ItemUseContext( turtlePlayer, Hand.MAIN_HAND, hit ); if( !canDeployOnBlock( new BlockItemUseContext( context ), turtle, turtlePlayer, position, side, allowReplace, outErrorMessage ) ) { return stack; @@ -353,33 +355,33 @@ public class TurtlePlaceCommand implements ITurtleCommand // See PlayerInteractionManager.processRightClickBlock // TODO: ^ Check we're still consistent. - PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock( turtlePlayer, EnumHand.MAIN_HAND, position, side, new Vec3d( hitX, hitY, hitZ ) ); + PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock( turtlePlayer, Hand.MAIN_HAND, position, side ); if( !event.isCanceled() ) { - if( item.onItemUseFirst( stack, context ) == EnumActionResult.SUCCESS ) + if( item.onItemUseFirst( stack, context ) == ActionResultType.SUCCESS ) { placed = true; turtlePlayer.loadInventory( stackCopy ); } else if( event.getUseItem() != Event.Result.DENY && - stackCopy.onItemUse( context ) == EnumActionResult.SUCCESS ) + stackCopy.onItemUse( context ) == ActionResultType.SUCCESS ) { placed = true; turtlePlayer.loadInventory( stackCopy ); } } - if( !placed && (item instanceof ItemBucket || item instanceof ItemBoat || item instanceof ItemLilyPad || item instanceof ItemGlassBottle) ) + if( !placed && (item instanceof BucketItem || item instanceof BoatItem || item instanceof LilyPadItem || item instanceof GlassBottleItem) ) { - EnumActionResult actionResult = ForgeHooks.onItemRightClick( turtlePlayer, EnumHand.MAIN_HAND ); - if( actionResult == EnumActionResult.SUCCESS ) + ActionResultType actionResult = ForgeHooks.onItemRightClick( turtlePlayer, Hand.MAIN_HAND ); + if( actionResult == ActionResultType.SUCCESS ) { placed = true; } else if( actionResult == null ) { - ActionResult result = stackCopy.useItemRightClick( turtle.getWorld(), turtlePlayer, EnumHand.MAIN_HAND ); - if( result.getType() == EnumActionResult.SUCCESS && !ItemStack.areItemStacksEqual( stack, result.getResult() ) ) + ActionResult result = stackCopy.useItemRightClick( turtle.getWorld(), turtlePlayer, Hand.MAIN_HAND ); + if( result.getType() == ActionResultType.SUCCESS && !ItemStack.areItemStacksEqual( stack, result.getResult() ) ) { placed = true; turtlePlayer.loadInventory( result.getResult() ); @@ -388,7 +390,7 @@ public class TurtlePlaceCommand implements ITurtleCommand } // Set text on signs - if( placed && item instanceof ItemSign ) + if( placed && item instanceof SignItem ) { if( extraArguments != null && extraArguments.length >= 1 && extraArguments[0] instanceof String ) { @@ -398,9 +400,9 @@ public class TurtlePlaceCommand implements ITurtleCommand { tile = world.getTileEntity( position.offset( side ) ); } - if( tile instanceof TileEntitySign ) + if( tile instanceof SignTileEntity ) { - TileEntitySign signTile = (TileEntitySign) tile; + SignTileEntity signTile = (SignTileEntity) tile; String s = (String) extraArguments[0]; String[] split = s.split( "\n" ); int firstLine = split.length <= 2 ? 1 : 0; @@ -410,20 +412,20 @@ public class TurtlePlaceCommand implements ITurtleCommand { if( split[i - firstLine].length() > 15 ) { - signTile.signText[i] = new TextComponentString( split[i - firstLine].substring( 0, 15 ) ); + signTile.signText[i] = new StringTextComponent( split[i - firstLine].substring( 0, 15 ) ); } else { - signTile.signText[i] = new TextComponentString( split[i - firstLine] ); + signTile.signText[i] = new StringTextComponent( split[i - firstLine] ); } } else { - signTile.signText[i] = new TextComponentString( "" ); + signTile.signText[i] = new StringTextComponent( "" ); } } signTile.markDirty(); - world.markBlockRangeForRenderUpdate( signTile.getPos(), signTile.getPos() ); + world.notifyBlockUpdate( tile.getPos(), tile.getBlockState(), tile.getBlockState(), 3 ); } } } 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 564033055..6dadf9126 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlayer.java @@ -11,20 +11,13 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; -import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityType; -import net.minecraft.entity.IMerchant; -import net.minecraft.entity.passive.AbstractHorse; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntitySign; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.IInteractionObject; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; +import net.minecraft.world.ServerWorld; import net.minecraftforge.common.util.FakePlayer; import javax.annotation.Nonnull; @@ -33,24 +26,20 @@ import java.util.UUID; public final class TurtlePlayer extends FakePlayer { - public static final GameProfile DEFAULT_PROFILE = new GameProfile( + private static final GameProfile DEFAULT_PROFILE = new GameProfile( UUID.fromString( "0d0c4ca0-4ff1-11e4-916c-0800200c9a66" ), "[ComputerCraft]" ); - public static final EntityType TYPE = EntityType.Builder.create( TurtlePlayer.class, TurtlePlayer::new ) + public static final EntityType TYPE = EntityType.Builder.create( EntityClassification.MISC ) .disableSerialization() .disableSummoning() + .size( 0, 0 ) .build( ComputerCraft.MOD_ID + ":turtle_player" ); - private TurtlePlayer( World world ) - { - super( (WorldServer) world, DEFAULT_PROFILE ); - } - private TurtlePlayer( ITurtleAccess turtle ) { - super( (WorldServer) turtle.getWorld(), getProfile( turtle.getOwningPlayer() ) ); + super( (ServerWorld) turtle.getWorld(), getProfile( turtle.getOwningPlayer() ) ); setState( turtle ); } @@ -106,7 +95,7 @@ public final class TurtlePlayer extends FakePlayer // Store (or drop) anything else we found BlockPos dropPosition = turtle.getPosition(); - EnumFacing dropDirection = turtle.getDirection().getOpposite(); + Direction dropDirection = turtle.getDirection().getOpposite(); for( int i = 0; i < inventory.getSizeInventory(); i++ ) { ItemStack stack = inventory.getStackInSlot( i ); @@ -124,92 +113,19 @@ public final class TurtlePlayer extends FakePlayer return results; } + @Nonnull + @Override + public EntityType getType() + { + return TYPE; + } + @Override public Vec3d getPositionVector() { return new Vec3d( posX, posY, posZ ); } - @Override - public float getEyeHeight() - { - return 0.0f; - } - - @Override - public float getDefaultEyeHeight() - { - return 0.0f; - } - - @Override - public void sendEnterCombat() - { - } - - @Override - public void sendEndCombat() - { - } - - @Nonnull - @Override - public SleepResult trySleep( @Nonnull BlockPos bedLocation ) - { - return SleepResult.OTHER_PROBLEM; - } - - // TODO: Flesh this out. Or just stub out the connection, like plethora? - - @Override - public void openSignEditor( TileEntitySign signTile ) - { - } - - @Override - public void displayGui( IInteractionObject guiOwner ) - { - } - - @Override - public void displayGUIChest( IInventory chestInventory ) - { - } - - @Override - public void displayVillagerTradeGui( IMerchant villager ) - { - } - - @Override - public void openHorseInventory( AbstractHorse horse, IInventory inventoryIn ) - { - } - - @Override - public void openBook( ItemStack stack, @Nonnull EnumHand hand ) - { - } - - @Override - public void updateHeldItem() - { - } - - @Override - protected void onItemUseFinish() - { - } - - /* - @Override - public void mountEntityAndWakeUp() - { - } - */ - - @Override - public void dismountEntity( @Nonnull Entity entity ) - { - } + // TODO: Work out what needs stubbing again. + // Or just replace the network. } 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 7fd9b598d..37794b732 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java @@ -12,10 +12,10 @@ import dan200.computercraft.api.turtle.TurtleAnimation; import dan200.computercraft.api.turtle.TurtleCommandResult; import dan200.computercraft.api.turtle.event.TurtleInventoryEvent; import dan200.computercraft.shared.util.InventoryUtil; -import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; -import net.minecraft.util.EntitySelectors; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; +import net.minecraft.util.EntityPredicates; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -48,13 +48,13 @@ public class TurtleSuckCommand implements ITurtleCommand } // Get world direction from direction - EnumFacing direction = m_direction.toWorldDir( turtle ); + Direction direction = m_direction.toWorldDir( turtle ); // Get inventory for thing in front World world = turtle.getWorld(); BlockPos turtlePosition = turtle.getPosition(); BlockPos blockPosition = turtlePosition.offset( direction ); - EnumFacing side = direction.getOpposite(); + Direction side = direction.getOpposite(); IItemHandler inventory = InventoryUtil.getInventory( world, blockPosition, side ); @@ -98,10 +98,10 @@ 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( EntityItem.class, aabb, EntitySelectors.IS_ALIVE ); + List list = world.getEntitiesWithinAABB( ItemEntity.class, aabb, EntityPredicates.IS_ALIVE ); if( list.isEmpty() ) return TurtleCommandResult.failure( "No items to take" ); - for( EntityItem entity : list ) + for( ItemEntity entity : list ) { // Suck up the item ItemStack stack = entity.getItem().copy(); 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 26ee1e557..61713a0af 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java @@ -12,11 +12,11 @@ import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.core.InputState; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.core.TurtleBrain; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.inventory.container.Container; +import net.minecraft.inventory.container.ContainerType; +import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; @@ -24,30 +24,29 @@ import javax.annotation.Nullable; public class ContainerTurtle extends Container implements IContainerComputer { - private static final int PROGRESS_ID_SELECTED_SLOT = 0; + public static final ContainerType TYPE = null; - public final int playerInvStartY; - public final int turtleInvStartX; + public static final int PLAYER_START_Y = 134; + public static final int TURTLE_START_X = 175; private final ITurtleAccess m_turtle; private IComputer m_computer; private final InputState input = new InputState( this ); - private int m_selectedSlot; + private int selectedSlot; - protected ContainerTurtle( IInventory playerInventory, ITurtleAccess turtle, int playerInvStartY, int turtleInvStartX ) + protected ContainerTurtle( int id, PlayerInventory playerInventory, ITurtleAccess turtle ) { - this.playerInvStartY = playerInvStartY; - this.turtleInvStartX = turtleInvStartX; + super( TYPE, id ); m_turtle = turtle; - m_selectedSlot = m_turtle.getWorld().isRemote ? 0 : m_turtle.getSelectedSlot(); + selectedSlot = m_turtle.getWorld().isRemote ? 0 : m_turtle.getSelectedSlot(); // Turtle inventory for( int y = 0; y < 4; y++ ) { for( int x = 0; x < 4; x++ ) { - addSlot( new Slot( m_turtle.getInventory(), x + y * 4, turtleInvStartX + 1 + x * 18, playerInvStartY + 1 + y * 18 ) ); + addSlot( new Slot( m_turtle.getInventory(), x + y * 4, TURTLE_START_X + 1 + x * 18, PLAYER_START_Y + 1 + y * 18 ) ); } } @@ -56,83 +55,37 @@ public class ContainerTurtle extends Container implements IContainerComputer { for( int x = 0; x < 9; x++ ) { - addSlot( new Slot( playerInventory, x + y * 9 + 9, 8 + x * 18, playerInvStartY + 1 + y * 18 ) ); + addSlot( new Slot( playerInventory, x + y * 9 + 9, 8 + x * 18, PLAYER_START_Y + 1 + y * 18 ) ); } } // Player hotbar for( int x = 0; x < 9; x++ ) { - addSlot( new Slot( playerInventory, x, 8 + x * 18, playerInvStartY + 3 * 18 + 5 ) ); + addSlot( new Slot( playerInventory, x, 8 + x * 18, PLAYER_START_Y + 3 * 18 + 5 ) ); } } - public ContainerTurtle( IInventory playerInventory, ITurtleAccess turtle ) + public ContainerTurtle( int id, PlayerInventory playerInventory, ITurtleAccess turtle, IComputer computer ) { - this( playerInventory, turtle, 134, 175 ); - } - - public ContainerTurtle( IInventory playerInventory, ITurtleAccess turtle, IComputer computer ) - { - this( playerInventory, turtle ); + this( id, playerInventory, turtle ); m_computer = computer; } public int getSelectedSlot() { - return m_selectedSlot; - } - - private void sendStateToPlayer( IContainerListener listener ) - { - int selectedSlot = m_turtle.getSelectedSlot(); - listener.sendWindowProperty( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot ); + return selectedSlot; } @Override - public void addListener( IContainerListener listener ) - { - super.addListener( listener ); - sendStateToPlayer( listener ); - } - - @Override - public void detectAndSendChanges() - { - super.detectAndSendChanges(); - - int selectedSlot = m_turtle.getSelectedSlot(); - for( IContainerListener listener : listeners ) - { - if( m_selectedSlot != selectedSlot ) - { - listener.sendWindowProperty( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot ); - } - } - m_selectedSlot = selectedSlot; - } - - @Override - public void updateProgressBar( int id, int value ) - { - super.updateProgressBar( id, value ); - switch( id ) - { - case PROGRESS_ID_SELECTED_SLOT: - m_selectedSlot = value; - break; - } - } - - @Override - public boolean canInteractWith( @Nonnull EntityPlayer player ) + public boolean canInteractWith( @Nonnull PlayerEntity player ) { TileTurtle turtle = ((TurtleBrain) m_turtle).getOwner(); return turtle != null && turtle.isUsableByPlayer( player ); } @Nonnull - private ItemStack tryItemMerge( EntityPlayer player, int slotNum, int firstSlot, int lastSlot, boolean reverse ) + private ItemStack tryItemMerge( PlayerEntity player, int slotNum, int firstSlot, int lastSlot, boolean reverse ) { Slot slot = inventorySlots.get( slotNum ); ItemStack originalStack = ItemStack.EMPTY; @@ -168,7 +121,7 @@ public class ContainerTurtle extends Container implements IContainerComputer @Nonnull @Override - public ItemStack transferStackInSlot( EntityPlayer player, int slotNum ) + public ItemStack transferStackInSlot( PlayerEntity player, int slotNum ) { if( slotNum >= 0 && slotNum < 16 ) { @@ -196,7 +149,7 @@ public class ContainerTurtle extends Container implements IContainerComputer } @Override - public void onContainerClosed( EntityPlayer player ) + public void onContainerClosed( PlayerEntity player ) { super.onContainerClosed( player ); input.close(); 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 33519d2d6..889cf1a20 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtle.java @@ -16,12 +16,12 @@ import dan200.computercraft.shared.computer.items.ItemComputerBase; import dan200.computercraft.shared.turtle.blocks.BlockTurtle; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TranslationTextComponent; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -39,7 +39,7 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem { // Build the stack ItemStack stack = new ItemStack( this ); - if( label != null ) stack.setDisplayName( new TextComponentString( label ) ); + if( label != null ) stack.setDisplayName( 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 ); @@ -83,26 +83,26 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem ITurtleUpgrade right = getUpgrade( stack, TurtleSide.Right ); if( left != null && right != null ) { - return new TextComponentTranslation( baseString + ".upgraded_twice", - new TextComponentTranslation( right.getUnlocalisedAdjective() ), - new TextComponentTranslation( left.getUnlocalisedAdjective() ) + return new TranslationTextComponent( baseString + ".upgraded_twice", + new TranslationTextComponent( right.getUnlocalisedAdjective() ), + new TranslationTextComponent( left.getUnlocalisedAdjective() ) ); } else if( left != null ) { - return new TextComponentTranslation( baseString + ".upgraded", - new TextComponentTranslation( left.getUnlocalisedAdjective() ) + return new TranslationTextComponent( baseString + ".upgraded", + new TranslationTextComponent( left.getUnlocalisedAdjective() ) ); } else if( right != null ) { - return new TextComponentTranslation( baseString + ".upgraded", - new TextComponentTranslation( right.getUnlocalisedAdjective() ) + return new TranslationTextComponent( baseString + ".upgraded", + new TranslationTextComponent( right.getUnlocalisedAdjective() ) ); } else { - return new TextComponentTranslation( baseString ); + return new TranslationTextComponent( baseString ); } } @@ -144,7 +144,7 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem @Override public ITurtleUpgrade getUpgrade( @Nonnull ItemStack stack, @Nonnull TurtleSide side ) { - NBTTagCompound tag = stack.getTag(); + CompoundNBT tag = stack.getTag(); if( tag == null ) return null; String key = side == TurtleSide.Left ? NBT_LEFT_UPGRADE : NBT_RIGHT_UPGRADE; @@ -154,14 +154,14 @@ public class ItemTurtle extends ItemComputerBase implements ITurtleItem @Override public ResourceLocation getOverlay( @Nonnull ItemStack stack ) { - NBTTagCompound tag = stack.getTag(); + CompoundNBT tag = stack.getTag(); return tag != null && tag.contains( NBT_OVERLAY ) ? new ResourceLocation( tag.getString( NBT_OVERLAY ) ) : null; } @Override public int getFuelLevel( @Nonnull ItemStack stack ) { - NBTTagCompound tag = stack.getTag(); + CompoundNBT tag = stack.getTag(); return tag != null && tag.contains( NBT_FUEL ) ? tag.getInt( NBT_FUEL ) : 0; } } 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 ff48d31da..103654b99 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java @@ -6,7 +6,6 @@ package dan200.computercraft.shared.turtle.recipes; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.computer.recipe.ComputerFamilyRecipe; @@ -43,7 +42,6 @@ public final class TurtleRecipe extends ComputerFamilyRecipe return TurtleItemFactory.create( computerID, label, -1, getFamily(), null, null, 0, null ); } - private static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ); public static final IRecipeSerializer SERIALIZER = new Serializer() { @Override @@ -51,12 +49,5 @@ public final class TurtleRecipe extends ComputerFamilyRecipe { return new TurtleRecipe( identifier, group, width, height, ingredients, result, family ); } - - @Nonnull - @Override - public ResourceLocation getName() - { - return ID; - } }; } 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 c896666f6..40a01cf6e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java @@ -6,24 +6,23 @@ package dan200.computercraft.shared.turtle.recipes; -import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.shared.TurtleUpgrades; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.turtle.items.ITurtleItem; import dan200.computercraft.shared.turtle.items.TurtleItemFactory; -import dan200.computercraft.shared.util.AbstractRecipe; -import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.RecipeSerializers; +import net.minecraft.item.crafting.SpecialRecipe; +import net.minecraft.item.crafting.SpecialRecipeSerializer; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import javax.annotation.Nonnull; -public final class TurtleUpgradeRecipe extends AbstractRecipe +public final class TurtleUpgradeRecipe extends SpecialRecipe { private TurtleUpgradeRecipe( ResourceLocation id ) { @@ -44,14 +43,14 @@ public final class TurtleUpgradeRecipe extends AbstractRecipe } @Override - public boolean matches( @Nonnull IInventory inventory, @Nonnull World world ) + public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world ) { return !getCraftingResult( inventory ).isEmpty(); } @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull IInventory inventory ) + public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) { // Scan the grid for a row containing a turtle and 1 or 2 items ItemStack leftItem = ItemStack.EMPTY; @@ -187,7 +186,5 @@ public final class TurtleUpgradeRecipe extends AbstractRecipe return SERIALIZER; } - public static final IRecipeSerializer SERIALIZER = new RecipeSerializers.SimpleSerializer<>( - ComputerCraft.MOD_ID + ":turtle_upgrade", TurtleUpgradeRecipe::new - ); + public static final IRecipeSerializer SERIALIZER = new SpecialRecipeSerializer<>( TurtleUpgradeRecipe::new ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java index 884781afc..c73df2afc 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleCraftingTable.java @@ -11,11 +11,11 @@ import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleUpgradeType; +import net.minecraft.block.Blocks; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ModelManager; import net.minecraft.client.renderer.model.ModelResourceLocation; -import net.minecraft.init.Blocks; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; 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 13a7e6d17..e7dda6993 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleHoe.java @@ -12,11 +12,11 @@ import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleVerb; import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand; import dan200.computercraft.shared.turtle.core.TurtlePlayer; +import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -36,7 +36,7 @@ public class TurtleHoe extends TurtleTool } @Override - protected boolean canBreakBlock( IBlockState state, World world, BlockPos pos, TurtlePlayer player ) + protected boolean canBreakBlock( BlockState state, World world, BlockPos pos, TurtlePlayer player ) { if( !super.canBreakBlock( state, world, pos, player ) ) return false; @@ -46,12 +46,12 @@ public class TurtleHoe extends TurtleTool material == Material.GOURD || material == Material.LEAVES || material == Material.OCEAN_PLANT || - material == Material.VINE; + material == Material.TALL_PLANTS; } @Nonnull @Override - public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction ) { if( verb == TurtleVerb.Dig ) { 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 169dd98cc..85fe72fea 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java @@ -9,17 +9,15 @@ package dan200.computercraft.shared.turtle.upgrades; import dan200.computercraft.api.turtle.ITurtleAccess; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.core.TurtlePlayer; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.IRecipeType; import net.minecraft.util.NonNullList; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.world.ServerWorld; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.common.crafting.VanillaRecipeTypes; import net.minecraftforge.fml.hooks.BasicEventHooks; import javax.annotation.Nonnull; @@ -28,7 +26,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class TurtleInventoryCrafting extends InventoryCrafting +public class TurtleInventoryCrafting extends CraftingInventory { private ITurtleAccess m_turtle; private int m_xStart; @@ -46,7 +44,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting } @Nullable - private IRecipe tryCrafting( int xStart, int yStart ) + private IRecipe tryCrafting( int xStart, int yStart ) { m_xStart = xStart; m_yStart = yStart; @@ -68,16 +66,16 @@ public class TurtleInventoryCrafting extends InventoryCrafting } // Check the actual crafting - return m_turtle.getWorld().getRecipeManager().getRecipe( this, m_turtle.getWorld(), VanillaRecipeTypes.CRAFTING ); + return m_turtle.getWorld().getRecipeManager().func_215371_a( IRecipeType.field_222149_a, this, m_turtle.getWorld() ).orElse( null ); } @Nullable public List doCrafting( World world, int maxCount ) { - if( world.isRemote || !(world instanceof WorldServer) ) return null; + if( world.isRemote || !(world instanceof ServerWorld) ) return null; // Find out what we can craft - IRecipe recipe = tryCrafting( 0, 0 ); + IRecipe recipe = tryCrafting( 0, 0 ); if( recipe == null ) recipe = tryCrafting( 0, 1 ); if( recipe == null ) recipe = tryCrafting( 1, 0 ); if( recipe == null ) recipe = tryCrafting( 1, 1 ); @@ -173,19 +171,6 @@ public class TurtleInventoryCrafting extends InventoryCrafting return m_turtle.getInventory().getStackInSlot( i ); } - @Nonnull - @Override - public ITextComponent getName() - { - return new TextComponentString( "" ); - } - - @Override - public boolean hasCustomName() - { - return false; - } - @Nonnull @Override public ItemStack removeStackFromSlot( int i ) @@ -222,7 +207,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting } @Override - public boolean isUsableByPlayer( EntityPlayer player ) + public boolean isUsableByPlayer( PlayerEntity player ) { return true; } 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 4fa8e9a62..e6bbcf6d5 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleModem.java @@ -16,8 +16,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ModelManager; import net.minecraft.client.renderer.model.ModelResourceLocation; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -100,7 +100,7 @@ public class TurtleModem extends AbstractTurtleUpgrade @Nonnull @Override - public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing dir ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction dir ) { return TurtleCommandResult.failure(); } @@ -137,7 +137,7 @@ public class TurtleModem extends AbstractTurtleUpgrade boolean active = false; if( turtle != null ) { - NBTTagCompound turtleNBT = turtle.getUpgradeNBTData( side ); + CompoundNBT turtleNBT = turtle.getUpgradeNBTData( side ); if( turtleNBT.contains( "active" ) ) { active = turtleNBT.getBoolean( "active" ); 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 464765a8e..8c30075f6 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleShovel.java @@ -12,11 +12,11 @@ import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleVerb; import dan200.computercraft.shared.turtle.core.TurtlePlaceCommand; import dan200.computercraft.shared.turtle.core.TurtlePlayer; +import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -36,27 +36,26 @@ public class TurtleShovel extends TurtleTool } @Override - protected boolean canBreakBlock( IBlockState state, World world, BlockPos pos, TurtlePlayer player ) + protected boolean canBreakBlock( BlockState state, World world, BlockPos pos, TurtlePlayer player ) { if( !super.canBreakBlock( state, world, pos, player ) ) return false; Material material = state.getMaterial(); - return material == Material.GROUND || + return material == Material.EARTH || material == Material.SAND || material == Material.SNOW || material == Material.CLAY || - material == Material.CRAFTED_SNOW || - material == Material.GRASS || + material == Material.SNOW_BLOCK || material == Material.PLANTS || material == Material.CACTUS || material == Material.GOURD || material == Material.LEAVES || - material == Material.VINE; + material == Material.TALL_PLANTS; } @Nonnull @Override - public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction ) { if( verb == TurtleVerb.Dig ) { 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 31b445081..dd6a64daf 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleSword.java @@ -7,8 +7,8 @@ package dan200.computercraft.shared.turtle.upgrades; import dan200.computercraft.shared.turtle.core.TurtlePlayer; +import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; -import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -27,15 +27,15 @@ public class TurtleSword extends TurtleTool } @Override - protected boolean canBreakBlock( IBlockState state, World world, BlockPos pos, TurtlePlayer player ) + protected boolean canBreakBlock( BlockState state, World world, BlockPos pos, TurtlePlayer player ) { if( !super.canBreakBlock( state, world, pos, player ) ) return false; Material material = state.getMaterial(); return material == Material.PLANTS || material == Material.LEAVES || - material == Material.VINE || - material == Material.CLOTH || + material == Material.TALL_PLANTS || + 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 3d64cd141..5f82731b9 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleTool.java @@ -18,19 +18,19 @@ import dan200.computercraft.shared.util.DropConsumer; import dan200.computercraft.shared.util.InventoryUtil; import dan200.computercraft.shared.util.WorldUtil; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.entity.Entity; import net.minecraft.entity.SharedMonsterAttributes; -import net.minecraft.entity.item.EntityArmorStand; +import net.minecraft.entity.item.ArmorStandEntity; import net.minecraft.fluid.IFluidState; -import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.DamageSource; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -84,7 +84,7 @@ public class TurtleTool extends AbstractTurtleUpgrade @Nonnull @Override - public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction ) + public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction ) { switch( verb ) { @@ -97,7 +97,7 @@ public class TurtleTool extends AbstractTurtleUpgrade } } - protected boolean canBreakBlock( IBlockState state, World world, BlockPos pos, TurtlePlayer player ) + protected boolean canBreakBlock( BlockState state, World world, BlockPos pos, TurtlePlayer player ) { Block block = state.getBlock(); return !state.isAir( world, pos ) @@ -111,7 +111,7 @@ public class TurtleTool extends AbstractTurtleUpgrade return 3.0f; } - private TurtleCommandResult attack( final ITurtleAccess turtle, EnumFacing direction, TurtleSide side ) + private TurtleCommandResult attack( final ITurtleAccess turtle, Direction direction, TurtleSide side ) { // Create a fake player, and orient it appropriately final World world = turtle.getWorld(); @@ -154,7 +154,7 @@ public class TurtleTool extends AbstractTurtleUpgrade if( damage > 0.0f ) { DamageSource source = DamageSource.causePlayerDamage( turtlePlayer ); - if( hitEntity instanceof EntityArmorStand ) + if( hitEntity instanceof ArmorStandEntity ) { // Special case for armor stands: attack twice to guarantee destroy hitEntity.attackEntityFrom( source, damage ); @@ -188,7 +188,7 @@ public class TurtleTool extends AbstractTurtleUpgrade return TurtleCommandResult.failure( "Nothing to attack here" ); } - private TurtleCommandResult dig( ITurtleAccess turtle, EnumFacing direction, TurtleSide side ) + private TurtleCommandResult dig( ITurtleAccess turtle, Direction direction, TurtleSide side ) { // Get ready to dig World world = turtle.getWorld(); @@ -200,7 +200,7 @@ public class TurtleTool extends AbstractTurtleUpgrade return TurtleCommandResult.failure( "Nothing to dig here" ); } - IBlockState state = world.getBlockState( blockPosition ); + BlockState state = world.getBlockState( blockPosition ); IFluidState fluidState = world.getFluidState( blockPosition ); TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, turtlePosition, direction ); diff --git a/src/main/java/dan200/computercraft/shared/util/AbstractRecipe.java b/src/main/java/dan200/computercraft/shared/util/AbstractRecipe.java deleted file mode 100644 index a6908bbee..000000000 --- a/src/main/java/dan200/computercraft/shared/util/AbstractRecipe.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.util; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.ResourceLocation; - -import javax.annotation.Nonnull; - -public abstract class AbstractRecipe implements IRecipe -{ - private final ResourceLocation id; - - public AbstractRecipe( ResourceLocation id ) - { - this.id = id; - } - - @Nonnull - @Override - public ItemStack getRecipeOutput() - { - return ItemStack.EMPTY; - } - - @Nonnull - @Override - public ResourceLocation getId() - { - return id; - } - - @Override - public boolean isDynamic() - { - return true; - } -} diff --git a/src/main/java/dan200/computercraft/shared/util/ColourTracker.java b/src/main/java/dan200/computercraft/shared/util/ColourTracker.java index 41152fb4c..ae0c9f403 100644 --- a/src/main/java/dan200/computercraft/shared/util/ColourTracker.java +++ b/src/main/java/dan200/computercraft/shared/util/ColourTracker.java @@ -6,8 +6,10 @@ package dan200.computercraft.shared.util; +import net.minecraft.item.crafting.ArmorDyeRecipe; + /** - * A reimplementation of the colour system in {@link net.minecraft.item.crafting.RecipesArmorDyes}, but + * A reimplementation of the colour system in {@link ArmorDyeRecipe}, but * bundled together as an object. */ public class ColourTracker diff --git a/src/main/java/dan200/computercraft/shared/util/ColourUtils.java b/src/main/java/dan200/computercraft/shared/util/ColourUtils.java index 22d47f827..dcf0ee2b0 100644 --- a/src/main/java/dan200/computercraft/shared/util/ColourUtils.java +++ b/src/main/java/dan200/computercraft/shared/util/ColourUtils.java @@ -6,7 +6,7 @@ package dan200.computercraft.shared.util; -import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.DyeColor; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tags.Tag; @@ -39,12 +39,12 @@ public final class ColourUtils @Nullable private ColourUtils() {} - public static EnumDyeColor getStackColour( ItemStack stack ) + public static DyeColor getStackColour( ItemStack stack ) { for( int i = 0; i < DYES.length; i++ ) { Tag dye = DYES[i]; - if( dye.contains( stack.getItem() ) ) return EnumDyeColor.byId( i ); + if( dye.contains( stack.getItem() ) ) return DyeColor.byId( i ); } return null; diff --git a/src/main/java/dan200/computercraft/shared/util/DefaultInteractionObject.java b/src/main/java/dan200/computercraft/shared/util/DefaultInteractionObject.java deleted file mode 100644 index 878f2951a..000000000 --- a/src/main/java/dan200/computercraft/shared/util/DefaultInteractionObject.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.util; - -import dan200.computercraft.shared.network.container.ContainerType; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.world.IInteractionObject; - -import javax.annotation.Nonnull; - -public interface DefaultInteractionObject extends IInteractionObject -{ - @Nonnull - @Override - T createContainer( @Nonnull InventoryPlayer inventory, @Nonnull EntityPlayer player ); - - @Nonnull - ContainerType getContainerType(); - - @Nonnull - @Override - default String getGuiID() - { - return getContainerType().getId().toString(); - } -} diff --git a/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java b/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java index dbaf26825..0a369e72b 100644 --- a/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java +++ b/src/main/java/dan200/computercraft/shared/util/DefaultInventory.java @@ -6,13 +6,11 @@ package dan200.computercraft.shared.util; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; import javax.annotation.Nonnull; -import javax.annotation.Nullable; public interface DefaultInventory extends IInventory { @@ -23,12 +21,12 @@ public interface DefaultInventory extends IInventory } @Override - default void openInventory( @Nonnull EntityPlayer player ) + default void openInventory( @Nonnull PlayerEntity player ) { } @Override - default void closeInventory( @Nonnull EntityPlayer player ) + default void closeInventory( @Nonnull PlayerEntity player ) { } @@ -37,34 +35,4 @@ public interface DefaultInventory extends IInventory { return true; } - - @Override - default int getField( int field ) - { - return 0; - } - - @Override - default void setField( int field, int value ) - { - } - - @Override - default int getFieldCount() - { - return 0; - } - - @Override - default boolean hasCustomName() - { - return getCustomName() != null; - } - - @Nullable - @Override - default ITextComponent getCustomName() - { - return null; - } } diff --git a/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java b/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java index 2c1f0bc24..e02ea273b 100644 --- a/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java +++ b/src/main/java/dan200/computercraft/shared/util/DefaultSidedInventory.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.util; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -16,13 +16,13 @@ import javax.annotation.Nullable; public interface DefaultSidedInventory extends DefaultInventory, ISidedInventory { @Override - default boolean canInsertItem( int slot, @Nonnull ItemStack stack, @Nullable EnumFacing side ) + default boolean canInsertItem( int slot, @Nonnull ItemStack stack, @Nullable Direction side ) { return isItemValidForSlot( slot, stack ); } @Override - default boolean canExtractItem( int slot, @Nonnull ItemStack stack, @Nonnull EnumFacing side ) + default boolean canExtractItem( 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 cee516e4c..6c6de1087 100644 --- a/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/DirectionUtil.java @@ -7,27 +7,27 @@ package dan200.computercraft.shared.util; import dan200.computercraft.core.computer.ComputerSide; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; public final class DirectionUtil { private DirectionUtil() {} - public static final EnumFacing[] FACINGS = EnumFacing.values(); + public static final Direction[] FACINGS = Direction.values(); - public static ComputerSide toLocal( EnumFacing front, EnumFacing dir ) + public static ComputerSide toLocal( Direction front, Direction dir ) { - if( front.getAxis() == EnumFacing.Axis.Y ) front = EnumFacing.NORTH; + if( front.getAxis() == Direction.Axis.Y ) front = Direction.NORTH; 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 == EnumFacing.UP ) return ComputerSide.TOP; + if( dir == Direction.UP ) return ComputerSide.TOP; return ComputerSide.BOTTOM; } - public static float toPitchAngle( EnumFacing dir ) + public static float toPitchAngle( Direction dir ) { switch( dir ) { diff --git a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java index 701dc8dbd..ca28204bf 100644 --- a/src/main/java/dan200/computercraft/shared/util/DropConsumer.java +++ b/src/main/java/dan200/computercraft/shared/util/DropConsumer.java @@ -8,7 +8,7 @@ package dan200.computercraft.shared.util; import dan200.computercraft.ComputerCraft; import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; @@ -69,10 +69,10 @@ public final class DropConsumer Entity entity = dropEntity.get(); if( entity != null ) { - Collection dropped = entity.captureDrops( null ); + Collection dropped = entity.captureDrops( null ); if( dropped != null ) { - for( EntityItem entityItem : dropped ) handleDrops( entityItem.getItem() ); + for( ItemEntity entityItem : dropped ) handleDrops( entityItem.getItem() ); } } } @@ -101,8 +101,8 @@ public final class DropConsumer // Capture any mob drops for the current entity if( dropEntity != null && event.getEntity() == dropEntity.get() ) { - Collection drops = event.getDrops(); - for( EntityItem entityItem : drops ) handleDrops( entityItem.getItem() ); + Collection drops = event.getDrops(); + for( ItemEntity entityItem : drops ) handleDrops( entityItem.getItem() ); drops.clear(); } } @@ -126,10 +126,10 @@ public final class DropConsumer public static void onEntitySpawn( EntityJoinWorldEvent event ) { // Capture any nearby item spawns - if( dropWorld != null && dropWorld.get() == event.getWorld() && event.getEntity() instanceof EntityItem + if( dropWorld != null && dropWorld.get() == event.getWorld() && event.getEntity() instanceof ItemEntity && dropBounds.contains( event.getEntity().getPositionVector() ) ) { - handleDrops( ((EntityItem) event.getEntity()).getItem() ); + handleDrops( ((ItemEntity) event.getEntity()).getItem() ); event.setCanceled( true ); } } diff --git a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java index fa388a76f..1c12f20cc 100644 --- a/src/main/java/dan200/computercraft/shared/util/IDAssigner.java +++ b/src/main/java/dan200/computercraft/shared/util/IDAssigner.java @@ -43,7 +43,7 @@ public final class IDAssigner public static File getDir() { MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); - File worldDirectory = server.getWorld( DimensionType.OVERWORLD ).getSaveHandler().getWorldDirectory(); + File worldDirectory = server.getWorld( DimensionType.OVERWORLD ).func_217485_w().getWorldDirectory(); // getSaveHandler 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 dd4d0d86e..8a582f341 100644 --- a/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java +++ b/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java @@ -7,15 +7,13 @@ package dan200.computercraft.shared.util; import com.google.gson.JsonObject; -import dan200.computercraft.ComputerCraft; -import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.RecipeSerializers; import net.minecraft.item.crafting.ShapedRecipe; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.JsonUtils; +import net.minecraft.util.JSONUtils; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; @@ -41,14 +39,14 @@ public final class ImpostorRecipe extends ShapedRecipe } @Override - public boolean matches( @Nonnull IInventory inv, World world ) + public boolean matches( @Nonnull CraftingInventory inv, World world ) { return false; } @Nonnull @Override - public ItemStack getCraftingResult( @Nonnull IInventory inventory ) + public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory ) { return ItemStack.EMPTY; } @@ -60,15 +58,14 @@ public final class ImpostorRecipe extends ShapedRecipe return SERIALIZER; } - private static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shaped" ); public static final IRecipeSerializer SERIALIZER = new IRecipeSerializer() { @Override public ImpostorRecipe read( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json ) { - String group = JsonUtils.getString( json, "group", "" ); - ShapedRecipe recipe = RecipeSerializers.CRAFTING_SHAPED.read( identifier, json ); - ItemStack result = CraftingHelper.getItemStack( JsonUtils.getJsonObject( json, "result" ), true ); + String group = JSONUtils.getString( json, "group", "" ); + ShapedRecipe recipe = IRecipeSerializer.field_222157_a.read( identifier, json ); + ItemStack result = CraftingHelper.getItemStack( JSONUtils.getJsonObject( json, "result" ), true ); return new ImpostorRecipe( identifier, group, recipe.getWidth(), recipe.getHeight(), recipe.getIngredients(), result ); } @@ -93,12 +90,5 @@ public final class ImpostorRecipe extends ShapedRecipe for( Ingredient ingredient : recipe.getIngredients() ) ingredient.write( buf ); buf.writeItemStack( recipe.getRecipeOutput() ); } - - @Nonnull - @Override - public ResourceLocation getName() - { - return ID; - } }; } diff --git a/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java b/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java index 889ed2869..779f7e470 100644 --- a/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java +++ b/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java @@ -9,14 +9,13 @@ package dan200.computercraft.shared.util; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import dan200.computercraft.ComputerCraft; -import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.ShapelessRecipe; import net.minecraft.network.PacketBuffer; -import net.minecraft.util.JsonUtils; +import net.minecraft.util.JSONUtils; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; @@ -42,14 +41,14 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe } @Override - public boolean matches( IInventory inv, World world ) + public boolean matches( CraftingInventory inv, World world ) { return false; } @Nonnull @Override - public ItemStack getCraftingResult( IInventory inventory ) + public ItemStack getCraftingResult( CraftingInventory inventory ) { return ItemStack.EMPTY; } @@ -61,15 +60,13 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe return SERIALIZER; } - private static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shapeless" ); - public static final IRecipeSerializer SERIALIZER = new IRecipeSerializer() { @Override public ImpostorShapelessRecipe read( @Nonnull ResourceLocation id, @Nonnull JsonObject json ) { - String s = JsonUtils.getString( json, "group", "" ); - NonNullList ingredients = readIngredients( JsonUtils.getJsonArray( json, "ingredients" ) ); + String s = JSONUtils.getString( json, "group", "" ); + NonNullList ingredients = readIngredients( JSONUtils.getJsonArray( json, "ingredients" ) ); if( ingredients.isEmpty() ) throw new JsonParseException( "No ingredients for shapeless recipe" ); if( ingredients.size() > 9 ) @@ -77,7 +74,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.getJsonObject( json, "result" ), true ); return new ImpostorShapelessRecipe( id, s, itemstack, ingredients ); } @@ -115,12 +112,5 @@ public final class ImpostorShapelessRecipe extends ShapelessRecipe for( Ingredient ingredient : recipe.getIngredients() ) ingredient.write( buffer ); buffer.writeItemStack( recipe.getRecipeOutput() ); } - - @Nonnull - @Override - public ResourceLocation getName() - { - return ID; - } }; } diff --git a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java index d67223e24..3cd4d006e 100644 --- a/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/InventoryUtil.java @@ -10,9 +10,9 @@ import net.minecraft.entity.Entity; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -62,8 +62,8 @@ public final class InventoryUtil // A more expanded form of ItemStack.areShareTagsEqual, but allowing an empty tag to be equal to a // null one. - NBTTagCompound shareTagA = a.getItem().getShareTag( a ); - NBTTagCompound shareTagB = b.getItem().getShareTag( b ); + CompoundNBT shareTagA = a.getItem().getShareTag( a ); + CompoundNBT shareTagB = b.getItem().getShareTag( b ); if( shareTagA == shareTagB ) return true; if( shareTagA == null ) return shareTagB.isEmpty(); if( shareTagB == null ) return shareTagA.isEmpty(); @@ -78,7 +78,7 @@ public final class InventoryUtil // Methods for finding inventories: - public static IItemHandler getInventory( World world, BlockPos pos, EnumFacing side ) + public static IItemHandler getInventory( World world, BlockPos pos, Direction side ) { // Look for tile with inventory TileEntity tileEntity = world.getTileEntity( pos ); @@ -105,7 +105,7 @@ public final class InventoryUtil pos.getY() + 0.5 + 0.6 * side.getYOffset(), pos.getZ() + 0.5 + 0.6 * side.getZOffset() ); - EnumFacing dir = side.getOpposite(); + Direction dir = side.getOpposite(); Vec3d vecDir = new Vec3d( dir.getXOffset(), dir.getYOffset(), dir.getZOffset() ); diff --git a/src/main/java/dan200/computercraft/shared/util/NBTUtil.java b/src/main/java/dan200/computercraft/shared/util/NBTUtil.java index 9a115002b..7dfbbb540 100644 --- a/src/main/java/dan200/computercraft/shared/util/NBTUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/NBTUtil.java @@ -18,21 +18,21 @@ public final class NBTUtil { private NBTUtil() {} - private static INBTBase toNBTTag( Object object ) + private static INBT toNBTTag( Object object ) { if( object == null ) return null; - if( object instanceof Boolean ) return new NBTTagByte( (byte) ((boolean) (Boolean) object ? 1 : 0) ); - if( object instanceof Number ) return new NBTTagDouble( ((Number) object).doubleValue() ); - if( object instanceof String ) return new NBTTagString( object.toString() ); + if( object instanceof Boolean ) return new ByteNBT( (byte) ((boolean) (Boolean) object ? 1 : 0) ); + if( object instanceof Number ) return new DoubleNBT( ((Number) object).doubleValue() ); + if( object instanceof String ) return new StringNBT( object.toString() ); if( object instanceof Map ) { Map m = (Map) object; - NBTTagCompound nbt = new NBTTagCompound(); + CompoundNBT nbt = new CompoundNBT(); int i = 0; for( Map.Entry entry : m.entrySet() ) { - INBTBase key = toNBTTag( entry.getKey() ); - INBTBase value = toNBTTag( entry.getKey() ); + INBT key = toNBTTag( entry.getKey() ); + INBT value = toNBTTag( entry.getKey() ); if( key != null && value != null ) { nbt.put( "k" + i, key ); @@ -47,35 +47,35 @@ public final class NBTUtil return null; } - public static NBTTagCompound encodeObjects( Object[] objects ) + public static CompoundNBT encodeObjects( Object[] objects ) { if( objects == null || objects.length <= 0 ) return null; - NBTTagCompound nbt = new NBTTagCompound(); + CompoundNBT nbt = new CompoundNBT(); nbt.putInt( "len", objects.length ); for( int i = 0; i < objects.length; i++ ) { - INBTBase child = toNBTTag( objects[i] ); + INBT child = toNBTTag( objects[i] ); if( child != null ) nbt.put( Integer.toString( i ), child ); } return nbt; } - private static Object fromNBTTag( INBTBase tag ) + private static Object fromNBTTag( INBT tag ) { if( tag == null ) return null; switch( tag.getId() ) { case TAG_BYTE: - return ((NBTTagByte) tag).getByte() > 0; + return ((ByteNBT) tag).getByte() > 0; case TAG_DOUBLE: - return ((NBTTagDouble) tag).getDouble(); + return ((DoubleNBT) tag).getDouble(); default: case TAG_STRING: return tag.getString(); case TAG_COMPOUND: { - NBTTagCompound c = (NBTTagCompound) tag; + CompoundNBT c = (CompoundNBT) tag; int len = c.getInt( "len" ); Map map = new HashMap<>( len ); for( int i = 0; i < len; i++ ) @@ -89,7 +89,7 @@ public final class NBTUtil } } - public static Object toLua( INBTBase tag ) + public static Object toLua( INBT tag ) { if( tag == null ) return null; @@ -100,15 +100,15 @@ public final class NBTUtil case Constants.NBT.TAG_SHORT: case Constants.NBT.TAG_INT: case Constants.NBT.TAG_LONG: - return ((NBTPrimitive) tag).getLong(); + return ((NumberNBT) tag).getLong(); case Constants.NBT.TAG_FLOAT: case Constants.NBT.TAG_DOUBLE: - return ((NBTPrimitive) tag).getDouble(); + return ((NumberNBT) tag).getDouble(); case Constants.NBT.TAG_STRING: // String return tag.getString(); case Constants.NBT.TAG_COMPOUND: // Compound { - NBTTagCompound compound = (NBTTagCompound) tag; + CompoundNBT compound = (CompoundNBT) tag; Map map = new HashMap<>( compound.size() ); for( String key : compound.keySet() ) { @@ -119,21 +119,21 @@ public final class NBTUtil } case Constants.NBT.TAG_LIST: { - NBTTagList list = (NBTTagList) tag; + ListNBT list = (ListNBT) tag; Map map = new HashMap<>( list.size() ); for( int i = 0; i < list.size(); i++ ) map.put( i, toLua( list.get( i ) ) ); return map; } case Constants.NBT.TAG_BYTE_ARRAY: { - byte[] array = ((NBTTagByteArray) tag).getByteArray(); + byte[] array = ((ByteArrayNBT) tag).getByteArray(); 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 = ((NBTTagIntArray) tag).getIntArray(); + int[] array = ((IntArrayNBT) tag).getIntArray(); Map map = new HashMap<>( array.length ); for( int i = 0; i < array.length; i++ ) map.put( i + 1, array[i] ); return map; @@ -144,7 +144,7 @@ public final class NBTUtil } } - public static Object[] decodeObjects( NBTTagCompound tag ) + public static Object[] decodeObjects( CompoundNBT tag ) { int len = tag.getInt( "len" ); if( len <= 0 ) return null; diff --git a/src/main/java/dan200/computercraft/shared/util/NamedBlockEntityType.java b/src/main/java/dan200/computercraft/shared/util/NamedTileEntityType.java similarity index 58% rename from src/main/java/dan200/computercraft/shared/util/NamedBlockEntityType.java rename to src/main/java/dan200/computercraft/shared/util/NamedTileEntityType.java index db4c0caad..42f292495 100644 --- a/src/main/java/dan200/computercraft/shared/util/NamedBlockEntityType.java +++ b/src/main/java/dan200/computercraft/shared/util/NamedTileEntityType.java @@ -9,6 +9,7 @@ package dan200.computercraft.shared.util; import com.mojang.datafixers.DataFixUtils; import com.mojang.datafixers.types.Type; import dan200.computercraft.ComputerCraft; +import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.ResourceLocation; @@ -16,36 +17,52 @@ import net.minecraft.util.SharedConstants; import net.minecraft.util.datafix.DataFixesManager; import net.minecraft.util.datafix.TypeReferences; +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.Objects; import java.util.function.Function; import java.util.function.Supplier; -public final class NamedBlockEntityType extends TileEntityType +public final class NamedTileEntityType extends TileEntityType { private final ResourceLocation identifier; + private Block block; - private NamedBlockEntityType( ResourceLocation identifier, Supplier supplier ) + private NamedTileEntityType( ResourceLocation identifier, Supplier supplier ) { - super( supplier, getDatafixer( identifier ) ); + super( supplier, Collections.emptySet(), getDatafixer( identifier ) ); this.identifier = identifier; setRegistryName( identifier ); } - public static NamedBlockEntityType create( ResourceLocation identifier, Supplier supplier ) + public static NamedTileEntityType create( ResourceLocation identifier, Supplier supplier ) { - return new NamedBlockEntityType<>( identifier, supplier ); + return new NamedTileEntityType<>( identifier, supplier ); } - public static NamedBlockEntityType create( ResourceLocation identifier, Function, ? extends T> builder ) + public static NamedTileEntityType create( ResourceLocation identifier, Function, ? extends T> builder ) { return new FixedPointSupplier<>( identifier, builder ).factory; } + public void setBlock( @Nonnull Block block ) + { + if( this.block != null ) throw new IllegalStateException( "Cannot change block once set" ); + this.block = Objects.requireNonNull( block, "block cannot be null" ); + } + + @Override + public boolean isValidBlock( @Nonnull Block block ) + { + return block == this.block; + } + public ResourceLocation getId() { return identifier; } - public static Type getDatafixer( ResourceLocation id ) + private static Type getDatafixer( ResourceLocation id ) { try { @@ -63,10 +80,10 @@ public final class NamedBlockEntityType extends TileEntity private static final class FixedPointSupplier implements Supplier { - final NamedBlockEntityType factory; - private final Function, ? extends T> builder; + final NamedTileEntityType factory; + private final Function, ? extends T> builder; - private FixedPointSupplier( ResourceLocation identifier, Function, ? extends T> builder ) + private FixedPointSupplier( ResourceLocation identifier, Function, ? extends T> builder ) { factory = create( identifier, this ); this.builder = builder; diff --git a/src/main/java/dan200/computercraft/shared/util/Palette.java b/src/main/java/dan200/computercraft/shared/util/Palette.java index 3174a2d0b..16f474d4e 100644 --- a/src/main/java/dan200/computercraft/shared/util/Palette.java +++ b/src/main/java/dan200/computercraft/shared/util/Palette.java @@ -6,7 +6,7 @@ package dan200.computercraft.shared.util; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.CompoundNBT; public class Palette { @@ -79,7 +79,7 @@ public class Palette }; } - public NBTTagCompound writeToNBT( NBTTagCompound nbt ) + public CompoundNBT writeToNBT( CompoundNBT nbt ) { int[] rgb8 = new int[colours.length]; @@ -92,7 +92,7 @@ public class Palette return nbt; } - public void readFromNBT( NBTTagCompound nbt ) + public void readFromNBT( CompoundNBT nbt ) { if( !nbt.contains( "term_palette" ) ) return; int[] rgb8 = nbt.getIntArray( "term_palette" ); diff --git a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java index 332c9e161..7e4568cec 100644 --- a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java @@ -11,7 +11,7 @@ import com.google.common.collect.Sets; import com.google.gson.*; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.item.crafting.Ingredient; -import net.minecraft.util.JsonUtils; +import net.minecraft.util.JSONUtils; import net.minecraft.util.NonNullList; import java.util.Map; @@ -40,7 +40,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.getJsonObject( json, "key" ).entrySet() ) { if( entry.getKey().length() != 1 ) { @@ -56,7 +56,7 @@ public final class RecipeUtil ingMap.put( ' ', Ingredient.EMPTY ); - JsonArray patternJ = JsonUtils.getJsonArray( json, "pattern" ); + JsonArray patternJ = JSONUtils.getJsonArray( json, "pattern" ); if( patternJ.size() == 0 ) { @@ -66,7 +66,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.getString( 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" ); @@ -107,7 +107,7 @@ public final class RecipeUtil public static NonNullList getIngredients( JsonObject json ) { NonNullList ingredients = NonNullList.create(); - for( JsonElement ele : JsonUtils.getJsonArray( json, "ingredients" ) ) + for( JsonElement ele : JSONUtils.getJsonArray( json, "ingredients" ) ) { ingredients.add( Ingredient.deserialize( ele ) ); } @@ -118,7 +118,7 @@ public final class RecipeUtil public static ComputerFamily getFamily( JsonObject json, String name ) { - String familyName = JsonUtils.getString( json, name ); + String familyName = JSONUtils.getString( json, name ); try { return ComputerFamily.valueOf( familyName ); diff --git a/src/main/java/dan200/computercraft/shared/util/RecordUtil.java b/src/main/java/dan200/computercraft/shared/util/RecordUtil.java index f5ff089e9..ba04109ce 100644 --- a/src/main/java/dan200/computercraft/shared/util/RecordUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RecordUtil.java @@ -10,12 +10,12 @@ import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.NetworkMessage; import dan200.computercraft.shared.network.client.PlayRecordClientMessage; import net.minecraft.item.Item; -import net.minecraft.item.ItemRecord; import net.minecraft.item.ItemStack; +import net.minecraft.item.MusicDiscItem; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.World; import javax.annotation.Nonnull; @@ -33,8 +33,8 @@ public final class RecordUtil public static String getRecordInfo( @Nonnull ItemStack recordStack ) { Item item = recordStack.getItem(); - if( !(item instanceof ItemRecord) ) return null; + if( !(item instanceof MusicDiscItem) ) return null; - return new TextComponentTranslation( item.getTranslationKey() + ".desc" ).getString(); + return new TranslationTextComponent( item.getTranslationKey() + ".desc" ).getString(); } } diff --git a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java index 86ed53269..66c7a092f 100644 --- a/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/RedstoneUtil.java @@ -6,8 +6,8 @@ package dan200.computercraft.shared.util; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.EnumFacing; +import net.minecraft.block.BlockState; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.ForgeEventFactory; @@ -16,10 +16,10 @@ import java.util.EnumSet; public final class RedstoneUtil { - public static void propagateRedstoneOutput( World world, BlockPos pos, EnumFacing side ) + public static void propagateRedstoneOutput( World world, BlockPos pos, Direction side ) { // Propagate ordinary output. See BlockRedstoneDiode.notifyNeighbors - IBlockState block = world.getBlockState( pos ); + BlockState block = world.getBlockState( pos ); if( ForgeEventFactory.onNeighborNotify( world, pos, block, EnumSet.of( side ), false ).isCanceled() ) return; BlockPos neighbourPos = pos.offset( side ); diff --git a/src/main/java/dan200/computercraft/shared/util/SingleIntArray.java b/src/main/java/dan200/computercraft/shared/util/SingleIntArray.java new file mode 100644 index 000000000..8d4b4c3a4 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/util/SingleIntArray.java @@ -0,0 +1,33 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.util; + +import net.minecraft.util.IIntArray; + +@FunctionalInterface +public interface SingleIntArray extends IIntArray +{ + int get(); + + @Override + default int func_221476_a( int property ) + { + return property == 0 ? get() : 0; + } + + @Override + default void func_221477_a( int i, int i1 ) + { + + } + + @Override + default int func_221478_a() + { + return 1; + } +} diff --git a/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java b/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java index eaed69114..f890b34e4 100644 --- a/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java +++ b/src/main/java/dan200/computercraft/shared/util/ValidatingSlot.java @@ -7,7 +7,7 @@ package dan200.computercraft.shared.util; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; +import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; public class ValidatingSlot extends Slot diff --git a/src/main/java/dan200/computercraft/shared/util/WaterloggableBlock.java b/src/main/java/dan200/computercraft/shared/util/WaterloggableBlock.java deleted file mode 100644 index 4c0f593c5..000000000 --- a/src/main/java/dan200/computercraft/shared/util/WaterloggableBlock.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.util; - -import net.minecraft.block.IBucketPickupHandler; -import net.minecraft.block.ILiquidContainer; -import net.minecraft.block.state.IBlockState; -import net.minecraft.fluid.Fluid; -import net.minecraft.fluid.IFluidState; -import net.minecraft.init.Fluids; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.state.BooleanProperty; -import net.minecraft.state.properties.BlockStateProperties; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; - -import javax.annotation.Nonnull; - -/** - * Represents a block which can be filled with water - * - * I'm fairly sure this exists on 1.14, but it's a useful convenience wrapper to have on 1.13. - */ -public interface WaterloggableBlock extends IBucketPickupHandler, ILiquidContainer -{ - BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - - /** - * Call from {@link net.minecraft.block.Block#getFluidState(IBlockState)} - * - * @param state The current state - * @return This waterlogged block's current fluid - */ - default IFluidState getWaterloggedFluidState( IBlockState state ) - { - return state.get( WATERLOGGED ) ? Fluids.WATER.getStillFluidState( false ) : Fluids.EMPTY.getDefaultState(); - } - - @Nonnull - @Override - default Fluid pickupFluid( @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull IBlockState state ) - { - if( state.get( WATERLOGGED ) ) - { - world.setBlockState( pos, state.with( WATERLOGGED, false ), 3 ); - return Fluids.WATER; - } - else - { - return Fluids.EMPTY; - } - } - - @Override - default boolean canContainFluid( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Fluid fluid ) - { - return !state.get( WATERLOGGED ) && fluid == Fluids.WATER; - } - - @Override - default boolean receiveFluid( @Nonnull IWorld world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull IFluidState fluid ) - { - if( !canContainFluid( world, pos, state, fluid.getFluid() ) ) return false; - - if( !world.isRemote() ) - { - world.setBlockState( pos, state.with( WATERLOGGED, true ), 3 ); - world.getPendingFluidTicks().scheduleTick( pos, fluid.getFluid(), fluid.getFluid().getTickRate( world ) ); - } - - return true; - } - - /** - * Call from {@link net.minecraft.block.Block#updatePostPlacement(IBlockState, EnumFacing, IBlockState, IWorld, BlockPos, BlockPos)} - * - * @param state The current state - * @param world The position of this block - * @param pos The world this block exists in - */ - default void updateWaterloggedPostPlacement( IBlockState state, IWorld world, BlockPos pos ) - { - if( state.get( WATERLOGGED ) ) - { - world.getPendingFluidTicks().scheduleTick( pos, Fluids.WATER, Fluids.WATER.getTickRate( world ) ); - } - } - - default boolean getWaterloggedStateForPlacement( BlockItemUseContext context ) - { - return context.getWorld().getFluidState( context.getPos() ).getFluid() == Fluids.WATER; - } -} diff --git a/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java b/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java new file mode 100644 index 000000000..71770017b --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/util/WaterloggableHelpers.java @@ -0,0 +1,62 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.util; + +import net.minecraft.block.BlockState; +import net.minecraft.fluid.Fluids; +import net.minecraft.fluid.IFluidState; +import net.minecraft.item.BlockItemUseContext; +import net.minecraft.state.BooleanProperty; +import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorld; + +/** + * Represents a block which can be filled with water + * + * I'm fairly sure this exists on 1.14, but it's a useful convenience wrapper to have on 1.13. + */ +public final class WaterloggableHelpers +{ + public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + + private WaterloggableHelpers() + { + } + + /** + * Call from {@link net.minecraft.block.Block#getFluidState(BlockState)} + * + * @param state The current state + * @return This waterlogged block's current fluid + */ + public static IFluidState getWaterloggedFluidState( BlockState state ) + { + return state.get( WATERLOGGED ) ? Fluids.WATER.getStillFluidState( false ) : Fluids.EMPTY.getDefaultState(); + } + + /** + * Call from {@link net.minecraft.block.Block#updatePostPlacement(BlockState, Direction, BlockState, IWorld, BlockPos, BlockPos)} + * + * @param state The current state + * @param world The position of this block + * @param pos The world this block exists in + */ + public static void updateWaterloggedPostPlacement( BlockState state, IWorld world, BlockPos pos ) + { + if( state.get( WATERLOGGED ) ) + { + world.getPendingFluidTicks().scheduleTick( pos, Fluids.WATER, Fluids.WATER.getTickRate( world ) ); + } + } + + public static boolean getWaterloggedStateForPlacement( BlockItemUseContext context ) + { + return context.getWorld().getFluidState( context.getPos() ).getFluid() == 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 cc1cac870..b37c1534a 100644 --- a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java @@ -7,17 +7,13 @@ package dan200.computercraft.shared.util; import com.google.common.base.Predicate; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.block.BlockState; +import net.minecraft.entity.*; +import net.minecraft.entity.item.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; +import net.minecraft.util.Direction; +import net.minecraft.util.math.*; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.World; import org.apache.commons.lang3.tuple.Pair; @@ -30,10 +26,25 @@ public final class WorldUtil @SuppressWarnings( "Guava" ) private static final Predicate CAN_COLLIDE = x -> x != null && x.isAlive() && x.canBeCollidedWith(); + private static final Entity ENTITY = new ItemEntity( EntityType.ITEM, null ) + { + @Override + public EntitySize getSize( Pose pose ) + { + return EntitySize.fixed( 0, 0 ); + } + }; + + static + { + ENTITY.noClip = true; + ENTITY.recalculateSize(); + } + public static boolean isLiquidBlock( World world, BlockPos pos ) { if( !World.isValid( pos ) ) return false; - IBlockState state = world.getBlockState( pos ); + BlockState state = world.getBlockState( pos ); return !state.getFluidState().isEmpty(); } @@ -50,10 +61,12 @@ public final class WorldUtil Vec3d vecEnd = vecStart.add( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance ); // Raycast for blocks - RayTraceResult result = world.rayTraceBlocks( vecStart, vecEnd ); - if( result != null && result.type == RayTraceResult.Type.BLOCK ) + ENTITY.setPosition( vecStart.x, vecStart.y, vecStart.z ); + RayTraceContext context = new RayTraceContext( vecStart, vecEnd, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, ENTITY ); + RayTraceResult result = world.func_217299_a( context ); + if( result != null && result.getType() == RayTraceResult.Type.BLOCK ) { - distance = vecStart.distanceTo( result.hitVec ); + distance = vecStart.distanceTo( result.getHitVec() ); vecEnd = vecStart.add( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance ); } @@ -76,15 +89,6 @@ public final class WorldUtil for( Entity entity : list ) { AxisAlignedBB littleBox = entity.getBoundingBox(); - if( littleBox == null ) - { - littleBox = entity.getCollisionBoundingBox(); - if( littleBox == null ) - { - continue; - } - } - if( littleBox.contains( vecStart ) ) { closest = entity; @@ -92,10 +96,10 @@ public final class WorldUtil continue; } - RayTraceResult littleBoxResult = littleBox.calculateIntercept( vecStart, vecEnd ); + Vec3d littleBoxResult = littleBox.func_216365_b( vecStart, vecEnd ).orElse( null ); // rayTrace if( littleBoxResult != null ) { - double dist = vecStart.distanceTo( littleBoxResult.hitVec ); + double dist = vecStart.distanceTo( littleBoxResult ); if( closest == null || dist <= closestDist ) { closest = entity; @@ -119,14 +123,14 @@ public final class WorldUtil return null; } - public static Vec3d getRayStart( EntityLivingBase entity ) + public static Vec3d getRayStart( LivingEntity entity ) { return entity.getEyePosition( 1 ); } - public static Vec3d getRayEnd( EntityPlayer player ) + public static Vec3d getRayEnd( PlayerEntity player ) { - double reach = player.getAttribute( EntityPlayer.REACH_DISTANCE ).getValue(); + double reach = player.getAttribute( PlayerEntity.REACH_DISTANCE ).getValue(); Vec3d look = player.getLookVec(); return getRayStart( player ).add( look.x * reach, look.y * reach, look.z * reach ); } @@ -136,7 +140,7 @@ public final class WorldUtil dropItemStack( stack, world, pos, null ); } - public static void dropItemStack( @Nonnull ItemStack stack, World world, BlockPos pos, EnumFacing direction ) + public static void dropItemStack( @Nonnull ItemStack stack, World world, BlockPos pos, Direction direction ) { double xDir; double yDir; @@ -167,11 +171,13 @@ public final class WorldUtil public static void dropItemStack( @Nonnull ItemStack stack, World world, double xPos, double yPos, double zPos, double xDir, double yDir, double zDir ) { - EntityItem item = new EntityItem( world, xPos, yPos, zPos, stack.copy() ); - item.motionX = xDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1; - item.motionY = yDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1; - item.motionZ = zDir * 0.7 + world.getRandom().nextFloat() * 0.2 - 0.1; + ItemEntity item = new ItemEntity( world, xPos, yPos, zPos, stack.copy() ); + item.setVelocity( + 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.spawnEntity( item ); + world.func_217376_c( item ); } } diff --git a/src/main/java/dan200/computercraft/shared/wired/CapabilityWiredElement.java b/src/main/java/dan200/computercraft/shared/wired/CapabilityWiredElement.java index d484f94bb..deadafe09 100644 --- a/src/main/java/dan200/computercraft/shared/wired/CapabilityWiredElement.java +++ b/src/main/java/dan200/computercraft/shared/wired/CapabilityWiredElement.java @@ -8,8 +8,8 @@ package dan200.computercraft.shared.wired; import dan200.computercraft.api.network.wired.IWiredElement; import dan200.computercraft.api.network.wired.IWiredNode; -import net.minecraft.nbt.INBTBase; -import net.minecraft.util.EnumFacing; +import net.minecraft.nbt.INBT; +import net.minecraft.util.Direction; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; @@ -66,13 +66,13 @@ public final class CapabilityWiredElement private static class NullStorage implements Capability.IStorage { @Override - public INBTBase writeNBT( Capability capability, IWiredElement instance, EnumFacing side ) + public INBT writeNBT( Capability capability, IWiredElement instance, Direction side ) { return null; } @Override - public void readNBT( Capability capability, IWiredElement instance, EnumFacing side, INBTBase base ) + public void readNBT( Capability capability, IWiredElement instance, Direction side, INBT base ) { } } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 83b686667..ab5165580 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,5 +1,10 @@ # ItemPocketRenderer/ItemPrintoutRenderer public net.minecraft.client.renderer.FirstPersonRenderer func_187466_c()V # renderArms public net.minecraft.client.renderer.FirstPersonRenderer func_178100_c(F)F # getMapAngleFromPitch -public net.minecraft.client.renderer.FirstPersonRenderer func_187456_a(FFLnet/minecraft/util/EnumHandSide;)V # renderArmFirstPerson +public net.minecraft.client.renderer.FirstPersonRenderer func_187456_a(FFLnet/minecraft/util/HandSide;)V # renderArmFirstPerson +# Containers +public net.minecraft.inventory.container.ContainerType$IFactory +public net.minecraft.inventory.container.ContainerType (Lnet/minecraft/inventory/container/ContainerType$IFactory;)V +public net.minecraft.client.gui.ScreenManager$IScreenFactory +public net.minecraft.client.gui.ScreenManager func_216911_a(Lnet/minecraft/inventory/container/ContainerType;Lnet/minecraft/client/gui/ScreenManager$IScreenFactory;)V # registerFactory diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index f9d4254ed..ff246ba74 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[25,)" +loaderVersion="[26,)" issueTrackerURL="https://github.com/SquidDev-CC/CC-Tweaked/issues" displayURL="https://github.com/SquidDev-CC/CC-Tweaked" @@ -19,6 +19,6 @@ CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles a [[dependencies.computercraft]] modId="forge" mandatory=true - versionRange="[25,)" + versionRange="[26,)" ordering="NONE" side="BOTH" diff --git a/src/main/resources/data/computercraft/recipes/generated/disk/disk_1.json b/src/main/resources/data/computercraft/recipes/generated/disk/disk_1.json index 8b01925bb..a27ee37c6 100644 --- a/src/main/resources/data/computercraft/recipes/generated/disk/disk_1.json +++ b/src/main/resources/data/computercraft/recipes/generated/disk/disk_1.json @@ -4,7 +4,7 @@ "ingredients": [ { "tag": "forge:dusts/redstone" }, { "item": "minecraft:paper" }, - { "item": "minecraft:ink_sac" } + { "item": "minecraft:black_dye" } ], "result": { "item": "computercraft:disk", "nbt": { "color": 1118481 } } } diff --git a/src/main/resources/data/computercraft/recipes/generated/disk/disk_12.json b/src/main/resources/data/computercraft/recipes/generated/disk/disk_12.json index 7920fc6dd..505066e7a 100644 --- a/src/main/resources/data/computercraft/recipes/generated/disk/disk_12.json +++ b/src/main/resources/data/computercraft/recipes/generated/disk/disk_12.json @@ -4,7 +4,7 @@ "ingredients": [ { "tag": "forge:dusts/redstone" }, { "item": "minecraft:paper" }, - { "item": "minecraft:dandelion_yellow" } + { "item": "minecraft:yellow_dye" } ], "result": { "item": "computercraft:disk", "nbt": { "color": 14605932 } } } diff --git a/src/main/resources/data/computercraft/recipes/generated/disk/disk_16.json b/src/main/resources/data/computercraft/recipes/generated/disk/disk_16.json index c3c6f193d..2fa82adad 100644 --- a/src/main/resources/data/computercraft/recipes/generated/disk/disk_16.json +++ b/src/main/resources/data/computercraft/recipes/generated/disk/disk_16.json @@ -4,7 +4,7 @@ "ingredients": [ { "tag": "forge:dusts/redstone" }, { "item": "minecraft:paper" }, - { "item": "minecraft:bone_meal" } + { "item": "minecraft:white_dye" } ], "result": { "item": "computercraft:disk", "nbt": { "color": 15790320 } } } diff --git a/src/main/resources/data/computercraft/recipes/generated/disk/disk_2.json b/src/main/resources/data/computercraft/recipes/generated/disk/disk_2.json index 53f78a99a..21ab48568 100644 --- a/src/main/resources/data/computercraft/recipes/generated/disk/disk_2.json +++ b/src/main/resources/data/computercraft/recipes/generated/disk/disk_2.json @@ -4,7 +4,7 @@ "ingredients": [ { "tag": "forge:dusts/redstone" }, { "item": "minecraft:paper" }, - { "item": "minecraft:rose_red" } + { "item": "minecraft:red_dye" } ], "result": { "item": "computercraft:disk", "nbt": { "color": 13388876 } } } diff --git a/src/main/resources/data/computercraft/recipes/generated/disk/disk_3.json b/src/main/resources/data/computercraft/recipes/generated/disk/disk_3.json index 452e4c348..a164af6cb 100644 --- a/src/main/resources/data/computercraft/recipes/generated/disk/disk_3.json +++ b/src/main/resources/data/computercraft/recipes/generated/disk/disk_3.json @@ -4,7 +4,7 @@ "ingredients": [ { "tag": "forge:dusts/redstone" }, { "item": "minecraft:paper" }, - { "item": "minecraft:cactus_green" } + { "item": "minecraft:green_dye" } ], "result": { "item": "computercraft:disk", "nbt": { "color": 5744206 } } } diff --git a/src/main/resources/data/computercraft/recipes/generated/disk/disk_4.json b/src/main/resources/data/computercraft/recipes/generated/disk/disk_4.json index 457bba1ed..7109021e3 100644 --- a/src/main/resources/data/computercraft/recipes/generated/disk/disk_4.json +++ b/src/main/resources/data/computercraft/recipes/generated/disk/disk_4.json @@ -4,7 +4,7 @@ "ingredients": [ { "tag": "forge:dusts/redstone" }, { "item": "minecraft:paper" }, - { "item": "minecraft:cocoa_beans" } + { "item": "minecraft:brown_dye" } ], "result": { "item": "computercraft:disk", "nbt": { "color": 8349260 } } } diff --git a/src/main/resources/data/computercraft/recipes/generated/disk/disk_5.json b/src/main/resources/data/computercraft/recipes/generated/disk/disk_5.json index 94520e185..538f14349 100644 --- a/src/main/resources/data/computercraft/recipes/generated/disk/disk_5.json +++ b/src/main/resources/data/computercraft/recipes/generated/disk/disk_5.json @@ -4,7 +4,7 @@ "ingredients": [ { "tag": "forge:dusts/redstone" }, { "item": "minecraft:paper" }, - { "item": "minecraft:lapis_lazuli" } + { "item": "minecraft:blue_dye" } ], "result": { "item": "computercraft:disk", "nbt": { "color": 3368652 } } } diff --git a/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java b/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java index 2e35df025..880b3c4e9 100644 --- a/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java +++ b/src/test/java/dan200/computercraft/shared/wired/NetworkTest.java @@ -18,7 +18,7 @@ import dan200.computercraft.api.network.wired.IWiredNode; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.shared.util.DirectionUtil; -import net.minecraft.util.EnumFacing; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -261,7 +261,7 @@ public class NetworkTest long start = System.nanoTime(); grid.forEach( ( existing, pos ) -> { - for( EnumFacing facing : DirectionUtil.FACINGS ) + for( Direction facing : DirectionUtil.FACINGS ) { BlockPos offset = pos.offset( facing ); if( offset.getX() > BRUTE_SIZE / 2 == pos.getX() > BRUTE_SIZE / 2 ) diff --git a/tools/recipes.lua b/tools/recipes.lua index 53c619f45..d2c007523 100644 --- a/tools/recipes.lua +++ b/tools/recipes.lua @@ -30,22 +30,22 @@ local pocket_upgrades = { --- All dye/disk colours local colours = { - { 0x111111, "minecraft:ink_sac" }, - { 0xcc4c4c, "minecraft:rose_red" }, - { 0x57A64E, "minecraft:cactus_green" }, - { 0x7f664c, "minecraft:cocoa_beans" }, - { 0x3366cc, "minecraft:lapis_lazuli" }, + { 0x111111, "minecraft:black_dye" }, + { 0xcc4c4c, "minecraft:red_dye" }, + { 0x57A64E, "minecraft:green_dye" }, + { 0x7f664c, "minecraft:brown_dye" }, + { 0x3366cc, "minecraft:blue_dye" }, { 0xb266e5, "minecraft:purple_dye" }, { 0x4c99b2, "minecraft:cyan_dye" }, { 0x999999, "minecraft:light_gray_dye" }, { 0x4c4c4c, "minecraft:gray_dye" }, { 0xf2b2cc, "minecraft:pink_dye" }, { 0x7fcc19, "minecraft:lime_dye" }, - { 0xdede6c, "minecraft:dandelion_yellow" }, + { 0xdede6c, "minecraft:yellow_dye" }, { 0x99b2f2, "minecraft:light_blue_dye" }, { 0xe57fd8, "minecraft:magenta_dye" }, { 0xf2b233, "minecraft:orange_dye" }, - { 0xf0f0f0, "minecraft:bone_meal" }, + { 0xf0f0f0, "minecraft:white_dye" }, } --- Read the provided file into a string, exiting the program if not found.