1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-08 08:20:29 +00:00

Initial update to 1.14

So very little works, but it compiles and runs.

Things to resolve over the next few days:
 - Horrible mappings (should largely be resolved by tomorrow).
 - Cannot send extra data over containers - we'll have to see what Forge
   does here.
 - Turtle models are broken
 - No block drops yet - this will largely be cherry-picking whatever I
   did on Fabric.
 - Weird inventory desyncs (items don't show up initially when
   interacting with a CC inventory).
 - Probably lots of other things.
This commit is contained in:
SquidDev 2019-06-08 13:36:31 +01:00
parent 0f3c44c926
commit 39a9ad0ce7
202 changed files with 2006 additions and 2522 deletions

View File

@ -9,7 +9,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.google.code.gson:gson:2.8.1' 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 'net.sf.proguard:proguard-gradle:6.1.0beta2'
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0' classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
} }
@ -98,7 +98,7 @@ dependencies {
// deobfProvided "pl.asie:Charset-Lib:0.5.4.6" // deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
// deobfProvided "MCMultiPart2:MCMultiPart:2.5.3" // 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' shade 'org.squiddev:Cobalt:0.5.0-SNAPSHOT'
@ -127,7 +127,7 @@ jar {
manifest { manifest {
attributes(["Specification-Title": "computercraft", attributes(["Specification-Title": "computercraft",
"Specification-Vendor": "SquidDev", "Specification-Vendor": "SquidDev",
"Specification-Version": "25.0", "Specification-Version": "26.0",
"Implementation-Title": "CC: Tweaked", "Implementation-Title": "CC: Tweaked",
"Implementation-Version": "${mod_version}", "Implementation-Version": "${mod_version}",
"Implementation-Vendor" :"SquidDev", "Implementation-Vendor" :"SquidDev",
@ -355,7 +355,7 @@ curseforge {
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : '' apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
project { project {
id = '282001' 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})." 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 { relations {
@ -431,7 +431,7 @@ githubRelease {
.takeWhile { it != 'Type "help changelog" to see the full version history.' } .takeWhile { it != 'Type "help changelog" to see the full version history.' }
.join("\n").trim() .join("\n").trim()
} }
prerelease false prerelease true
} }
def uploadTasks = ["uploadArchives", "curseforge", "githubRelease"] def uploadTasks = ["uploadArchives", "curseforge", "githubRelease"]

View File

@ -2,6 +2,6 @@
mod_version=1.83.1 mod_version=1.83.1
# Minecraft properties # Minecraft properties
mc_version=1.13.2 mc_version=1.14.2
forge_version=25.0.219 forge_version=26.0.5
mappings_version=20190530-1.13.2 mappings_version=20190608-1.14.2

View File

@ -26,7 +26,7 @@ import dan200.computercraft.shared.util.IDAssigner;
import dan200.computercraft.shared.wired.CapabilityWiredElement; import dan200.computercraft.shared.wired.CapabilityWiredElement;
import dan200.computercraft.shared.wired.WiredNode; import dan200.computercraft.shared.wired.WiredNode;
import net.minecraft.tileentity.TileEntity; 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.BlockPos;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -94,7 +94,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
} }
@Override @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 ); return BundledRedstone.getDefaultOutput( world, pos, side );
} }
@ -133,7 +133,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
@Nonnull @Nonnull
@Override @Override
public LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) public LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side )
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
return tile == null ? LazyOptional.empty() : tile.getCapability( CapabilityWiredElement.CAPABILITY, side ); return tile == null ? LazyOptional.empty() : tile.getCapability( CapabilityWiredElement.CAPABILITY, side );

View File

@ -20,7 +20,7 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider;
import dan200.computercraft.api.pocket.IPocketUpgrade; import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.api.turtle.ITurtleUpgrade; 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.util.math.BlockPos;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; 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. * If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
* @see IBundledRedstoneProvider * @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 ); return getInstance().getBundledRedstoneOutput( world, pos, side );
} }
@ -242,7 +242,7 @@ public final class ComputerCraftAPI
* @see IWiredElement#getNode() * @see IWiredElement#getNode()
*/ */
@Nonnull @Nonnull
public static LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) public static LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side )
{ {
return getInstance().getWiredElementAt( world, pos, side ); return getInstance().getWiredElementAt( world, pos, side );
} }
@ -284,7 +284,7 @@ public final class ComputerCraftAPI
void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider ); 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 ); void registerMediaProvider( @Nonnull IMediaProvider provider );
@ -299,6 +299,6 @@ public final class ComputerCraftAPI
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element ); IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
@Nonnull @Nonnull
LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ); LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side );
} }
} }

View File

@ -7,7 +7,7 @@
package dan200.computercraft.api.peripheral; package dan200.computercraft.api.peripheral;
import net.minecraft.tileentity.TileEntity; 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.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -34,5 +34,5 @@ public interface IPeripheralProvider
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
*/ */
@Nullable @Nullable
IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ); IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
} }

View File

@ -5,7 +5,7 @@
*/ */
package dan200.computercraft.api.peripheral; package dan200.computercraft.api.peripheral;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -25,8 +25,8 @@ public interface IPeripheralTile
* *
* @param side The side to get the peripheral from. * @param side The side to get the peripheral from.
* @return A peripheral, or {@code null} if there is not a peripheral here. * @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 @Nullable
IPeripheral getPeripheral( @Nonnull EnumFacing side ); IPeripheral getPeripheral( @Nonnull Direction side );
} }

View File

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

View File

@ -6,7 +6,7 @@
package dan200.computercraft.api.redstone; package dan200.computercraft.api.redstone;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -30,5 +30,5 @@ public interface IBundledRedstoneProvider
* handle this block. * handle this block.
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) * @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 );
} }

View File

@ -11,8 +11,8 @@ import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -83,10 +83,10 @@ public interface ITurtleAccess
* Returns the world direction the turtle is currently facing. * Returns the world direction the turtle is currently facing.
* *
* @return The world direction the turtle is currently facing. * @return The world direction the turtle is currently facing.
* @see #setDirection(EnumFacing) * @see #setDirection(Direction)
*/ */
@Nonnull @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 * 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). * @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() * @see #getDirection()
*/ */
void setDirection( @Nonnull EnumFacing dir ); void setDirection( @Nonnull Direction dir );
/** /**
* Get the currently selected slot in the turtle's inventory. * Get the currently selected slot in the turtle's inventory.
@ -290,7 +290,7 @@ public interface ITurtleAccess
* @see #updateUpgradeNBTData(TurtleSide) * @see #updateUpgradeNBTData(TurtleSide)
*/ */
@Nonnull @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 * Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the

View File

@ -13,7 +13,7 @@ import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -113,7 +113,7 @@ public interface ITurtleUpgrade
* to be called. * to be called.
*/ */
@Nonnull @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(); return TurtleCommandResult.failure();
} }

View File

@ -6,7 +6,7 @@
package dan200.computercraft.api.turtle; package dan200.computercraft.api.turtle;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -15,7 +15,7 @@ import javax.annotation.Nullable;
* Used to indicate the result of executing a turtle command. * Used to indicate the result of executing a turtle command.
* *
* @see ITurtleCommand#execute(ITurtleAccess) * @see ITurtleCommand#execute(ITurtleAccess)
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing) * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
*/ */
public final class TurtleCommandResult public final class TurtleCommandResult
{ {

View File

@ -6,14 +6,14 @@
package dan200.computercraft.api.turtle; 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 * An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by
* a turtle. * a turtle.
* *
* @see ITurtleUpgrade#getType() * @see ITurtleUpgrade#getType()
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing) * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
*/ */
public enum TurtleVerb public enum TurtleVerb
{ {

View File

@ -11,7 +11,7 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleVerb; import dan200.computercraft.api.turtle.TurtleVerb;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent;
@ -21,7 +21,7 @@ import java.util.Objects;
/** /**
* Fired when a turtle attempts to attack an entity. * 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. * 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. * Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both.

View File

@ -12,9 +12,9 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleVerb; 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.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer; 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. * 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. * 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. * 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 public static class Dig extends TurtleBlockEvent
{ {
private final IBlockState block; private final BlockState block;
private final ITurtleUpgrade upgrade; private final ITurtleUpgrade upgrade;
private final TurtleSide side; 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 ); 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. * @return The block which is going to be broken.
*/ */
@Nonnull @Nonnull
public IBlockState getBlock() public BlockState getBlock()
{ {
return block; return block;
} }
@ -185,10 +185,10 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
*/ */
public static class Inspect extends TurtleBlockEvent public static class Inspect extends TurtleBlockEvent
{ {
private final IBlockState state; private final BlockState state;
private final Map<String, Object> data; private final Map<String, Object> data;
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Map<String, Object> data ) public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Map<String, Object> data )
{ {
super( turtle, TurtleAction.INSPECT, player, world, pos ); super( turtle, TurtleAction.INSPECT, player, world, pos );
@ -204,7 +204,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
* @return The inspected block state. * @return The inspected block state.
*/ */
@Nonnull @Nonnull
public IBlockState getState() public BlockState getState()
{ {
return state; return state;
} }

View File

@ -16,7 +16,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.IUnbakedModel; import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation; import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.client.renderer.model.ModelRotation;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.resources.IResourceManager; import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation; 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.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.BasicState;
import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -82,7 +82,7 @@ public final class ClientRegistry
IResourceManager manager = Minecraft.getInstance().getResourceManager(); IResourceManager manager = Minecraft.getInstance().getResourceManager();
for( String extra : EXTRA_TEXTURES ) 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<>() ); model.getTextures( loader::getUnbakedModel, new HashSet<>() );
return model.bake( return model.bake(
loader::getUnbakedModel, loader,
ModelLoader.defaultTextureGetter(), ModelLoader.defaultTextureGetter(),
ModelRotation.X0_Y0, false, DefaultVertexFormats.BLOCK new BasicState( model.getDefaultState(), false ), DefaultVertexFormats.BLOCK
); );
} }
} }

View File

@ -12,8 +12,8 @@ import dan200.computercraft.shared.command.text.TableFormatter;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiNewChat; import net.minecraft.client.gui.NewChatGui;
import net.minecraft.client.gui.GuiUtilRenderComponents; import net.minecraft.client.gui.RenderComponentsUtil;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
@ -65,18 +65,18 @@ public class ClientTableFormatter implements TableFormatter
public void writeLine( int id, ITextComponent component ) public void writeLine( int id, ITextComponent component )
{ {
Minecraft mc = Minecraft.getInstance(); 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 // Trim the text if it goes over the allowed length
int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() ); int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() );
List<ITextComponent> list = GuiUtilRenderComponents.splitText( component, maxWidth, mc.fontRenderer, false, false ); List<ITextComponent> list = RenderComponentsUtil.splitText( component, maxWidth, mc.fontRenderer, false, false );
if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id ); if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
} }
@Override @Override
public int display( TableBuilder table ) 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() ); int lastHeight = lastHeights.get( table.getId() );

View File

@ -6,11 +6,11 @@
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; 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 ); drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH, p, greyScale );
} }
GlStateManager.disableTexture2D(); GlStateManager.disableTexture();
tessellator.draw(); tessellator.draw();
GlStateManager.enableTexture2D(); GlStateManager.enableTexture();
} }
public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale, Palette p ) 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() public void bindFont()
{ {
m_textureManager.bindTexture( FONT ); 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 );
} }
} }

View File

@ -6,19 +6,22 @@
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.WidgetTerminal; import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.gui.widgets.WidgetWrapper; import dan200.computercraft.client.gui.widgets.WidgetWrapper;
import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.computer.core.ClientComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.IContainerComputer;
import dan200.computercraft.shared.computer.inventory.ContainerComputer; import dan200.computercraft.shared.computer.inventory.ContainerComputer;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
public class GuiComputer extends GuiContainer public class GuiComputer<T extends Container & IContainerComputer> extends ContainerScreen<T>
{ {
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" ); 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" ); 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 WidgetTerminal terminal;
private WidgetWrapper terminalWrapper; 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_family = family;
m_computer = computer; m_computer = computer;
m_termWidth = termWidth; m_termWidth = termWidth;
@ -43,10 +49,10 @@ public class GuiComputer extends GuiContainer
terminal = null; terminal = null;
} }
public GuiComputer( TileComputer computer ) public static GuiComputer<ContainerComputer> create( int id, TileComputer computer, PlayerInventory inventory, ITextComponent component )
{ {
this( return new GuiComputer<>(
new ContainerComputer( computer ), new ContainerComputer( id, computer ), inventory, component,
computer.getFamily(), computer.getFamily(),
computer.createClientComputer(), computer.createClientComputer(),
ComputerCraft.terminalWidth_computer, ComputerCraft.terminalWidth_computer,
@ -55,9 +61,9 @@ public class GuiComputer extends GuiContainer
} }
@Override @Override
protected void initGui() protected void init()
{ {
mc.keyboardListener.enableRepeatEvents( true ); minecraft.keyboardListener.enableRepeatEvents( true );
int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH; int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT; int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
@ -65,9 +71,9 @@ public class GuiComputer extends GuiContainer
xSize = termPxWidth + 4 + 24; xSize = termPxWidth + 4 + 24;
ySize = termPxHeight + 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 ); terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight );
children.add( terminalWrapper ); children.add( terminalWrapper );
@ -75,12 +81,12 @@ public class GuiComputer extends GuiContainer
} }
@Override @Override
public void onGuiClosed() public void removed()
{ {
super.onGuiClosed(); super.removed();
children.remove( terminal ); children.remove( terminal );
terminal = null; terminal = null;
mc.keyboardListener.enableRepeatEvents( false ); minecraft.keyboardListener.enableRepeatEvents( false );
} }
@Override @Override
@ -108,32 +114,32 @@ public class GuiComputer extends GuiContainer
{ {
case Normal: case Normal:
default: default:
mc.getTextureManager().bindTexture( BACKGROUND_NORMAL ); minecraft.getTextureManager().bindTexture( BACKGROUND_NORMAL );
break; break;
case Advanced: case Advanced:
mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED ); minecraft.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
break; break;
case Command: case Command:
mc.getTextureManager().bindTexture( BACKGROUND_COMMAND ); minecraft.getTextureManager().bindTexture( BACKGROUND_COMMAND );
break; break;
} }
drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 ); blit( startX - 12, startY - 12, 12, 28, 12, 12 );
drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 12 ); blit( startX - 12, endY, 12, 40, 12, 12 );
drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 ); blit( endX, startY - 12, 24, 28, 12, 12 );
drawTexturedModalRect( endX, endY, 24, 40, 12, 12 ); blit( endX, endY, 24, 40, 12, 12 );
drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 ); blit( startX, startY - 12, 0, 0, endX - startX, 12 );
drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 12 ); blit( startX, endY, 0, 12, endX - startX, 12 );
drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY ); blit( startX - 12, startY, 0, 28, 12, endY - startY );
drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY ); blit( endX, startY, 36, 28, 12, endY - startY );
} }
@Override @Override
public void render( int mouseX, int mouseY, float partialTicks ) public void render( int mouseX, int mouseY, float partialTicks )
{ {
drawDefaultBackground(); renderBackground();
super.render( mouseX, mouseY, partialTicks ); super.render( mouseX, mouseY, partialTicks );
renderHoveredToolTip( mouseX, mouseY ); renderHoveredToolTip( mouseX, mouseY );
} }

View File

@ -6,44 +6,42 @@
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
public class GuiDiskDrive extends GuiContainer public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
{ {
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" ); private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
private final ContainerDiskDrive m_container; public GuiDiskDrive( ContainerDiskDrive container, PlayerInventory player, ITextComponent title )
public GuiDiskDrive( ContainerDiskDrive container )
{ {
super( container ); super( container, player, title );
m_container = container;
} }
@Override @Override
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
{ {
String title = m_container.getDiskDrive().getDisplayName().getString(); String title = this.title.getFormattedText();
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 ); font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 ); font.drawString( title, 8, ySize - 96 + 2, 0x404040 );
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
{ {
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
mc.getTextureManager().bindTexture( BACKGROUND ); minecraft.getTextureManager().bindTexture( BACKGROUND );
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); blit( guiLeft, guiTop, 0, 0, xSize, ySize );
} }
@Override @Override
public void render( int mouseX, int mouseY, float partialTicks ) public void render( int mouseX, int mouseY, float partialTicks )
{ {
drawDefaultBackground(); renderBackground();
super.render( mouseX, mouseY, partialTicks ); super.render( mouseX, mouseY, partialTicks );
renderHoveredToolTip( mouseX, mouseY ); renderHoveredToolTip( mouseX, mouseY );
} }

View File

@ -10,15 +10,17 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer; import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
import dan200.computercraft.shared.pocket.items.ItemPocketComputer; import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
public class GuiPocketComputer extends GuiComputer public class GuiPocketComputer extends GuiComputer<ContainerPocketComputer>
{ {
public GuiPocketComputer( ContainerPocketComputer container ) public GuiPocketComputer( ContainerPocketComputer container, PlayerInventory player, ITextComponent title )
{ {
super( super(
container, container, player, title,
getFamily( container.getStack() ), getFamily( container.getStack() ),
ItemPocketComputer.createClientComputer( container.getStack() ), ItemPocketComputer.createClientComputer( container.getStack() ),
ComputerCraft.terminalWidth_pocketComputer, ComputerCraft.terminalWidth_pocketComputer,

View File

@ -6,46 +6,45 @@
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter; import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
public class GuiPrinter extends GuiContainer public class GuiPrinter extends ContainerScreen<ContainerPrinter>
{ {
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" ); private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
private final ContainerPrinter container; public GuiPrinter( ContainerPrinter container, PlayerInventory player, ITextComponent title )
public GuiPrinter( ContainerPrinter container )
{ {
super( container ); super( container, player, title );
this.container = container;
} }
@Override @Override
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY ) protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
{ {
String title = container.getPrinter().getDisplayName().getString(); String title = getTitle().getFormattedText();
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 ); font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 ); font.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY ) protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
{ {
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
mc.getTextureManager().bindTexture( BACKGROUND ); minecraft.getTextureManager().bindTexture( BACKGROUND );
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); 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 @Override
public void render( int mouseX, int mouseY, float partialTicks ) public void render( int mouseX, int mouseY, float partialTicks )
{ {
drawDefaultBackground(); renderBackground();
super.render( mouseX, mouseY, partialTicks ); super.render( mouseX, mouseY, partialTicks );
renderHoveredToolTip( mouseX, mouseY ); renderHoveredToolTip( mouseX, mouseY );
} }

View File

@ -6,16 +6,18 @@
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.common.ContainerHeldItem; import dan200.computercraft.shared.common.ContainerHeldItem;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.text.ITextComponent;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import static dan200.computercraft.client.render.PrintoutRenderer.*; import static dan200.computercraft.client.render.PrintoutRenderer.*;
public class GuiPrintout extends GuiContainer public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
{ {
private final boolean m_book; private final boolean m_book;
private final int m_pages; private final int m_pages;
@ -23,9 +25,9 @@ public class GuiPrintout extends GuiContainer
private final TextBuffer[] m_colours; private final TextBuffer[] m_colours;
private int m_page; 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; ySize = Y_SIZE;
@ -63,9 +65,9 @@ public class GuiPrintout extends GuiContainer
} }
@Override @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 ) if( delta < 0 )
{ {
// Scroll up goes to the next page // 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.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
GlStateManager.enableDepthTest(); 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 ); 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 ) 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. // We must take the background further back in order to not overlap with our printed pages.
zLevel--; blitOffset--;
drawDefaultBackground(); renderBackground();
zLevel++; blitOffset++;
super.render( mouseX, mouseY, partialTicks ); super.render( mouseX, mouseY, partialTicks );
renderHoveredToolTip( mouseX, mouseY ); renderHoveredToolTip( mouseX, mouseY );

View File

@ -6,6 +6,7 @@
package dan200.computercraft.client.gui; package dan200.computercraft.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.gui.widgets.WidgetTerminal; import dan200.computercraft.client.gui.widgets.WidgetTerminal;
import dan200.computercraft.client.gui.widgets.WidgetWrapper; 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.computer.core.ComputerFamily;
import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
public class GuiTurtle extends GuiContainer public class GuiTurtle extends ContainerScreen<ContainerTurtle>
{ {
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" ); 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" ); 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 WidgetTerminal terminal;
private WidgetWrapper terminalWrapper; 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_container = container;
m_family = turtle.getFamily(); m_family = turtle.getFamily();
@ -43,16 +45,16 @@ public class GuiTurtle extends GuiContainer
} }
@Override @Override
protected void initGui() protected void init()
{ {
super.initGui(); super.init();
mc.keyboardListener.enableRepeatEvents( true ); minecraft.keyboardListener.enableRepeatEvents( true );
int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH; int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT; int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
terminal = new WidgetTerminal( terminal = new WidgetTerminal(
mc, () -> m_computer, minecraft, () -> m_computer,
ComputerCraft.terminalWidth_turtle, ComputerCraft.terminalWidth_turtle,
ComputerCraft.terminalHeight_turtle, ComputerCraft.terminalHeight_turtle,
2, 2, 2, 2 2, 2, 2, 2
@ -64,11 +66,12 @@ public class GuiTurtle extends GuiContainer
} }
@Override @Override
public void onGuiClosed() public void removed()
{ {
super.removed();
children.remove( terminal ); children.remove( terminal );
terminal = null; terminal = null;
mc.keyboardListener.enableRepeatEvents( false ); minecraft.keyboardListener.enableRepeatEvents( false );
} }
@Override @Override
@ -87,8 +90,8 @@ public class GuiTurtle extends GuiContainer
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
int slotX = slot % 4; int slotX = slot % 4;
int slotY = slot / 4; int slotY = slot / 4;
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); minecraft.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 ); 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 // Draw border/inventory
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F ); GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL ); minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize ); blit( guiLeft, guiTop, 0, 0, xSize, ySize );
drawSelectionSlot( advanced ); drawSelectionSlot( advanced );
} }
@ -110,7 +113,7 @@ public class GuiTurtle extends GuiContainer
@Override @Override
public void render( int mouseX, int mouseY, float partialTicks ) public void render( int mouseX, int mouseY, float partialTicks )
{ {
drawDefaultBackground(); renderBackground();
super.render( mouseX, mouseY, partialTicks ); super.render( mouseX, mouseY, partialTicks );
renderHoveredToolTip( mouseX, mouseY ); renderHoveredToolTip( mouseX, mouseY );
} }

View File

@ -6,6 +6,7 @@
package dan200.computercraft.client.gui.widgets; package dan200.computercraft.client.gui.widgets;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.FrameInfo;
import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.Terminal; 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.Minecraft;
import net.minecraft.client.gui.IGuiEventListener; import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.SharedConstants; import net.minecraft.util.SharedConstants;
@ -35,6 +35,8 @@ public class WidgetTerminal implements IGuiEventListener
private final Minecraft client; private final Minecraft client;
private boolean focused;
private final Supplier<ClientComputer> computer; private final Supplier<ClientComputer> computer;
private final int termWidth; private final int termWidth;
private final int termHeight; private final int termHeight;
@ -250,14 +252,23 @@ public class WidgetTerminal implements IGuiEventListener
} }
@Override @Override
public boolean mouseScrolled( double delta ) public boolean mouseScrolled( double mouseX, double mouseY, double delta )
{ {
ClientComputer computer = this.computer.get(); 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; return true;
@ -284,9 +295,9 @@ public class WidgetTerminal implements IGuiEventListener
} }
@Override @Override
public void focusChanged( boolean focused ) public boolean changeFocus( boolean reversed )
{ {
if( !focused ) if( focused )
{ {
// When blurring, we should make all keys go up // When blurring, we should make all keys go up
for( int key = 0; key < keysDown.size(); key++ ) for( int key = 0; key < keysDown.size(); key++ )
@ -305,6 +316,8 @@ public class WidgetTerminal implements IGuiEventListener
shutdownTimer = terminateTimer = rebootTimer = -1; shutdownTimer = terminateTimer = rebootTimer = -1;
} }
focused = !focused;
return true;
} }
public void draw( int originX, int originY ) public void draw( int originX, int originY )

View File

@ -26,15 +26,9 @@ public class WidgetWrapper implements IGuiEventListener
} }
@Override @Override
public void focusChanged( boolean b ) public boolean changeFocus( boolean b )
{ {
listener.focusChanged( b ); return listener.changeFocus( b );
}
@Override
public boolean canFocus()
{
return listener.canFocus();
} }
@Override @Override
@ -59,9 +53,9 @@ public class WidgetWrapper implements IGuiEventListener
} }
@Override @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 @Override

View File

@ -7,33 +7,29 @@
package dan200.computercraft.client.proxy; package dan200.computercraft.client.proxy;
import dan200.computercraft.ComputerCraft; 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.TileEntityCableRenderer;
import dan200.computercraft.client.render.TileEntityMonitorRenderer; import dan200.computercraft.client.render.TileEntityMonitorRenderer;
import dan200.computercraft.client.render.TileEntityTurtleRenderer; import dan200.computercraft.client.render.TileEntityTurtleRenderer;
import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.common.ContainerHeldItem;
import dan200.computercraft.shared.computer.core.ClientComputer; import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
import dan200.computercraft.shared.network.container.*;
import dan200.computercraft.shared.peripheral.modem.wired.TileCable; import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor; import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
import dan200.computercraft.shared.peripheral.monitor.TileMonitor; 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.blocks.TileTurtle;
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle; import net.minecraft.client.gui.ScreenManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; 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.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; 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 ) @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
public final class ComputerCraftProxyClient public final class ComputerCraftProxyClient
{ {
@ -50,35 +46,11 @@ public final class ComputerCraftProxyClient
private static void registerContainers() private static void registerContainers()
{ {
ContainerType.registerGui( TileEntityContainerType::computer, ( packet, player ) -> ScreenManager.registerFactory( ContainerPrinter.TYPE, GuiPrinter::new );
new GuiComputer( (TileComputer) packet.getTileEntity( player ) ) ); ScreenManager.registerFactory( ContainerDiskDrive.TYPE, GuiDiskDrive::new );
ContainerType.registerGui( TileEntityContainerType::diskDrive, GuiDiskDrive::new ); ScreenManager.registerFactory( ContainerPocketComputer.TYPE, GuiPocketComputer::new );
ContainerType.registerGui( TileEntityContainerType::printer, GuiPrinter::new ); ScreenManager.registerFactory( ContainerHeldItem.PRINTOUT_TYPE, GuiPrintout::new );
ContainerType.registerGui( TileEntityContainerType::turtle, ( packet, player ) -> { // TODO: ScreenManager.registerFactory( ContainerViewComputer.TYPE, GuiComputer::new );
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<ContainerType<?>, EntityPlayer, GuiContainer> factory = (BiFunction<ContainerType<?>, EntityPlayer, GuiContainer>) ContainerType.guiFactories.get( packet.getId() );
return factory.apply( type, Minecraft.getInstance().player );
} );
} }
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT ) @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )

View File

@ -6,17 +6,20 @@
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable; import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes; import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
import dan200.computercraft.shared.util.WorldUtil; 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.Minecraft;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.WorldRenderer; 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.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; 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". * Draw an outline for a specific part of a cable "Multipart".
* *
* @param event The event to observe * @param event The event to observe
* @see WorldRenderer#drawSelectionBox(EntityPlayer, RayTraceResult, int, float) * @see WorldRenderer#drawSelectionBox(PlayerEntity, RayTraceResult, int, float)
*/ */
@SubscribeEvent @SubscribeEvent
public static void drawHighlight( DrawBlockHighlightEvent event ) 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(); BlockRayTraceResult hit = (BlockRayTraceResult) event.getTarget();
World world = event.getPlayer().getEntityWorld(); 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. // 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 ) ) 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 ); event.setCanceled( true );
EntityPlayer player = event.getPlayer();
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
float partialTicks = event.getPartialTicks();
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO ); 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.lineWidth( Math.max( 2.5F, mc.mainWindow.getFramebufferWidth() / 1920.0F * 2.5F ) );
GlStateManager.disableTexture2D(); GlStateManager.disableTexture();
GlStateManager.depthMask( false ); GlStateManager.depthMask( false );
GlStateManager.matrixMode( GL11.GL_PROJECTION ); GlStateManager.matrixMode( GL11.GL_PROJECTION );
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.scalef( 1.0F, 1.0F, 0.999F ); GlStateManager.scalef( 1.0F, 1.0F, 0.999F );
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks; VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
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() ) )
? CableShapes.getModemShape( state ) ? CableShapes.getModemShape( state )
: CableShapes.getCableShape( 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.popMatrix();
GlStateManager.matrixMode( GL11.GL_MODELVIEW ); GlStateManager.matrixMode( GL11.GL_MODELVIEW );
GlStateManager.depthMask( true ); GlStateManager.depthMask( true );
GlStateManager.enableTexture2D(); GlStateManager.enableTexture();
GlStateManager.disableBlend(); GlStateManager.disableBlend();
} }
} }

View File

@ -6,13 +6,13 @@
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.FirstPersonRenderer; import net.minecraft.client.renderer.FirstPersonRenderer;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.EnumHandSide; import net.minecraft.util.HandSide;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
public abstract class ItemMapLikeRenderer public abstract class ItemMapLikeRenderer
@ -25,19 +25,19 @@ public abstract class ItemMapLikeRenderer
*/ */
protected abstract void renderItem( ItemStack stack ); 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(); GlStateManager.pushMatrix();
if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() ) if( hand == Hand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
{ {
renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack ); renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack );
} }
else else
{ {
renderItemFirstPersonSide( renderItemFirstPersonSide(
hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(), hand == Hand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
equipProgress, swingProgress, stack equipProgress, swingProgress, stack
); );
} }
@ -51,12 +51,12 @@ public abstract class ItemMapLikeRenderer
* @param equipProgress The equip progress of this item * @param equipProgress The equip progress of this item
* @param swingProgress The swing progress of this item * @param swingProgress The swing progress of this item
* @param stack The stack to render * @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(); 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 ); GlStateManager.translatef( offset * 0.125f, -0.125f, 0f );
// If the player is not invisible then render a single arm // If the player is not invisible then render a single arm

View File

@ -6,6 +6,7 @@
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.client.FrameInfo; import dan200.computercraft.client.FrameInfo;
import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.client.gui.FixedWidthFontRenderer;
@ -18,7 +19,6 @@ import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack; 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 ) private static void renderLight( int colour, int width, int height )
{ {
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GlStateManager.disableTexture2D(); GlStateManager.disableTexture();
float r = ((colour >>> 16) & 0xFF) / 255.0f; float r = ((colour >>> 16) & 0xFF) / 255.0f;
float g = ((colour >>> 8) & 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(); buffer.pos( width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
tessellator.draw(); tessellator.draw();
GlStateManager.enableTexture2D(); GlStateManager.enableTexture();
} }
private static void renderTerminal( Terminal terminal, boolean greyscale, int width, int height ) private static void renderTerminal( Terminal terminal, boolean greyscale, int width, int height )

View File

@ -6,9 +6,9 @@
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderItemInFrameEvent; import net.minecraftforge.client.event.RenderItemInFrameEvent;

View File

@ -9,7 +9,7 @@ package dan200.computercraft.client.render;
import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat; 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.IVertexConsumer;
import net.minecraftforge.client.model.pipeline.LightUtil; import net.minecraftforge.client.model.pipeline.LightUtil;
import net.minecraftforge.client.model.pipeline.VertexTransformer; import net.minecraftforge.client.model.pipeline.VertexTransformer;
@ -102,7 +102,7 @@ public final class ModelTransformer
} }
@Override @Override
public void setQuadOrientation( @Nonnull EnumFacing orientation ) public void setQuadOrientation( @Nonnull Direction orientation )
{ {
super.setQuadOrientation( orientation == null ? orientation : TRSRTransformation.rotate( positionMatrix, orientation ) ); super.setQuadOrientation( orientation == null ? orientation : TRSRTransformation.rotate( positionMatrix, orientation ) );
} }
@ -187,7 +187,7 @@ public final class ModelTransformer
private final int[] vertexData; private final int[] vertexData;
private int vertexIndex = 0, elementIndex = 0; private int vertexIndex = 0, elementIndex = 0;
private EnumFacing orientation; private Direction orientation;
private int quadTint; private int quadTint;
private boolean diffuse; private boolean diffuse;
private TextureAtlasSprite texture; private TextureAtlasSprite texture;
@ -212,7 +212,7 @@ public final class ModelTransformer
} }
@Override @Override
public void setQuadOrientation( @Nonnull EnumFacing orientation ) public void setQuadOrientation( @Nonnull Direction orientation )
{ {
this.orientation = orientation; this.orientation = orientation;
} }

View File

@ -6,18 +6,19 @@
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.peripheral.monitor.TileMonitor; import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; 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.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.DrawBlockHighlightEvent; import net.minecraftforge.client.event.DrawBlockHighlightEvent;
@ -27,7 +28,7 @@ import org.lwjgl.opengl.GL11;
import java.util.EnumSet; 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 ) @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
public final class MonitorHighlightRenderer public final class MonitorHighlightRenderer
@ -41,10 +42,13 @@ public final class MonitorHighlightRenderer
@SubscribeEvent @SubscribeEvent
public static void drawHighlight( DrawBlockHighlightEvent event ) 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(); World world = event.getInfo().func_216773_g().getEntityWorld();
BlockPos pos = event.getTarget().getBlockPos(); BlockPos pos = ((BlockRayTraceResult) event.getTarget()).getPos();
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( !(tile instanceof TileMonitor) ) return; if( !(tile instanceof TileMonitor) ) return;
@ -53,8 +57,8 @@ public final class MonitorHighlightRenderer
event.setCanceled( true ); event.setCanceled( true );
// Determine which sides are part of the external faces of the monitor, and so which need to be rendered. // Determine which sides are part of the external faces of the monitor, and so which need to be rendered.
EnumSet<EnumFacing> faces = EnumSet.allOf( EnumFacing.class ); EnumSet<Direction> faces = EnumSet.allOf( Direction.class );
EnumFacing front = monitor.getFront(); Direction front = monitor.getFront();
faces.remove( front ); faces.remove( front );
if( monitor.getXIndex() != 0 ) faces.remove( monitor.getRight().getOpposite() ); if( monitor.getXIndex() != 0 ) faces.remove( monitor.getRight().getOpposite() );
if( monitor.getXIndex() != monitor.getWidth() - 1 ) faces.remove( monitor.getRight() ); if( monitor.getXIndex() != monitor.getWidth() - 1 ) faces.remove( monitor.getRight() );
@ -64,16 +68,12 @@ public final class MonitorHighlightRenderer
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO ); 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.lineWidth( Math.max( 2.5F, (float) Minecraft.getInstance().mainWindow.getFramebufferWidth() / 1920.0F * 2.5F ) );
GlStateManager.disableTexture2D(); GlStateManager.disableTexture();
GlStateManager.depthMask( false ); GlStateManager.depthMask( false );
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
EntityPlayer player = event.getPlayer(); Vec3d cameraPos = event.getInfo().func_216785_c();
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks(); GlStateManager.translated( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() );
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() );
Tessellator tessellator = Tessellator.getInstance(); Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer(); BufferBuilder buffer = tessellator.getBuffer();
@ -97,11 +97,11 @@ public final class MonitorHighlightRenderer
GlStateManager.popMatrix(); GlStateManager.popMatrix();
GlStateManager.depthMask( true ); GlStateManager.depthMask( true );
GlStateManager.enableTexture2D(); GlStateManager.enableTexture();
GlStateManager.disableBlend(); 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 minX = x == 0 ? -EXPAND : 1 + EXPAND;
double minY = y == 0 ? -EXPAND : 1 + EXPAND; double minY = y == 0 ? -EXPAND : 1 + EXPAND;

View File

@ -6,14 +6,14 @@
package dan200.computercraft.client.render; 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.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.core.terminal.TextBuffer;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder; 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.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -76,7 +76,7 @@ public final class PrintoutRenderer
{ {
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GlStateManager.enableTexture2D(); GlStateManager.enableTexture();
GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO ); GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance(); FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
@ -91,7 +91,7 @@ public final class PrintoutRenderer
{ {
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f ); GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
GlStateManager.enableBlend(); GlStateManager.enableBlend();
GlStateManager.enableTexture2D(); GlStateManager.enableTexture();
GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO ); GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
Minecraft.getInstance().getTextureManager().bindTexture( BG ); Minecraft.getInstance().getTextureManager().bindTexture( BG );

View File

@ -6,6 +6,7 @@
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable; import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant; 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.peripheral.modem.wired.TileCable;
import dan200.computercraft.shared.util.WorldUtil; import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.Block; 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.Minecraft;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.model.IBakedModel; 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.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.client.model.data.EmptyModelData; import net.minecraftforge.client.model.data.EmptyModelData;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -52,16 +52,19 @@ public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
RayTraceResult hit = mc.objectMouseOver; 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(); World world = te.getWorld();
IBlockState state = world.getBlockState( pos ); BlockState state = world.getBlockState( pos );
Block block = state.getBlock(); Block block = state.getBlock();
if( block != ComputerCraft.Blocks.cable ) return; 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 ) ) ? block.getDefaultState().with( BlockCable.MODEM, state.get( BlockCable.MODEM ) )
: state.with( BlockCable.MODEM, CableModemVariant.None ); : state.with( BlockCable.MODEM, CableModemVariant.None );
@ -80,7 +83,7 @@ public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
TextureAtlasSprite breakingTexture = mc.getTextureMap().getSprite( DESTROY_STAGES[destroyStage] ); TextureAtlasSprite breakingTexture = mc.getTextureMap().getSprite( DESTROY_STAGES[destroyStage] );
mc.getBlockRendererDispatcher().getBlockModelRenderer().renderModel( mc.getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
world, 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 state, pos, buffer, true, random, state.getPositionRandom( pos ), EmptyModelData.INSTANCE
); );

View File

@ -6,6 +6,8 @@
package dan200.computercraft.client.render; 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.FrameInfo;
import dan200.computercraft.client.gui.FixedWidthFontRenderer; import dan200.computercraft.client.gui.FixedWidthFontRenderer;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
@ -17,12 +19,10 @@ import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder; 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.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@ -64,8 +64,8 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
posZ += originPos.getZ() - monitorPos.getZ(); posZ += originPos.getZ() - monitorPos.getZ();
// Determine orientation // Determine orientation
EnumFacing dir = origin.getDirection(); Direction dir = origin.getDirection();
EnumFacing front = origin.getFront(); Direction front = origin.getFront();
float yaw = dir.getHorizontalAngle(); float yaw = dir.getHorizontalAngle();
float pitch = DirectionUtil.toPitchAngle( front ); float pitch = DirectionUtil.toPitchAngle( front );
@ -94,7 +94,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
// Draw the contents // Draw the contents
GlStateManager.depthMask( false ); GlStateManager.depthMask( false );
OpenGlHelper.glMultiTexCoord2f( OpenGlHelper.GL_TEXTURE1, 0xFFFF, 0xFFFF ); GLX.glMultiTexCoord2f( GLX.GL_TEXTURE1, 0xFFFF, 0xFFFF );
GlStateManager.disableLighting(); GlStateManager.disableLighting();
mc.gameRenderer.disableLightmap(); mc.gameRenderer.disableLightmap();
try try
@ -171,7 +171,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
} }
} }
GlStateManager.callList( originTerminal.renderDisplayLists[0] ); GlStateManager.callList( originTerminal.renderDisplayLists[0] );
GlStateManager.resetColor(); GlStateManager.clearCurrentColor();
// Draw text // Draw text
fontRenderer.bindFont(); fontRenderer.bindFont();
@ -199,7 +199,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
} }
} }
GlStateManager.callList( originTerminal.renderDisplayLists[1] ); GlStateManager.callList( originTerminal.renderDisplayLists[1] );
GlStateManager.resetColor(); GlStateManager.clearCurrentColor();
// Draw cursor // Draw cursor
fontRenderer.bindFont(); fontRenderer.bindFont();
@ -233,7 +233,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
if( FrameInfo.getGlobalCursorBlink() ) if( FrameInfo.getGlobalCursorBlink() )
{ {
GlStateManager.callList( originTerminal.renderDisplayLists[2] ); GlStateManager.callList( originTerminal.renderDisplayLists[2] );
GlStateManager.resetColor(); GlStateManager.clearCurrentColor();
} }
} }
finally finally

View File

@ -6,6 +6,7 @@
package dan200.computercraft.client.render; package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide; import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.computer.core.ComputerFamily; 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.DirectionUtil;
import dan200.computercraft.shared.util.Holiday; import dan200.computercraft.shared.util.Holiday;
import dan200.computercraft.shared.util.HolidayUtil; 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.Minecraft;
import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ModelManager; import net.minecraft.client.renderer.model.ModelManager;
import net.minecraft.client.renderer.model.ModelResourceLocation; 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.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat; 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.ResourceLocation;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.data.EmptyModelData; import net.minecraftforge.client.model.data.EmptyModelData;
@ -85,13 +87,15 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
{ {
// Render the label // Render the label
String label = turtle.createProxy().getLabel(); 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 ); setLightmapDisabled( true );
GameRenderer.drawNameplate( GameRenderer.func_215307_a(
getFontRenderer(), label, getFontRenderer(), label,
(float) posX + 0.5F, (float) posY + 1.2F, (float) posZ + 0.5F, 0, (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 ); setLightmapDisabled( false );
} }
@ -99,7 +103,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
try try
{ {
IBlockState state = turtle.getBlockState(); BlockState state = turtle.getBlockState();
// Setup the transform // Setup the transform
Vec3d offset = turtle.getRenderOffset( partialTicks ); Vec3d offset = turtle.getRenderOffset( partialTicks );
float yaw = turtle.getRenderYaw( partialTicks ); float yaw = turtle.getRenderYaw( partialTicks );
@ -153,7 +157,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
} }
} }
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 ); ITurtleUpgrade upgrade = turtle.getUpgrade( side );
if( upgrade != null ) if( upgrade != null )
@ -186,20 +190,20 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
} }
} }
private void renderModel( IBlockState state, ModelResourceLocation modelLocation, int[] tints ) private void renderModel( BlockState state, ModelResourceLocation modelLocation, int[] tints )
{ {
Minecraft mc = Minecraft.getInstance(); Minecraft mc = Minecraft.getInstance();
ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager(); ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager();
renderModel( state, modelManager.getModel( modelLocation ), tints ); 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 ); Random random = new Random( 0 );
Tessellator tessellator = Tessellator.getInstance(); 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 ); 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 ); renderQuads( tessellator, model.getQuads( state, facing, random, EmptyModelData.INSTANCE ), tints );
} }

View File

@ -9,15 +9,15 @@ package dan200.computercraft.client.render;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.IUnbakedModel; 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.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.resources.IResourceManager; import net.minecraft.resources.IResourceManager;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ICustomModelLoader; import net.minecraftforge.client.model.ICustomModelLoader;
import net.minecraftforge.common.model.IModelState;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
@ -91,13 +91,13 @@ public final class TurtleModelLoader implements ICustomModelLoader
.collect( Collectors.toSet() ); .collect( Collectors.toSet() );
} }
@Nullable @Nonnull
@Override @Override
public IBakedModel bake( @Nonnull Function<ResourceLocation, IUnbakedModel> modelGetter, @Nonnull Function<ResourceLocation, TextureAtlasSprite> spriteGetter, @Nonnull IModelState state, boolean uvlock, @Nonnull VertexFormat format ) public IBakedModel bake( @Nonnull ModelBakery bakery, @Nonnull Function<ResourceLocation, TextureAtlasSprite> spriteGetter, @Nonnull ISprite sprite, @Nonnull VertexFormat format )
{ {
return new TurtleSmartItemModel( return new TurtleSmartItemModel(
modelGetter.apply( family ).bake( modelGetter, spriteGetter, state, uvlock, format ), bakery.getBakedModel( family, sprite, spriteGetter, format ),
modelGetter.apply( COLOUR_TURTLE_MODEL ).bake( modelGetter, spriteGetter, state, uvlock, format ) bakery.getBakedModel( COLOUR_TURTLE_MODEL, sprite, spriteGetter, format )
); );
} }
} }

View File

@ -6,12 +6,12 @@
package dan200.computercraft.client.render; 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.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ItemOverrideList; import net.minecraft.client.renderer.model.ItemOverrideList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; 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.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.IModelData;
@ -29,7 +29,7 @@ public class TurtleMultiModel implements IBakedModel
private final IBakedModel m_rightUpgradeModel; private final IBakedModel m_rightUpgradeModel;
private final Matrix4f m_rightUpgradeTransform; private final Matrix4f m_rightUpgradeTransform;
private List<BakedQuad> m_generalQuads = null; private List<BakedQuad> m_generalQuads = null;
private Map<EnumFacing, List<BakedQuad>> m_faceQuads = new EnumMap<>( EnumFacing.class ); private Map<Direction, List<BakedQuad>> m_faceQuads = new EnumMap<>( Direction.class );
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, Matrix4f generalTransform, IBakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, IBakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform ) 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 @Nonnull
@Override @Override
@Deprecated @Deprecated
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, @Nonnull Random rand ) public List<BakedQuad> getQuads( BlockState state, Direction side, @Nonnull Random rand )
{ {
return getQuads( state, side, rand, EmptyModelData.INSTANCE ); return getQuads( state, side, rand, EmptyModelData.INSTANCE );
} }
@Nonnull @Nonnull
@Override @Override
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, @Nonnull Random rand, @Nonnull IModelData data ) public List<BakedQuad> getQuads( BlockState state, Direction side, @Nonnull Random rand, @Nonnull IModelData data )
{ {
if( side != null ) if( side != null )
{ {
@ -67,7 +67,7 @@ public class TurtleMultiModel implements IBakedModel
} }
} }
private List<BakedQuad> buildQuads( IBlockState state, EnumFacing side, Random rand ) private List<BakedQuad> buildQuads( BlockState state, Direction side, Random rand )
{ {
ArrayList<BakedQuad> quads = new ArrayList<>(); ArrayList<BakedQuad> quads = new ArrayList<>();
ModelTransformer.transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform ); ModelTransformer.transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform );

View File

@ -12,13 +12,13 @@ import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.turtle.items.ItemTurtle; import dan200.computercraft.shared.turtle.items.ItemTurtle;
import dan200.computercraft.shared.util.Holiday; import dan200.computercraft.shared.util.Holiday;
import dan200.computercraft.shared.util.HolidayUtil; 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.Minecraft;
import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; 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.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.IModelData;
@ -111,7 +111,7 @@ public class TurtleSmartItemModel implements IBakedModel
{ {
@Nonnull @Nonnull
@Override @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(); ItemTurtle turtle = (ItemTurtle) stack.getItem();
int colour = turtle.getColour( stack ); int colour = turtle.getColour( stack );
@ -169,7 +169,7 @@ public class TurtleSmartItemModel implements IBakedModel
@Nonnull @Nonnull
@Override @Override
@Deprecated @Deprecated
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, @Nonnull Random rand ) public List<BakedQuad> getQuads( BlockState state, Direction facing, @Nonnull Random rand )
{ {
return familyModel.getQuads( state, facing, rand ); return familyModel.getQuads( state, facing, rand );
} }
@ -177,7 +177,7 @@ public class TurtleSmartItemModel implements IBakedModel
@Nonnull @Nonnull
@Override @Override
@Deprecated @Deprecated
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, @Nonnull Random rand, @Nonnull IModelData data ) public List<BakedQuad> getQuads( BlockState state, Direction facing, @Nonnull Random rand, @Nonnull IModelData data )
{ {
return familyModel.getQuads( state, facing, rand, data ); return familyModel.getQuads( state, facing, rand, data );
} }

View File

@ -6,11 +6,13 @@
package dan200.computercraft.core.computer; package dan200.computercraft.core.computer;
import net.minecraft.util.Direction;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; 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.. * facing..
*/ */
public enum ComputerSide public enum ComputerSide

View File

@ -267,7 +267,7 @@ public class ResourceMount implements IMount
synchronized void add( IReloadableResourceManager manager, ResourceMount mount ) 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 ); mounts.add( mount );
} }
} }

View File

@ -7,7 +7,7 @@
package dan200.computercraft.core.terminal; package dan200.computercraft.core.terminal;
import dan200.computercraft.shared.util.Palette; import dan200.computercraft.shared.util.Palette;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
public class Terminal public class Terminal
{ {
@ -334,7 +334,7 @@ public class Terminal
m_changed = false; m_changed = false;
} }
public synchronized NBTTagCompound writeToNBT( NBTTagCompound nbt ) public synchronized CompoundNBT writeToNBT( CompoundNBT nbt )
{ {
nbt.putInt( "term_cursorX", m_cursorX ); nbt.putInt( "term_cursorX", m_cursorX );
nbt.putInt( "term_cursorY", m_cursorY ); nbt.putInt( "term_cursorY", m_cursorY );
@ -354,7 +354,7 @@ public class Terminal
return nbt; return nbt;
} }
public synchronized void readFromNBT( NBTTagCompound nbt ) public synchronized void readFromNBT( CompoundNBT nbt )
{ {
m_cursorX = nbt.getInt( "term_cursorX" ); m_cursorX = nbt.getInt( "term_cursorX" );
m_cursorY = nbt.getInt( "term_cursorY" ); m_cursorY = nbt.getInt( "term_cursorY" );

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; 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.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -30,12 +30,12 @@ public final class BundledRedstone
providers.add( provider ); 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; 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; if( !World.isValid( pos ) ) return -1;
@ -60,7 +60,7 @@ public final class BundledRedstone
return combinedSignal; 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 ); int signal = getUnmaskedOutput( world, pos, side );
return signal >= 0 ? signal : 0; return signal >= 0 ? signal : 0;

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.peripheral.IPeripheralProvider; 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.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -30,12 +30,12 @@ public final class Peripherals
providers.add( provider ); 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; 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: // Try the handlers in order:
for( IPeripheralProvider peripheralProvider : providers ) for( IPeripheralProvider peripheralProvider : providers )

View File

@ -39,10 +39,10 @@ import dan200.computercraft.shared.util.CreativeTabMain;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.init.Items; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.Items;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.RegistryEvent;
@ -181,7 +181,7 @@ public final class Registry
); );
} }
private static <T extends ItemBlock> T setupItemBlock( T item ) private static <T extends BlockItem> T setupItemBlock( T item )
{ {
item.setRegistryName( item.getBlock().getRegistryName() ); item.setRegistryName( item.getBlock().getRegistryName() );
return item; return item;
@ -247,14 +247,14 @@ public final class Registry
// Peripherals // Peripherals
registry.registerAll( registry.registerAll(
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.speaker, defaultItem() ) ), setupItemBlock( new BlockItem( ComputerCraft.Blocks.speaker, defaultItem() ) ),
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.diskDrive, defaultItem() ) ), setupItemBlock( new BlockItem( ComputerCraft.Blocks.diskDrive, defaultItem() ) ),
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.printer, defaultItem() ) ), setupItemBlock( new BlockItem( ComputerCraft.Blocks.printer, defaultItem() ) ),
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.monitorNormal, defaultItem() ) ), setupItemBlock( new BlockItem( ComputerCraft.Blocks.monitorNormal, defaultItem() ) ),
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.monitorAdvanced, defaultItem() ) ), setupItemBlock( new BlockItem( ComputerCraft.Blocks.monitorAdvanced, defaultItem() ) ),
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.wirelessModemNormal, defaultItem() ) ), setupItemBlock( new BlockItem( ComputerCraft.Blocks.wirelessModemNormal, defaultItem() ) ),
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.wirelessModemAdvanced, defaultItem() ) ), setupItemBlock( new BlockItem( ComputerCraft.Blocks.wirelessModemAdvanced, defaultItem() ) ),
setupItemBlock( new ItemBlock( ComputerCraft.Blocks.wiredModemFull, defaultItem() ) ) setupItemBlock( new BlockItem( ComputerCraft.Blocks.wiredModemFull, defaultItem() ) )
); );
ComputerCraft.Items.cable = new ItemBlockCable.Cable( ComputerCraft.Blocks.cable, 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 ); ComputerCraft.TurtleUpgrades.diamondSword = new TurtleSword( new ResourceLocation( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD );
ComputerCraftAPI.registerTurtleUpgrade( ComputerCraft.TurtleUpgrades.diamondSword ); 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 ); ComputerCraftAPI.registerTurtleUpgrade( ComputerCraft.TurtleUpgrades.diamondShovel );
ComputerCraft.TurtleUpgrades.diamondPickaxe = new TurtleTool( new ResourceLocation( "minecraft", "diamond_pickaxe" ), Items.DIAMOND_PICKAXE ); ComputerCraft.TurtleUpgrades.diamondPickaxe = new TurtleTool( new ResourceLocation( "minecraft", "diamond_pickaxe" ), Items.DIAMOND_PICKAXE );

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.event.TurtleActionEvent; 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.server.MinecraftServer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -18,13 +18,13 @@ import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID ) @Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID )
public final class TurtlePermissions 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(); MinecraftServer server = world.getServer();
return server == null || world.isRemote || !server.isBlockProtected( world, pos, player ); 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(); MinecraftServer server = world.getServer();
return server == null || world.isRemote || !server.isBlockProtected( world, pos, player ); return server == null || world.isRemote || !server.isBlockProtected( world, pos, player );

View File

@ -20,17 +20,17 @@ import dan200.computercraft.core.tracking.TrackingField;
import dan200.computercraft.shared.command.text.TableBuilder; import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.network.Containers; import dan200.computercraft.shared.network.container.ViewComputerContainerData;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.play.server.SPacketPlayerPosLook; import net.minecraft.network.play.server.SPlayerPositionLookPacket;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; 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.World;
import net.minecraft.world.WorldServer;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.*; import java.util.*;
@ -170,16 +170,21 @@ public final class CommandComputerCraft
if( world == null || pos == null ) throw TP_NOT_THERE.create(); if( world == null || pos == null ) throw TP_NOT_THERE.create();
Entity entity = context.getSource().assertIsEntity(); 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 ) 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 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; return 1;
@ -210,9 +215,9 @@ public final class CommandComputerCraft
.requires( UserLevel.OP ) .requires( UserLevel.OP )
.arg( "computer", oneComputer() ) .arg( "computer", oneComputer() )
.executes( context -> { .executes( context -> {
EntityPlayerMP player = context.getSource().asPlayer(); ServerPlayerEntity player = context.getSource().asPlayer();
ServerComputer computer = getComputerArgument( context, "computer" ); ServerComputer computer = getComputerArgument( context, "computer" );
Containers.openComputerGUI( player, computer ); new ViewComputerContainerData( computer ).open( player );
return 1; return 1;
} ) ) } ) )
@ -259,7 +264,7 @@ public final class CommandComputerCraft
private static ITextComponent linkComputer( CommandSource source, ServerComputer serverComputer, int computerId ) private static ITextComponent linkComputer( CommandSource source, ServerComputer serverComputer, int computerId )
{ {
ITextComponent out = new TextComponentString( "" ); ITextComponent out = new StringTextComponent( "" );
// Append the computer instance // Append the computer instance
if( serverComputer == null ) if( serverComputer == null )
@ -319,7 +324,7 @@ public final class CommandComputerCraft
private static TrackingContext getTimingContext( CommandSource source ) private static TrackingContext getTimingContext( CommandSource source )
{ {
Entity entity = source.getEntity(); 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<TrackingField> DEFAULT_FIELDS = Arrays.asList( TrackingField.TASKS, TrackingField.TOTAL_TIME, TrackingField.AVERAGE_TIME, TrackingField.MAX_TIME ); private static final List<TrackingField> DEFAULT_FIELDS = Arrays.asList( TrackingField.TASKS, TrackingField.TOTAL_TIME, TrackingField.AVERAGE_TIME, TrackingField.MAX_TIME );

View File

@ -12,8 +12,8 @@ import dan200.computercraft.ComputerCraft;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent; import net.minecraft.util.text.event.HoverEvent;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@ -58,10 +58,10 @@ public final class CommandCopy
public static ITextComponent createCopyText( String text ) public static ITextComponent createCopyText( String text )
{ {
TextComponentString name = new TextComponentString( text ); StringTextComponent name = new StringTextComponent( text );
name.getStyle() name.getStyle()
.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, PREFIX + text ) ) .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; return name;
} }
} }

View File

@ -12,7 +12,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.command.ISuggestionProvider; import net.minecraft.command.ISuggestionProvider;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import java.util.Arrays; import java.util.Arrays;
@ -27,9 +27,9 @@ public final class CommandUtils
public static boolean isPlayer( CommandSource output ) public static boolean isPlayer( CommandSource output )
{ {
Entity sender = output.getEntity(); Entity sender = output.getEntity();
return sender instanceof EntityPlayerMP return sender instanceof ServerPlayerEntity
&& !(sender instanceof FakePlayer) && !(sender instanceof FakePlayer)
&& ((EntityPlayerMP) sender).connection != null; && ((ServerPlayerEntity) sender).connection != null;
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared.command;
import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType; import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TranslationTextComponent;
public final class Exceptions public final class Exceptions
{ {
@ -28,16 +28,16 @@ public final class Exceptions
private static SimpleCommandExceptionType translated( String key ) private static SimpleCommandExceptionType translated( String key )
{ {
return new SimpleCommandExceptionType( new TextComponentTranslation( key ) ); return new SimpleCommandExceptionType( new TranslationTextComponent( key ) );
} }
private static DynamicCommandExceptionType translated1( String 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 ) 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 ) );
} }
} }

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.command;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -62,8 +62,8 @@ public enum UserLevel implements Predicate<CommandSource>
MinecraftServer server = source.getServer(); MinecraftServer server = source.getServer();
Entity sender = source.getEntity(); Entity sender = source.getEntity();
if( server.isSinglePlayer() && sender instanceof EntityPlayer && if( server.isSinglePlayer() && sender instanceof PlayerEntity &&
((EntityPlayer) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() ) ) ((PlayerEntity) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() ) )
{ {
if( this == OWNER || this == OWNER_OP ) return true; if( this == OWNER || this == OWNER_OP ) return true;
} }

View File

@ -18,12 +18,12 @@ public final class ArgumentSerializers
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
private static <T extends ArgumentType<?>> void registerUnsafe( ResourceLocation id, Class<T> type, IArgumentSerializer<?> serializer ) private static <T extends ArgumentType<?>> void registerUnsafe( ResourceLocation id, Class<T> type, IArgumentSerializer<?> serializer )
{ {
ArgumentTypes.register( id, type, (IArgumentSerializer<T>) serializer ); ArgumentTypes.func_218136_a( id.toString(), type, (IArgumentSerializer<T>) serializer );
} }
private static <T extends ArgumentType<?>> void register( ResourceLocation id, Class<T> type, IArgumentSerializer<T> serializer ) private static <T extends ArgumentType<?>> void register( ResourceLocation id, Class<T> type, IArgumentSerializer<T> serializer )
{ {
ArgumentTypes.register( id, type, serializer ); ArgumentTypes.func_218136_a( id.toString(), type, serializer );
} }
private static <T extends ArgumentType<?>> void register( ResourceLocation id, T instance ) private static <T extends ArgumentType<?>> void register( ResourceLocation id, T instance )

View File

@ -19,7 +19,7 @@ import net.minecraft.command.arguments.ArgumentTypes;
import net.minecraft.command.arguments.IArgumentSerializer; import net.minecraft.command.arguments.IArgumentSerializer;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
@ -160,7 +160,7 @@ public final class RepeatArgumentType<T, U> implements ArgumentType<List<T>>
{ {
Message message = arg.some.create().getRawMessage(); Message message = arg.some.create().getRawMessage();
if( message instanceof ITextComponent ) return (ITextComponent) message; if( message instanceof ITextComponent ) return (ITextComponent) message;
return new TextComponentString( message.getString() ); return new StringTextComponent( message.getString() );
} }
} }
} }

View File

@ -15,7 +15,7 @@ import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.util.text.ITextComponent; 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.TextFormatting;
import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.ClickEvent;
@ -174,7 +174,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
temp.addChild( node ); temp.addChild( node );
String usage = dispatcher.getSmartUsage( temp, context.getSource() ).get( node ).substring( node.getName().length() ); String usage = dispatcher.getSmartUsage( temp, context.getSource() ).get( node ).substring( node.getName().length() );
ITextComponent output = new TextComponentString( "" ) ITextComponent output = new StringTextComponent( "" )
.appendSibling( coloured( "/" + command + usage, HEADER ) ) .appendSibling( coloured( "/" + command + usage, HEADER ) )
.appendText( " " ) .appendText( " " )
.appendSibling( coloured( translate( "commands." + id + ".synopsis" ), SYNOPSIS ) ) .appendSibling( coloured( translate( "commands." + id + ".synopsis" ), SYNOPSIS ) )

View File

@ -22,7 +22,7 @@ public final class ChatHelpers
public static ITextComponent coloured( String text, TextFormatting colour ) public static ITextComponent coloured( String text, TextFormatting colour )
{ {
ITextComponent component = new TextComponentString( text == null ? "" : text ); ITextComponent component = new StringTextComponent( text == null ? "" : text );
component.getStyle().setColor( colour ); component.getStyle().setColor( colour );
return component; return component;
} }
@ -35,22 +35,22 @@ public final class ChatHelpers
public static ITextComponent text( String text ) public static ITextComponent text( String text )
{ {
return new TextComponentString( text == null ? "" : text ); return new StringTextComponent( text == null ? "" : text );
} }
public static ITextComponent translate( String text ) public static ITextComponent translate( String text )
{ {
return new TextComponentTranslation( text == null ? "" : text ); return new TranslationTextComponent( text == null ? "" : text );
} }
public static ITextComponent translate( String text, Object... args ) public static ITextComponent translate( String text, Object... args )
{ {
return new TextComponentTranslation( text == null ? "" : text, args ); return new TranslationTextComponent( text == null ? "" : text, args );
} }
public static ITextComponent list( ITextComponent... children ) public static ITextComponent list( ITextComponent... children )
{ {
ITextComponent component = new TextComponentString( "" ); ITextComponent component = new StringTextComponent( "" );
for( ITextComponent child : children ) for( ITextComponent child : children )
{ {
component.appendSibling( child ); component.appendSibling( child );

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.command.text;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -28,7 +28,7 @@ public class ServerTableFormatter implements TableFormatter
{ {
int extraWidth = width - getWidth( component ); int extraWidth = width - getWidth( component );
if( extraWidth <= 0 ) return null; if( extraWidth <= 0 ) return null;
return new TextComponentString( StringUtils.repeat( ' ', extraWidth ) ); return new StringTextComponent( StringUtils.repeat( ' ', extraWidth ) );
} }
@Override @Override

View File

@ -10,7 +10,7 @@ import dan200.computercraft.shared.command.CommandUtils;
import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.network.client.ChatTableClientMessage; import dan200.computercraft.shared.network.client.ChatTableClientMessage;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -125,7 +125,7 @@ public class TableBuilder
if( CommandUtils.isPlayer( source ) ) if( CommandUtils.isPlayer( source ) )
{ {
trim( 18 ); trim( 18 );
NetworkHandler.sendToPlayer( (EntityPlayerMP) source.getEntity(), new ChatTableClientMessage( this ) ); NetworkHandler.sendToPlayer( (ServerPlayerEntity) source.getEntity(), new ChatTableClientMessage( this ) );
} }
else else
{ {

View File

@ -7,7 +7,7 @@
package dan200.computercraft.shared.command.text; package dan200.computercraft.shared.command.text;
import net.minecraft.util.text.ITextComponent; 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.TextFormatting;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -77,7 +77,7 @@ public interface TableFormatter
if( headers != null ) if( headers != null )
{ {
TextComponentString line = new TextComponentString( "" ); StringTextComponent line = new StringTextComponent( "" );
for( int i = 0; i < columns - 1; i++ ) for( int i = 0; i < columns - 1; i++ )
{ {
line.appendSibling( headers[i] ); line.appendSibling( headers[i] );
@ -98,7 +98,7 @@ public interface TableFormatter
for( ITextComponent[] row : table.getRows() ) for( ITextComponent[] row : table.getRows() )
{ {
TextComponentString line = new TextComponentString( "" ); StringTextComponent line = new StringTextComponent( "" );
for( int i = 0; i < columns - 1; i++ ) for( int i = 0; i < columns - 1; i++ )
{ {
line.appendSibling( row[i] ); line.appendSibling( row[i] );

View File

@ -6,14 +6,15 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import dan200.computercraft.shared.util.NamedTileEntityType;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Hand;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader; import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -26,15 +27,16 @@ public abstract class BlockGeneric extends Block
{ {
private final TileEntityType<? extends TileGeneric> type; private final TileEntityType<? extends TileGeneric> type;
public BlockGeneric( Properties settings, TileEntityType<? extends TileGeneric> type ) public BlockGeneric( Properties settings, NamedTileEntityType<? extends TileGeneric> type )
{ {
super( settings ); super( settings );
this.type = type; this.type = type;
type.setBlock( this );
} }
@Override @Override
@Deprecated @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; if( block.getBlock() == replace.getBlock() ) return;
@ -46,22 +48,22 @@ public abstract class BlockGeneric extends Block
@Override @Override
@Deprecated @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 ); 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 @Override
@Deprecated @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 ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourChange( neighbourPos );
} }
@Override @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 ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourTileEntityChange( neighbour ); if( tile instanceof TileGeneric ) ((TileGeneric) tile).onNeighbourTileEntityChange( neighbour );
@ -69,21 +71,21 @@ public abstract class BlockGeneric extends Block
@Override @Override
@Deprecated @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 ); TileEntity te = world.getTileEntity( pos );
if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick(); if( te instanceof TileGeneric ) ((TileGeneric) te).blockTick();
} }
@Override @Override
public boolean hasTileEntity( IBlockState state ) public boolean hasTileEntity( BlockState state )
{ {
return true; return true;
} }
@Nullable @Nullable
@Override @Override
public TileEntity createTileEntity( @Nonnull IBlockState state, @Nonnull IBlockReader world ) public TileEntity createTileEntity( @Nonnull BlockState state, @Nonnull IBlockReader world )
{ {
return type.create(); return type.create();
} }

View File

@ -7,7 +7,7 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
public class ClientTerminal implements ITerminal public class ClientTerminal implements ITerminal
{ {
@ -47,12 +47,12 @@ public class ClientTerminal implements ITerminal
return m_colour; return m_colour;
} }
public void readDescription( NBTTagCompound nbt ) public void readDescription( CompoundNBT nbt )
{ {
m_colour = nbt.getBoolean( "colour" ); m_colour = nbt.getBoolean( "colour" );
if( nbt.contains( "terminal" ) ) if( nbt.contains( "terminal" ) )
{ {
NBTTagCompound terminal = nbt.getCompound( "terminal" ); CompoundNBT terminal = nbt.getCompound( "terminal" );
resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) ); resizeTerminal( terminal.getInt( "term_width" ), terminal.getInt( "term_height" ) );
m_terminal.readFromNBT( terminal ); m_terminal.readFromNBT( terminal );
} }

View File

@ -6,30 +6,29 @@
package dan200.computercraft.shared.common; 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.Colour;
import dan200.computercraft.shared.util.ColourTracker; import dan200.computercraft.shared.util.ColourTracker;
import dan200.computercraft.shared.util.ColourUtils; import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.EnumDyeColor; import net.minecraft.item.DyeColor;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeSerializer; 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.util.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class ColourableRecipe extends AbstractRecipe public class ColourableRecipe extends SpecialRecipe
{ {
public ColourableRecipe( ResourceLocation id ) private ColourableRecipe( ResourceLocation id )
{ {
super( id ); super( id );
} }
@Override @Override
public boolean matches( @Nonnull IInventory inv, @Nonnull World world ) public boolean matches( @Nonnull CraftingInventory inv, @Nonnull World world )
{ {
boolean hasColourable = false; boolean hasColourable = false;
boolean hasDye = false; boolean hasDye = false;
@ -58,7 +57,7 @@ public class ColourableRecipe extends AbstractRecipe
@Nonnull @Nonnull
@Override @Override
public ItemStack getCraftingResult( @Nonnull IInventory inv ) public ItemStack getCraftingResult( @Nonnull CraftingInventory inv )
{ {
ItemStack colourable = ItemStack.EMPTY; ItemStack colourable = ItemStack.EMPTY;
@ -76,7 +75,7 @@ public class ColourableRecipe extends AbstractRecipe
} }
else else
{ {
EnumDyeColor dye = ColourUtils.getStackColour( stack ); DyeColor dye = ColourUtils.getStackColour( stack );
if( dye == null ) continue; if( dye == null ) continue;
Colour colour = Colour.fromInt( 15 - dye.getId() ); Colour colour = Colour.fromInt( 15 - dye.getId() );
@ -101,7 +100,5 @@ public class ColourableRecipe extends AbstractRecipe
return SERIALIZER; return SERIALIZER;
} }
public static final IRecipeSerializer<?> SERIALIZER = new RecipeSerializers.SimpleSerializer<>( public static final IRecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>( ColourableRecipe::new );
ComputerCraft.MOD_ID + ":colour", ColourableRecipe::new
);
} }

View File

@ -6,21 +6,28 @@
package dan200.computercraft.shared.common; 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 dan200.computercraft.shared.util.InventoryUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class ContainerHeldItem extends Container public class ContainerHeldItem extends Container
{ {
private final ItemStack m_stack; public static final ContainerType<ContainerHeldItem> PRINTOUT_TYPE = ContainerData.create( PrintoutContainerData::new );
private final EnumHand m_hand;
public ContainerHeldItem( EntityPlayer player, EnumHand hand ) private final ItemStack m_stack;
private final Hand m_hand;
public ContainerHeldItem( ContainerType<? extends ContainerHeldItem> type, int id, PlayerEntity player, Hand hand )
{ {
super( type, id );
m_hand = hand; m_hand = hand;
m_stack = InventoryUtil.copyItem( player.getHeldItem( hand ) ); m_stack = InventoryUtil.copyItem( player.getHeldItem( hand ) );
} }
@ -32,7 +39,7 @@ public class ContainerHeldItem extends Container
} }
@Override @Override
public boolean canInteractWith( @Nonnull EntityPlayer player ) public boolean canInteractWith( @Nonnull PlayerEntity player )
{ {
if( !player.isAlive() ) return false; if( !player.isAlive() ) return false;

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.common;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -17,12 +17,12 @@ import javax.annotation.Nonnull;
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider
{ {
@Override @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 ); 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(); Block block = world.getBlockState( pos ).getBlock();
if( block instanceof IBundledRedstoneBlock ) if( block instanceof IBundledRedstoneBlock )

View File

@ -6,13 +6,13 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface IBundledRedstoneBlock 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 );
} }

View File

@ -7,7 +7,7 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
public interface IColouredItem public interface IColouredItem
{ {
@ -27,7 +27,7 @@ public interface IColouredItem
static int getColourBasic( ItemStack stack ) 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; return tag != null && tag.contains( NBT_COLOUR ) ? tag.getInt( NBT_COLOUR ) : -1;
} }
@ -35,7 +35,7 @@ public interface IColouredItem
{ {
if( colour == -1 ) if( colour == -1 )
{ {
NBTTagCompound tag = stack.getTag(); CompoundNBT tag = stack.getTag();
if( tag != null ) tag.remove( NBT_COLOUR ); if( tag != null ) tag.remove( NBT_COLOUR );
} }
else else

View File

@ -7,7 +7,7 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -86,12 +86,12 @@ public class ServerTerminal implements ITerminal
// Networking stuff // Networking stuff
public void writeDescription( NBTTagCompound nbt ) public void writeDescription( CompoundNBT nbt )
{ {
nbt.putBoolean( "colour", m_colour ); nbt.putBoolean( "colour", m_colour );
if( m_terminal != null ) if( m_terminal != null )
{ {
NBTTagCompound terminal = new NBTTagCompound(); CompoundNBT terminal = new CompoundNBT();
terminal.putInt( "term_width", m_terminal.getWidth() ); terminal.putInt( "term_width", m_terminal.getWidth() );
terminal.putInt( "term_height", m_terminal.getHeight() ); terminal.putInt( "term_height", m_terminal.getHeight() );
m_terminal.writeToNBT( terminal ); m_terminal.writeToNBT( terminal );

View File

@ -6,16 +6,16 @@
package dan200.computercraft.shared.common; package dan200.computercraft.shared.common;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager; 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.TileEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Hand;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -34,12 +34,12 @@ public abstract class TileGeneric extends TileEntity
{ {
markDirty(); markDirty();
BlockPos pos = getPos(); BlockPos pos = getPos();
IBlockState state = getBlockState(); BlockState state = getBlockState();
getWorld().markBlockRangeForRenderUpdate( pos, pos ); getWorld().markForRerender( pos );
getWorld().notifyBlockUpdate( pos, state, state, 3 ); 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; 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; 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( player == null || !player.isAlive() || getWorld().getTileEntity( getPos() ) != this ) return false;
if( ignoreRange ) return true; 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; 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 @Nonnull
@Override @Override
public final SPacketUpdateTileEntity getUpdatePacket() public final SUpdateTileEntityPacket getUpdatePacket()
{ {
NBTTagCompound nbt = new NBTTagCompound(); CompoundNBT nbt = new CompoundNBT();
writeDescription( nbt ); writeDescription( nbt );
return new SPacketUpdateTileEntity( pos, 0, nbt ); return new SUpdateTileEntityPacket( pos, 0, nbt );
} }
@Override @Override
public final void onDataPacket( NetworkManager net, SPacketUpdateTileEntity packet ) public final void onDataPacket( NetworkManager net, SUpdateTileEntityPacket packet )
{ {
if( packet.getTileEntityType() == 0 ) readDescription( packet.getNbtCompound() ); if( packet.getTileEntityType() == 0 ) readDescription( packet.getNbtCompound() );
} }
@Nonnull @Nonnull
@Override @Override
public NBTTagCompound getUpdateTag() public CompoundNBT getUpdateTag()
{ {
NBTTagCompound tag = super.getUpdateTag(); CompoundNBT tag = super.getUpdateTag();
writeDescription( tag ); writeDescription( tag );
return tag; return tag;
} }
@Override @Override
public void handleUpdateTag( @Nonnull NBTTagCompound tag ) public void handleUpdateTag( @Nonnull CompoundNBT tag )
{ {
super.handleUpdateTag( tag ); super.handleUpdateTag( tag );
readDescription( tag ); readDescription( tag );

View File

@ -16,10 +16,10 @@ import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.shared.computer.blocks.TileCommandComputer; import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
import dan200.computercraft.shared.util.NBTUtil; import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands; import net.minecraft.command.Commands;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.state.IProperty; import net.minecraft.state.IProperty;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -97,7 +97,7 @@ public class CommandAPI implements ILuaAPI
private static Object getBlockInfo( World world, BlockPos pos ) private static Object getBlockInfo( World world, BlockPos pos )
{ {
// Get the details of the block // Get the details of the block
IBlockState state = world.getBlockState( pos ); BlockState state = world.getBlockState( pos );
Block block = state.getBlock(); Block block = state.getBlock();
Map<Object, Object> table = new HashMap<>(); Map<Object, Object> table = new HashMap<>();
@ -112,7 +112,7 @@ public class CommandAPI implements ILuaAPI
table.put( "state", stateTable ); table.put( "state", stateTable );
TileEntity tile = world.getTileEntity( pos ); 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; return table;
} }

View File

@ -9,16 +9,16 @@ package dan200.computercraft.shared.computer.blocks;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.items.ComputerItemFactory; import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import dan200.computercraft.shared.util.NamedTileEntityType;
import net.minecraft.block.Block; 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.BlockItemUseContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.state.DirectionProperty; import net.minecraft.state.DirectionProperty;
import net.minecraft.state.EnumProperty; import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction;
import net.minecraft.util.EnumFacing;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -28,24 +28,24 @@ public class BlockComputer extends BlockComputerBase<TileComputer>
public static final EnumProperty<ComputerState> STATE = EnumProperty.create( "state", ComputerState.class ); public static final EnumProperty<ComputerState> STATE = EnumProperty.create( "state", ComputerState.class );
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public BlockComputer( Properties settings, ComputerFamily family, TileEntityType<? extends TileComputer> type ) public BlockComputer( Properties settings, ComputerFamily family, NamedTileEntityType<? extends TileComputer> type )
{ {
super( settings, family, type ); super( settings, family, type );
setDefaultState( getDefaultState() setDefaultState( getDefaultState()
.with( FACING, EnumFacing.NORTH ) .with( FACING, Direction.NORTH )
.with( STATE, ComputerState.OFF ) .with( STATE, ComputerState.OFF )
); );
} }
@Override @Override
protected void fillStateContainer( StateContainer.Builder<Block, IBlockState> builder ) protected void fillStateContainer( StateContainer.Builder<Block, BlockState> builder )
{ {
builder.add( FACING, STATE ); builder.add( FACING, STATE );
} }
@Nullable @Nullable
@Override @Override
public IBlockState getStateForPlacement( BlockItemUseContext placement ) public BlockState getStateForPlacement( BlockItemUseContext placement )
{ {
return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() ); return getDefaultState().with( FACING, placement.getPlacementHorizontalFacing().getOpposite() );
} }

View File

@ -12,15 +12,14 @@ import dan200.computercraft.shared.common.IBundledRedstoneBlock;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.computer.items.IComputerItem;
import net.minecraft.block.state.IBlockState; import dan200.computercraft.shared.util.NamedTileEntityType;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.IFluidState; import net.minecraft.fluid.IFluidState;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.util.Direction;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
@ -32,7 +31,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
{ {
private final ComputerFamily family; private final ComputerFamily family;
protected BlockComputerBase( Properties settings, ComputerFamily family, TileEntityType<? extends T> type ) protected BlockComputerBase( Properties settings, ComputerFamily family, NamedTileEntityType<? extends T> type )
{ {
super( settings, type ); super( settings, type );
this.family = family; this.family = family;
@ -40,9 +39,9 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
@Override @Override
@Deprecated @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 ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileComputerBase ) ((TileComputerBase) tile).updateInput(); if( tile instanceof TileComputerBase ) ((TileComputerBase) tile).updateInput();
@ -50,14 +49,14 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
@Override @Override
@Deprecated @Deprecated
public boolean canProvidePower( IBlockState state ) public boolean canProvidePower( BlockState state )
{ {
return true; return true;
} }
@Override @Override
@Deprecated @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 ); TileEntity entity = world.getTileEntity( pos );
if( !(entity instanceof TileComputerBase) ) return 0; if( !(entity instanceof TileComputerBase) ) return 0;
@ -80,19 +79,19 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
@Override @Override
@Deprecated @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 ); return getStrongPower( state, world, pos, incomingSide );
} }
@Override @Override
public boolean getBundledRedstoneConnectivity( World world, BlockPos pos, EnumFacing side ) public boolean getBundledRedstoneConnectivity( World world, BlockPos pos, Direction side )
{ {
return true; return true;
} }
@Override @Override
public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ) public int getBundledRedstoneOutput( World world, BlockPos pos, Direction side )
{ {
TileEntity entity = world.getTileEntity( pos ); TileEntity entity = world.getTileEntity( pos );
if( !(entity instanceof TileComputerBase) ) return 0; if( !(entity instanceof TileComputerBase) ) return 0;
@ -107,7 +106,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
@Nonnull @Nonnull
@Override @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 ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileComputerBase ) if( tile instanceof TileComputerBase )
@ -119,14 +118,15 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
return super.getPickBlock( state, target, world, pos, player ); return super.getPickBlock( state, target, world, pos, player );
} }
/* TODO: THIS!!
@Override @Override
@Deprecated @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 @Override
public final void getDrops( IBlockState state, NonNullList<ItemStack> drops, World world, BlockPos pos, int fortune ) public final void getDrops( BlockState state, NonNullList<ItemStack> drops, World world, BlockPos pos, int fortune )
{ {
TileEntity tile = world.getTileEntity( pos ); TileEntity tile = world.getTileEntity( pos );
if( tile instanceof TileComputerBase ) if( tile instanceof TileComputerBase )
@ -135,9 +135,10 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
if( !stack.isEmpty() ) drops.add( stack ); if( !stack.isEmpty() ) drops.add( stack );
} }
} }
*/
@Override @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 ) if( !world.isRemote )
{ {
@ -147,7 +148,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
if( tile instanceof TileComputerBase ) if( tile instanceof TileComputerBase )
{ {
TileComputerBase computer = (TileComputerBase) tile; TileComputerBase computer = (TileComputerBase) tile;
if( !player.abilities.isCreativeMode || computer.getLabel() != null ) if( !player.playerAbilities.isCreativeMode || computer.getLabel() != null )
{ {
spawnAsEntity( world, pos, getItem( computer ) ); spawnAsEntity( world, pos, getItem( computer ) );
} }
@ -158,7 +159,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
} }
@Override @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 ); super.onBlockPlacedBy( world, pos, state, placer, stack );

View File

@ -10,19 +10,19 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.apis.CommandAPI; import dan200.computercraft.shared.computer.apis.CommandAPI;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.util.NamedBlockEntityType; import dan200.computercraft.shared.util.NamedTileEntityType;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.command.ICommandSource; 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.server.MinecraftServer;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec2f; import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.WorldServer; import net.minecraft.world.ServerWorld;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.HashMap; import java.util.HashMap;
@ -30,7 +30,7 @@ import java.util.Map;
public class TileCommandComputer extends TileComputer public class TileCommandComputer extends TileComputer
{ {
public static final NamedBlockEntityType<TileCommandComputer> FACTORY = NamedBlockEntityType.create( public static final NamedTileEntityType<TileCommandComputer> FACTORY = NamedTileEntityType.create(
new ResourceLocation( ComputerCraft.MOD_ID, "command_computer" ), new ResourceLocation( ComputerCraft.MOD_ID, "command_computer" ),
f -> new TileCommandComputer( ComputerFamily.Command, f ) f -> new TileCommandComputer( ComputerFamily.Command, f )
); );
@ -104,8 +104,8 @@ public class TileCommandComputer extends TileComputer
return new CommandSource( receiver, return new CommandSource( receiver,
new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ), Vec2f.ZERO, new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ), Vec2f.ZERO,
(WorldServer) getWorld(), 2, (ServerWorld) getWorld(), 2,
name, new TextComponentString( name ), name, new StringTextComponent( name ),
getWorld().getServer(), null getWorld().getServer(), null
); );
} }
@ -119,17 +119,17 @@ public class TileCommandComputer extends TileComputer
} }
@Override @Override
public boolean isUsable( EntityPlayer player, boolean ignoreRange ) public boolean isUsable( PlayerEntity player, boolean ignoreRange )
{ {
MinecraftServer server = player.getServer(); MinecraftServer server = player.getServer();
if( server == null || !server.isCommandBlockEnabled() ) if( server == null || !server.isCommandBlockEnabled() )
{ {
player.sendStatusMessage( new TextComponentTranslation( "advMode.notEnabled" ), true ); player.sendStatusMessage( new TranslationTextComponent( "advMode.notEnabled" ), true );
return false; return false;
} }
else if( !player.canUseCommandBlock() ) else if( !player.canUseCommandBlock() )
{ {
player.sendStatusMessage( new TextComponentTranslation( "advMode.notAllowed" ), true ); player.sendStatusMessage( new TranslationTextComponent( "advMode.notAllowed" ), true );
return false; return false;
} }
else else

View File

@ -11,22 +11,21 @@ import dan200.computercraft.core.computer.ComputerSide;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.network.Containers; import dan200.computercraft.shared.util.NamedTileEntityType;
import dan200.computercraft.shared.util.NamedBlockEntityType; import net.minecraft.block.BlockState;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class TileComputer extends TileComputerBase public class TileComputer extends TileComputerBase
{ {
public static final NamedBlockEntityType<TileComputer> FACTORY_NORMAL = NamedBlockEntityType.create( public static final NamedTileEntityType<TileComputer> FACTORY_NORMAL = NamedTileEntityType.create(
new ResourceLocation( ComputerCraft.MOD_ID, "computer_normal" ), new ResourceLocation( ComputerCraft.MOD_ID, "computer_normal" ),
f -> new TileComputer( ComputerFamily.Normal, f ) f -> new TileComputer( ComputerFamily.Normal, f )
); );
public static final NamedBlockEntityType<TileComputer> FACTORY_ADVANCED = NamedBlockEntityType.create( public static final NamedTileEntityType<TileComputer> FACTORY_ADVANCED = NamedTileEntityType.create(
new ResourceLocation( ComputerCraft.MOD_ID, "computer_advanced" ), new ResourceLocation( ComputerCraft.MOD_ID, "computer_advanced" ),
f -> new TileComputer( ComputerFamily.Advanced, f ) f -> new TileComputer( ComputerFamily.Advanced, f )
); );
@ -69,18 +68,18 @@ public class TileComputer extends TileComputerBase
} }
@Override @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 ); return isUsable( player, false );
} }
@Override @Override
public EnumFacing getDirection() public Direction getDirection()
{ {
return getBlockState().get( BlockComputer.FACING ); return getBlockState().get( BlockComputer.FACING );
} }
@ -88,7 +87,7 @@ public class TileComputer extends TileComputerBase
@Override @Override
protected void updateBlockState( ComputerState newState ) protected void updateBlockState( ComputerState newState )
{ {
IBlockState existing = getBlockState(); BlockState existing = getBlockState();
if( existing.get( BlockComputer.STATE ) != newState ) if( existing.get( BlockComputer.STATE ) != newState )
{ {
getWorld().setBlockState( getPos(), existing.with( BlockComputer.STATE, newState ), 3 ); getWorld().setBlockState( getPos(), existing.with( BlockComputer.STATE, newState ), 3 );

View File

@ -20,28 +20,30 @@ import dan200.computercraft.shared.computer.core.ServerComputer;
import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.DirectionUtil;
import dan200.computercraft.shared.util.RedstoneUtil; import dan200.computercraft.shared.util.RedstoneUtil;
import joptsimple.internal.Strings; import joptsimple.internal.Strings;
import net.minecraft.block.BlockRedstoneWire; import net.minecraft.block.BlockState;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.Blocks;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.block.RedstoneDiodeBlock;
import net.minecraft.init.Blocks; import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.init.Items; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; 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.tileentity.TileEntityType;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.INameable; import net.minecraft.util.INameable;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Objects; import java.util.Objects;
public abstract class TileComputerBase extends TileGeneric implements IComputerTile, 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_ID = "ComputerId";
private static final String NBT_LABEL = "Label"; private static final String NBT_LABEL = "Label";
@ -76,7 +78,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
public void destroy() public void destroy()
{ {
unload(); unload();
for( EnumFacing dir : DirectionUtil.FACINGS ) for( Direction dir : DirectionUtil.FACINGS )
{ {
RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir );
} }
@ -95,15 +97,15 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
super.remove(); 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; return false;
} }
@Override @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 ); ItemStack currentItem = player.getHeldItem( hand );
if( !currentItem.isEmpty() && currentItem.getItem() == Items.NAME_TAG && canNameWithTag( player ) && currentItem.hasDisplayName() ) 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 @Nonnull
@Override @Override
public NBTTagCompound write( NBTTagCompound nbt ) public CompoundNBT write( CompoundNBT nbt )
{ {
// Save ID, label and power state // Save ID, label and power state
if( m_computerID >= 0 ) nbt.putInt( NBT_ID, m_computerID ); if( m_computerID >= 0 ) nbt.putInt( NBT_ID, m_computerID );
@ -193,7 +195,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
@Override @Override
public void read( NBTTagCompound nbt ) public void read( CompoundNBT nbt )
{ {
super.read( nbt ); super.read( nbt );
@ -208,9 +210,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
return false; 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 ) ); return remapLocalSide( DirectionUtil.toLocal( getDirection(), globalSide ) );
} }
@ -220,9 +222,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
return localSide; 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 ); ComputerSide localDir = remapToLocalSide( dir );
computer.setRedstoneInput( localDir, getRedstoneInput( world, offset, 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 pos The position of the neighbour
* @param side The side we are reading from * @param side The side we are reading from
* @return The effective redstone power * @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 ); int power = world.getRedstonePower( pos, side );
if( power >= 15 ) return power; if( power >= 15 ) return power;
IBlockState neighbour = world.getBlockState( pos ); BlockState neighbour = world.getBlockState( pos );
return neighbour.getBlock() == Blocks.REDSTONE_WIRE return neighbour.getBlock() == Blocks.REDSTONE_WIRE
? Math.max( power, neighbour.get( BlockRedstoneWire.POWER ) ) ? Math.max( power, neighbour.get( RedstoneWireBlock.POWER ) )
: power; : power;
} }
@ -262,7 +264,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
if( computer == null ) return; if( computer == null ) return;
BlockPos pos = computer.getPosition(); BlockPos pos = computer.getPosition();
for( EnumFacing dir : DirectionUtil.FACINGS ) for( Direction dir : DirectionUtil.FACINGS )
{ {
updateSideInput( computer, dir, pos.offset( dir ) ); updateSideInput( computer, dir, pos.offset( dir ) );
} }
@ -276,7 +278,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
if( computer == null ) return; if( computer == null ) return;
BlockPos pos = computer.getPosition(); BlockPos pos = computer.getPosition();
for( EnumFacing dir : DirectionUtil.FACINGS ) for( Direction dir : DirectionUtil.FACINGS )
{ {
BlockPos offset = pos.offset( dir ); BlockPos offset = pos.offset( dir );
if( offset.equals( neighbour ) ) if( offset.equals( neighbour ) )
@ -294,7 +296,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
{ {
// Update redstone // Update redstone
updateBlock(); updateBlock();
for( EnumFacing dir : DirectionUtil.FACINGS ) for( Direction dir : DirectionUtil.FACINGS )
{ {
RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir ); RedstoneUtil.propagateRedstoneOutput( getWorld(), getPos(), dir );
} }
@ -394,7 +396,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
// Networking stuff // Networking stuff
@Override @Override
protected void writeDescription( @Nonnull NBTTagCompound nbt ) protected void writeDescription( @Nonnull CompoundNBT nbt )
{ {
super.writeDescription( nbt ); super.writeDescription( nbt );
@ -404,7 +406,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
} }
@Override @Override
protected void readDescription( @Nonnull NBTTagCompound nbt ) protected void readDescription( @Nonnull CompoundNBT nbt )
{ {
super.readDescription( nbt ); super.readDescription( nbt );
m_instanceID = nbt.contains( NBT_INSTANCE ) ? nbt.getInt( NBT_INSTANCE ) : -1; m_instanceID = nbt.contains( NBT_INSTANCE ) ? nbt.getInt( NBT_INSTANCE ) : -1;
@ -429,7 +431,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Nullable @Nullable
@Override @Override
public IPeripheral getPeripheral( @Nonnull EnumFacing side ) public IPeripheral getPeripheral( @Nonnull Direction side )
{ {
return new ComputerPeripheral( "computer", createProxy() ); return new ComputerPeripheral( "computer", createProxy() );
} }
@ -438,7 +440,7 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override @Override
public ITextComponent getName() public ITextComponent getName()
{ {
return hasCustomName() ? new TextComponentString( m_label ) : getBlockState().getBlock().getNameTextComponent(); return hasCustomName() ? new StringTextComponent( m_label ) : getBlockState().getBlock().getNameTextComponent();
} }
@Override @Override
@ -451,6 +453,6 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
@Override @Override
public ITextComponent getCustomName() public ITextComponent getCustomName()
{ {
return hasCustomName() ? new TextComponentString( m_label ) : null; return hasCustomName() ? new StringTextComponent( m_label ) : null;
} }
} }

View File

@ -10,7 +10,7 @@ import com.google.common.base.Objects;
import dan200.computercraft.shared.common.ClientTerminal; import dan200.computercraft.shared.common.ClientTerminal;
import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.network.server.*; import dan200.computercraft.shared.network.server.*;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
public class ClientComputer extends ClientTerminal implements IComputer 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_on = false;
private boolean m_blinking = false; private boolean m_blinking = false;
private boolean m_changed = true; private boolean m_changed = true;
private NBTTagCompound m_userData = null; private CompoundNBT m_userData = null;
private boolean m_changedLastFrame = false; private boolean m_changedLastFrame = false;
@ -40,7 +40,7 @@ public class ClientComputer extends ClientTerminal implements IComputer
return m_changedLastFrame; return m_changedLastFrame;
} }
public NBTTagCompound getUserData() public CompoundNBT getUserData()
{ {
return m_userData; 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 ) ); 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 oldOn = m_on;
boolean oldBlinking = m_blinking; boolean oldBlinking = m_blinking;
NBTTagCompound oldUserData = m_userData; CompoundNBT oldUserData = m_userData;
m_on = state != ComputerState.OFF; m_on = state != ComputerState.OFF;
m_blinking = state == ComputerState.BLINKING; m_blinking = state == ComputerState.BLINKING;

View File

@ -6,11 +6,13 @@
package dan200.computercraft.shared.computer.core; package dan200.computercraft.shared.computer.core;
import net.minecraft.inventory.container.Container;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; 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. * if you provide custom computers/GUIs to interact with them.
*/ */
@FunctionalInterface @FunctionalInterface

View File

@ -22,9 +22,9 @@ import dan200.computercraft.shared.network.NetworkMessage;
import dan200.computercraft.shared.network.client.ComputerDataClientMessage; import dan200.computercraft.shared.network.client.ComputerDataClientMessage;
import dan200.computercraft.shared.network.client.ComputerDeletedClientMessage; import dan200.computercraft.shared.network.client.ComputerDeletedClientMessage;
import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage; import dan200.computercraft.shared.network.client.ComputerTerminalClientMessage;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -43,7 +43,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
private final ComputerFamily m_family; private final ComputerFamily m_family;
private final Computer m_computer; private final Computer m_computer;
private NBTTagCompound m_userData; private CompoundNBT m_userData;
private boolean m_changed; private boolean m_changed;
private boolean m_changedLastFrame; private boolean m_changedLastFrame;
@ -134,11 +134,11 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
m_computer.unload(); m_computer.unload();
} }
public NBTTagCompound getUserData() public CompoundNBT getUserData()
{ {
if( m_userData == null ) if( m_userData == null )
{ {
m_userData = new NBTTagCompound(); m_userData = new CompoundNBT();
} }
return m_userData; return m_userData;
} }
@ -155,7 +155,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
protected NetworkMessage createTerminalPacket() protected NetworkMessage createTerminalPacket()
{ {
NBTTagCompound tagCompound = new NBTTagCompound(); CompoundNBT tagCompound = new CompoundNBT();
writeDescription( tagCompound ); writeDescription( tagCompound );
return new ComputerTerminalClientMessage( getInstanceID(), tagCompound ); return new ComputerTerminalClientMessage( getInstanceID(), tagCompound );
} }
@ -174,7 +174,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
NetworkMessage packet = null; NetworkMessage packet = null;
for( EntityPlayer player : server.getPlayerList().getPlayers() ) for( PlayerEntity player : server.getPlayerList().getPlayers() )
{ {
if( isInteracting( player ) ) 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 // Send state to client
NetworkHandler.sendToPlayer( player, createComputerPacket() ); NetworkHandler.sendToPlayer( player, createComputerPacket() );
} }
public void sendTerminalState( EntityPlayer player ) public void sendTerminalState( PlayerEntity player )
{ {
// Send terminal state to client // Send terminal state to client
NetworkHandler.sendToPlayer( player, createTerminalPacket() ); NetworkHandler.sendToPlayer( player, createTerminalPacket() );
@ -357,7 +357,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
} }
@Nullable @Nullable
public IContainerComputer getContainer( EntityPlayer player ) public IContainerComputer getContainer( PlayerEntity player )
{ {
if( player == null ) return null; if( player == null ) return null;
@ -368,7 +368,7 @@ public class ServerComputer extends ServerTerminal implements IComputer, IComput
return computerContainer.getComputer() != this ? null : computerContainer; return computerContainer.getComputer() != this ? null : computerContainer;
} }
protected boolean isInteracting( EntityPlayer player ) protected boolean isInteracting( PlayerEntity player )
{ {
return getContainer( player ) != null; return getContainer( player ) != null;
} }

View File

@ -10,8 +10,8 @@ import dan200.computercraft.shared.computer.blocks.TileComputer;
import dan200.computercraft.shared.computer.core.IComputer; import dan200.computercraft.shared.computer.core.IComputer;
import dan200.computercraft.shared.computer.core.IContainerComputer; import dan200.computercraft.shared.computer.core.IContainerComputer;
import dan200.computercraft.shared.computer.core.InputState; import dan200.computercraft.shared.computer.core.InputState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Container; import net.minecraft.inventory.container.Container;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -21,13 +21,14 @@ public class ContainerComputer extends Container implements IContainerComputer
private final TileComputer computer; private final TileComputer computer;
private final InputState input = new InputState( this ); private final InputState input = new InputState( this );
public ContainerComputer( TileComputer computer ) public ContainerComputer( int id, TileComputer computer )
{ {
super( null, id );
this.computer = computer; this.computer = computer;
} }
@Override @Override
public boolean canInteractWith( @Nonnull EntityPlayer player ) public boolean canInteractWith( @Nonnull PlayerEntity player )
{ {
return computer.isUsableByPlayer( player ); return computer.isUsableByPlayer( player );
} }
@ -47,7 +48,7 @@ public class ContainerComputer extends Container implements IContainerComputer
} }
@Override @Override
public void onContainerClosed( EntityPlayer player ) public void onContainerClosed( PlayerEntity player )
{ {
super.onContainerClosed( player ); super.onContainerClosed( player );
input.close(); input.close();

View File

@ -8,21 +8,27 @@ package dan200.computercraft.shared.computer.inventory;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.*; import dan200.computercraft.shared.computer.core.*;
import net.minecraft.entity.player.EntityPlayer; import dan200.computercraft.shared.network.container.ContainerData;
import net.minecraft.inventory.Container; 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.server.MinecraftServer;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TranslationTextComponent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ContainerViewComputer extends Container implements IContainerComputer public class ContainerViewComputer extends Container implements IContainerComputer
{ {
public static final ContainerType<ContainerViewComputer> TYPE = ContainerData.create( ViewComputerContainerData::new );
private final IComputer computer; private final IComputer computer;
private final InputState input = new InputState( this ); private final InputState input = new InputState( this );
public ContainerViewComputer( IComputer computer ) public ContainerViewComputer( int id, IComputer computer )
{ {
super( TYPE, id );
this.computer = computer; this.computer = computer;
} }
@ -34,7 +40,7 @@ public class ContainerViewComputer extends Container implements IContainerComput
} }
@Override @Override
public boolean canInteractWith( @Nonnull EntityPlayer player ) public boolean canInteractWith( @Nonnull PlayerEntity player )
{ {
if( computer instanceof ServerComputer ) if( computer instanceof ServerComputer )
{ {
@ -52,18 +58,18 @@ public class ContainerViewComputer extends Container implements IContainerComput
MinecraftServer server = player.getServer(); MinecraftServer server = player.getServer();
if( server == null || !server.isCommandBlockEnabled() ) if( server == null || !server.isCommandBlockEnabled() )
{ {
player.sendStatusMessage( new TextComponentTranslation( "advMode.notEnabled" ), false ); player.sendStatusMessage( new TranslationTextComponent( "advMode.notEnabled" ), false );
return false; return false;
} }
else if( !player.canUseCommandBlock() ) else if( !player.canUseCommandBlock() )
{ {
player.sendStatusMessage( new TextComponentTranslation( "advMode.notAllowed" ), false ); player.sendStatusMessage( new TranslationTextComponent( "advMode.notAllowed" ), false );
return false; return false;
} }
} }
} }
return true; return computer != null;
} }
@Nonnull @Nonnull
@ -74,7 +80,7 @@ public class ContainerViewComputer extends Container implements IContainerComput
} }
@Override @Override
public void onContainerClosed( EntityPlayer player ) public void onContainerClosed( PlayerEntity player )
{ {
super.onContainerClosed( player ); super.onContainerClosed( player );
input.close(); input.close();

View File

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

View File

@ -9,7 +9,7 @@ package dan200.computercraft.shared.computer.items;
import dan200.computercraft.shared.computer.blocks.BlockComputer; import dan200.computercraft.shared.computer.blocks.BlockComputer;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -24,7 +24,7 @@ public class ItemComputer extends ItemComputerBase
{ {
ItemStack result = new ItemStack( this ); ItemStack result = new ItemStack( this );
if( id >= 0 ) result.getOrCreateTag().putInt( NBT_ID, id ); 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; return result;
} }

View File

@ -13,19 +13,19 @@ import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.computer.blocks.BlockComputerBase; import dan200.computercraft.shared.computer.blocks.BlockComputerBase;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemBlock; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; 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; private final ComputerFamily family;
@ -43,7 +43,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte
int id = getComputerID( stack ); int id = getComputerID( stack );
if( id >= 0 ) 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 ) ); .applyTextStyle( TextFormatting.GRAY ) );
} }
} }
@ -68,7 +68,7 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte
{ {
if( label != null ) if( label != null )
{ {
stack.setDisplayName( new TextComponentString( label ) ); stack.setDisplayName( new StringTextComponent( label ) );
} }
else else
{ {

View File

@ -7,7 +7,7 @@
package dan200.computercraft.shared.computer.recipe; package dan200.computercraft.shared.computer.recipe;
import dan200.computercraft.shared.computer.items.IComputerItem; 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.ItemStack;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.item.crafting.ShapedRecipe; 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 ); protected abstract ItemStack convert( @Nonnull IComputerItem item, @Nonnull ItemStack stack );
@Override @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; if( !super.matches( inventory, world ) ) return false;
@ -48,7 +48,7 @@ public abstract class ComputerConvertRecipe extends ShapedRecipe
@Nonnull @Nonnull
@Override @Override
public ItemStack getCraftingResult( @Nonnull IInventory inventory ) public ItemStack getCraftingResult( @Nonnull CraftingInventory inventory )
{ {
// Find our computer item and convert it. // Find our computer item and convert it.
for( int i = 0; i < inventory.getSizeInventory(); i++ ) for( int i = 0; i < inventory.getSizeInventory(); i++ )

View File

@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.Ingredient;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.JsonUtils; import net.minecraft.util.JSONUtils;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -42,11 +42,11 @@ public abstract class ComputerFamilyRecipe extends ComputerConvertRecipe
@Override @Override
public T read( @Nonnull ResourceLocation identifier, @Nonnull JsonObject json ) 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" ); ComputerFamily family = RecipeUtil.getFamily( json, "family" );
RecipeUtil.ShapedTemplate template = RecipeUtil.getTemplate( json ); 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 ); return create( identifier, group, template.width, template.height, template.ingredients, result, family );
} }

View File

@ -6,7 +6,6 @@
package dan200.computercraft.shared.computer.recipe; package dan200.computercraft.shared.computer.recipe;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.computer.items.IComputerItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -38,7 +37,6 @@ public class ComputerUpgradeRecipe extends ComputerFamilyRecipe
return SERIALIZER; return SERIALIZER;
} }
private static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "computer_upgrade" );
public static final IRecipeSerializer<ComputerUpgradeRecipe> SERIALIZER = new Serializer<ComputerUpgradeRecipe>() public static final IRecipeSerializer<ComputerUpgradeRecipe> SERIALIZER = new Serializer<ComputerUpgradeRecipe>()
{ {
@Override @Override
@ -46,12 +44,5 @@ public class ComputerUpgradeRecipe extends ComputerFamilyRecipe
{ {
return new ComputerUpgradeRecipe( identifier, group, width, height, ingredients, result, family ); return new ComputerUpgradeRecipe( identifier, group, width, height, ingredients, result, family );
} }
@Nonnull
@Override
public ResourceLocation getName()
{
return ID;
}
}; };
} }

View File

@ -6,7 +6,7 @@
package dan200.computercraft.shared.integration.charset; package dan200.computercraft.shared.integration.charset;
import dan200.computercraft.shared.common.TileGeneric; 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.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import pl.asie.charset.api.wires.IBundledEmitter; import pl.asie.charset.api.wires.IBundledEmitter;
@ -30,14 +30,14 @@ final class BundledCapabilityProvider implements ICapabilityProvider
} }
@Override @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; return capability == CAPABILITY_EMITTER || capability == CAPABILITY_RECEIVER;
} }
@Nullable @Nullable
@Override @Override
public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable EnumFacing side ) public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable Direction side )
{ {
if( capability == CAPABILITY_RECEIVER ) if( capability == CAPABILITY_RECEIVER )
{ {
@ -62,7 +62,7 @@ final class BundledCapabilityProvider implements ICapabilityProvider
{ {
emitter = emitters[index] = () -> { emitter = emitters[index] = () -> {
int flags = 0; int flags = 0;
for( EnumFacing facing : EnumFacing.VALUES ) flags |= tile.getBundledRedstoneOutput( facing ); for( Direction facing : Direction.VALUES ) flags |= tile.getBundledRedstoneOutput( facing );
return toBytes( flags ); return toBytes( flags );
}; };
} }

View File

@ -7,7 +7,7 @@ package dan200.computercraft.shared.integration.charset;
import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
import net.minecraft.tileentity.TileEntity; 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.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -18,7 +18,7 @@ import static dan200.computercraft.shared.integration.charset.IntegrationCharset
public class BundledRedstoneProvider implements IBundledRedstoneProvider public class BundledRedstoneProvider implements IBundledRedstoneProvider
{ {
@Override @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 ); TileEntity tile = world.getTileEntity( pos );
if( tile == null || !tile.hasCapability( CAPABILITY_EMITTER, side ) ) return -1; if( tile == null || !tile.hasCapability( CAPABILITY_EMITTER, side ) ) return -1;

View File

@ -8,13 +8,11 @@ package dan200.computercraft.shared.integration.mcmp;
import mcmultipart.MCMultiPart; import mcmultipart.MCMultiPart;
import mcmultipart.api.item.ItemBlockMultipart; import mcmultipart.api.item.ItemBlockMultipart;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemBlock; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.common.Loader; 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( return ItemBlockMultipart.place(
player, world, pos, hand, facing, hitX, hitY, hitZ, itemBlock, player, world, pos, hand, facing, hitX, hitY, hitZ, itemBlock,
@ -37,8 +35,8 @@ public final class MCMPHooks
MCMPIntegration.multipartMap.get( itemBlock.getBlock() ), MCMPIntegration.multipartMap.get( itemBlock.getBlock() ),
( (
ItemStack stack, EntityPlayer thisPlayer, World thisWorld, BlockPos thisPos, EnumFacing thisFacing, ItemStack stack, PlayerEntity thisPlayer, World thisWorld, BlockPos thisPos, Direction thisFacing,
float thisX, float thisY, float thisZ, IBlockState thisState float thisX, float thisY, float thisZ, BlockState thisState
) -> ) ->
thisPlayer.canPlayerEdit( thisPos, thisFacing, stack ) && thisPlayer.canPlayerEdit( thisPos, thisFacing, stack ) &&
thisWorld.getBlockState( thisPos ).getBlock().isReplaceable( thisWorld, thisPos ) && thisWorld.getBlockState( thisPos ).getBlock().isReplaceable( thisWorld, thisPos ) &&

View File

@ -24,7 +24,7 @@ import mcmultipart.api.ref.MCMPCapabilities;
import mcmultipart.api.slot.EnumFaceSlot; import mcmultipart.api.slot.EnumFaceSlot;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
@ -105,14 +105,14 @@ public class MCMPIntegration implements IMCMPAddon
} }
@Override @Override
public boolean hasCapability( @Nonnull Capability<?> capability, @Nullable EnumFacing facing ) public boolean hasCapability( @Nonnull Capability<?> capability, @Nullable Direction facing )
{ {
return capability == MCMPCapabilities.MULTIPART_TILE; return capability == MCMPCapabilities.MULTIPART_TILE;
} }
@Nullable @Nullable
@Override @Override
public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable EnumFacing facing ) public <T> T getCapability( @Nonnull Capability<T> capability, @Nullable Direction facing )
{ {
if( capability == MCMPCapabilities.MULTIPART_TILE ) if( capability == MCMPCapabilities.MULTIPART_TILE )
{ {

View File

@ -12,9 +12,9 @@ import mcmultipart.api.multipart.IMultipart;
import mcmultipart.api.slot.EnumFaceSlot; import mcmultipart.api.slot.EnumFaceSlot;
import mcmultipart.api.slot.IPartSlot; import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.LivingEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -22,13 +22,13 @@ import net.minecraft.world.World;
public class PartAdvancedModem implements IMultipart public class PartAdvancedModem implements IMultipart
{ {
@Override @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 ) ); return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) );
} }
@Override @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 ) ); return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) );
} }

View File

@ -14,9 +14,9 @@ import mcmultipart.api.slot.EnumCenterSlot;
import mcmultipart.api.slot.EnumFaceSlot; import mcmultipart.api.slot.EnumFaceSlot;
import mcmultipart.api.slot.IPartSlot; import mcmultipart.api.slot.IPartSlot;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.LivingEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -26,19 +26,19 @@ import javax.annotation.Nonnull;
public class PartPeripheral implements IMultipart public class PartPeripheral implements IMultipart
{ {
@Override @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 ); return getSlot( state );
} }
@Override @Override
public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, IBlockState state ) public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, BlockState state )
{ {
return getSlot( state ); return getSlot( state );
} }
@Nonnull @Nonnull
private static IPartSlot getSlot( IBlockState state ) private static IPartSlot getSlot( BlockState state )
{ {
BlockPeripheralVariant type = state.getValue( BlockPeripheral.VARIANT ); BlockPeripheralVariant type = state.getValue( BlockPeripheral.VARIANT );
if( type == BlockPeripheralVariant.WirelessModemUpOn || type == BlockPeripheralVariant.WirelessModemUpOff ) if( type == BlockPeripheralVariant.WirelessModemUpOn || type == BlockPeripheralVariant.WirelessModemUpOff )

View File

@ -13,17 +13,17 @@ import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import net.minecraft.client.util.ITooltipFlag; 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.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IWorldReader; import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -68,14 +68,14 @@ public class ItemDisk extends Item implements IMedia, IColouredItem
int id = getDiskID( stack ); int id = getDiskID( stack );
if( id >= 0 ) 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 ) ); .applyTextStyle( TextFormatting.GRAY ) );
} }
} }
} }
@Override @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; return true;
} }
@ -91,7 +91,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem
{ {
if( label != null ) if( label != null )
{ {
stack.setDisplayName( new TextComponentString( label ) ); stack.setDisplayName( new StringTextComponent( label ) );
} }
else else
{ {
@ -114,7 +114,7 @@ public class ItemDisk extends Item implements IMedia, IColouredItem
public static int getDiskID( @Nonnull ItemStack stack ) 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; return nbt != null && nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
} }

View File

@ -7,17 +7,17 @@
package dan200.computercraft.shared.media.items; package dan200.computercraft.shared.media.items;
import dan200.computercraft.ComputerCraft; 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.client.util.ITooltipFlag;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.ActionResultType;
import net.minecraft.util.EnumHand; import net.minecraft.util.Hand;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -53,15 +53,15 @@ public class ItemPrintout extends Item
public void addInformation( @Nonnull ItemStack stack, World world, List<ITextComponent> list, ITooltipFlag options ) public void addInformation( @Nonnull ItemStack stack, World world, List<ITextComponent> list, ITooltipFlag options )
{ {
String title = getTitle( stack ); 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 @Nonnull
@Override @Override
public ActionResult<ItemStack> onItemRightClick( World world, EntityPlayer player, @Nonnull EnumHand hand ) public ActionResult<ItemStack> onItemRightClick( World world, PlayerEntity player, @Nonnull Hand hand )
{ {
if( !world.isRemote ) Containers.openPrintoutGUI( player, hand ); if( !world.isRemote ) new PrintoutContainerData( hand ).open( player );
return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) ); return new ActionResult<>( ActionResultType.SUCCESS, player.getHeldItem( hand ) );
} }
@Nonnull @Nonnull
@ -73,7 +73,7 @@ public class ItemPrintout extends Item
if( title != null ) stack.getOrCreateTag().putString( NBT_TITLE, title ); if( title != null ) stack.getOrCreateTag().putString( NBT_TITLE, title );
if( text != null ) if( text != null )
{ {
NBTTagCompound tag = stack.getOrCreateTag(); CompoundNBT tag = stack.getOrCreateTag();
tag.putInt( NBT_PAGES, text.length / LINES_PER_PAGE ); tag.putInt( NBT_PAGES, text.length / LINES_PER_PAGE );
for( int i = 0; i < text.length; i++ ) for( int i = 0; i < text.length; i++ )
{ {
@ -82,7 +82,7 @@ public class ItemPrintout extends Item
} }
if( colours != null ) if( colours != null )
{ {
NBTTagCompound tag = stack.getOrCreateTag(); CompoundNBT tag = stack.getOrCreateTag();
for( int i = 0; i < colours.length; i++ ) for( int i = 0; i < colours.length; i++ )
{ {
if( colours[i] != null ) tag.putString( NBT_LINE_COLOUR + i, colours[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 ) 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; return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : null;
} }
public static int getPageCount( @Nonnull ItemStack stack ) 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; 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 ) private static String[] getLines( @Nonnull ItemStack stack, String prefix )
{ {
NBTTagCompound nbt = stack.getTag(); CompoundNBT nbt = stack.getTag();
int numLines = getPageCount( stack ) * LINES_PER_PAGE; int numLines = getPageCount( stack ) * LINES_PER_PAGE;
String[] lines = new String[numLines]; String[] lines = new String[numLines];
for( int i = 0; i < lines.length; i++ ) for( int i = 0; i < lines.length; i++ )

View File

@ -13,15 +13,15 @@ import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.core.filesystem.SubMount; import dan200.computercraft.core.filesystem.SubMount;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import net.minecraft.client.util.ITooltipFlag; 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.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; 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.IWorldReader;
import net.minecraft.world.World; 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<ITextComponent> list, ITooltipFlag tooltipOptions ) public void addInformation( ItemStack stack, @Nullable World world, List<ITextComponent> list, ITooltipFlag tooltipOptions )
{ {
String label = getTitle( stack ); String label = getTitle( stack );
if( !label.isEmpty() ) list.add( new TextComponentString( label ) ); if( !label.isEmpty() ) list.add( new StringTextComponent( label ) );
} }
@Override @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; return true;
} }
@ -94,7 +94,7 @@ public class ItemTreasureDisk extends Item implements IMedia
public static ItemStack create( String subPath, int colourIndex ) public static ItemStack create( String subPath, int colourIndex )
{ {
ItemStack result = new ItemStack( ComputerCraft.Items.treasureDisk ); ItemStack result = new ItemStack( ComputerCraft.Items.treasureDisk );
NBTTagCompound nbt = result.getOrCreateTag(); CompoundNBT nbt = result.getOrCreateTag();
nbt.putString( NBT_SUB_PATH, subPath ); nbt.putString( NBT_SUB_PATH, subPath );
int slash = subPath.indexOf( '/' ); int slash = subPath.indexOf( '/' );
@ -121,20 +121,20 @@ public class ItemTreasureDisk extends Item implements IMedia
@Nonnull @Nonnull
private static String getTitle( @Nonnull ItemStack stack ) 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"; return nbt != null && nbt.contains( NBT_TITLE ) ? nbt.getString( NBT_TITLE ) : "'alongtimeago' by dan200";
} }
@Nonnull @Nonnull
private static String getSubPath( @Nonnull ItemStack stack ) 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"; return nbt != null && nbt.contains( NBT_SUB_PATH ) ? nbt.getString( NBT_SUB_PATH ) : "dan200/alongtimeago";
} }
public static int getColour( @Nonnull ItemStack stack ) 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(); return nbt != null && nbt.contains( NBT_COLOUR ) ? nbt.getInt( NBT_COLOUR ) : Colour.Blue.getHex();
} }
} }

View File

@ -8,8 +8,8 @@ package dan200.computercraft.shared.media.items;
import dan200.computercraft.api.media.IMedia; import dan200.computercraft.api.media.IMedia;
import dan200.computercraft.shared.util.RecordUtil; import dan200.computercraft.shared.util.RecordUtil;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.MusicDiscItem;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -40,6 +40,6 @@ public final class RecordMedia implements IMedia
@Override @Override
public SoundEvent getAudio( @Nonnull ItemStack stack ) public SoundEvent getAudio( @Nonnull ItemStack stack )
{ {
return ((ItemRecord) stack.getItem()).getSound(); return ((MusicDiscItem) stack.getItem()).getSound();
} }
} }

View File

@ -6,26 +6,25 @@
package dan200.computercraft.shared.media.recipes; package dan200.computercraft.shared.media.recipes;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.media.items.ItemDisk; import dan200.computercraft.shared.media.items.ItemDisk;
import dan200.computercraft.shared.util.AbstractRecipe;
import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.Colour;
import dan200.computercraft.shared.util.ColourTracker; import dan200.computercraft.shared.util.ColourTracker;
import dan200.computercraft.shared.util.ColourUtils; import dan200.computercraft.shared.util.ColourUtils;
import net.minecraft.init.Items; import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.IInventory; import net.minecraft.item.DyeColor;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.Ingredient; 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.util.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.Tags; import net.minecraftforge.common.Tags;
import javax.annotation.Nonnull; 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 paper = Ingredient.fromItems( Items.PAPER );
private final Ingredient redstone = Ingredient.fromTag( Tags.Items.DUSTS_REDSTONE ); private final Ingredient redstone = Ingredient.fromTag( Tags.Items.DUSTS_REDSTONE );
@ -36,7 +35,7 @@ public class DiskRecipe extends AbstractRecipe
} }
@Override @Override
public boolean matches( @Nonnull IInventory inv, @Nonnull World world ) public boolean matches( @Nonnull CraftingInventory inv, @Nonnull World world )
{ {
boolean paperFound = false; boolean paperFound = false;
boolean redstoneFound = false; boolean redstoneFound = false;
@ -69,7 +68,7 @@ public class DiskRecipe extends AbstractRecipe
@Nonnull @Nonnull
@Override @Override
public ItemStack getCraftingResult( @Nonnull IInventory inv ) public ItemStack getCraftingResult( @Nonnull CraftingInventory inv )
{ {
ColourTracker tracker = new ColourTracker(); ColourTracker tracker = new ColourTracker();
@ -81,7 +80,7 @@ public class DiskRecipe extends AbstractRecipe
if( !paper.test( stack ) && !redstone.test( stack ) ) if( !paper.test( stack ) && !redstone.test( stack ) )
{ {
EnumDyeColor dye = ColourUtils.getStackColour( stack ); DyeColor dye = ColourUtils.getStackColour( stack );
if( dye == null ) continue; if( dye == null ) continue;
Colour colour = Colour.VALUES[dye.getId()]; Colour colour = Colour.VALUES[dye.getId()];
@ -112,7 +111,5 @@ public class DiskRecipe extends AbstractRecipe
return SERIALIZER; return SERIALIZER;
} }
public static final IRecipeSerializer<DiskRecipe> SERIALIZER = new RecipeSerializers.SimpleSerializer<>( public static final IRecipeSerializer<DiskRecipe> SERIALIZER = new SpecialRecipeSerializer<>( DiskRecipe::new );
ComputerCraft.MOD_ID + ":disk", DiskRecipe::new
);
} }

View File

@ -6,24 +6,23 @@
package dan200.computercraft.shared.media.recipes; package dan200.computercraft.shared.media.recipes;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.media.items.ItemPrintout; import dan200.computercraft.shared.media.items.ItemPrintout;
import dan200.computercraft.shared.util.AbstractRecipe; import net.minecraft.inventory.CraftingInventory;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.Ingredient; 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.util.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; 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 paper = Ingredient.fromItems( net.minecraft.item.Items.PAPER );
private final Ingredient leather = Ingredient.fromItems( Items.LEATHER ); private final Ingredient leather = Ingredient.fromItems( net.minecraft.item.Items.LEATHER );
private final Ingredient string = Ingredient.fromItems( Items.STRING ); private final Ingredient string = Ingredient.fromItems( Items.STRING );
private PrintoutRecipe( ResourceLocation id ) private PrintoutRecipe( ResourceLocation id )
@ -45,14 +44,14 @@ public final class PrintoutRecipe extends AbstractRecipe
} }
@Override @Override
public boolean matches( @Nonnull IInventory inventory, @Nonnull World world ) public boolean matches( @Nonnull CraftingInventory inventory, @Nonnull World world )
{ {
return !getCraftingResult( inventory ).isEmpty(); return !getCraftingResult( inventory ).isEmpty();
} }
@Nonnull @Nonnull
@Override @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 // See if we match the recipe, and extract the input disk ID and dye colour
int numPages = 0; int numPages = 0;
@ -165,7 +164,5 @@ public final class PrintoutRecipe extends AbstractRecipe
return SERIALIZER; return SERIALIZER;
} }
public static final IRecipeSerializer<?> SERIALIZER = new RecipeSerializers.SimpleSerializer<>( public static final IRecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>( PrintoutRecipe::new );
ComputerCraft.MOD_ID + ":printout", PrintoutRecipe::new
);
} }

View File

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

View File

@ -9,8 +9,8 @@ package dan200.computercraft.shared.network;
import dan200.computercraft.ComputerCraft; import dan200.computercraft.ComputerCraft;
import dan200.computercraft.shared.network.client.*; import dan200.computercraft.shared.network.client.*;
import dan200.computercraft.shared.network.server.*; import dan200.computercraft.shared.network.server.*;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -55,14 +55,14 @@ public final class NetworkHandler
registerMainThread( 14, PlayRecordClientMessage.class, PlayRecordClientMessage::new ); 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 ) public static void sendToAllPlayers( NetworkMessage packet )
{ {
for( EntityPlayerMP player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() ) for( ServerPlayerEntity player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() )
{ {
sendToPlayer( player, packet ); sendToPlayer( player, packet );
} }
@ -75,7 +75,7 @@ public final class NetworkHandler
public static void sendToAllAround( NetworkMessage packet, World world, Vec3d pos, double range ) 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; if( player.getEntityWorld() != world ) continue;

View File

@ -8,7 +8,7 @@ package dan200.computercraft.shared.network.client;
import dan200.computercraft.shared.computer.core.ComputerState; import dan200.computercraft.shared.computer.core.ComputerState;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@ -20,7 +20,7 @@ import javax.annotation.Nonnull;
public class ComputerDataClientMessage extends ComputerClientMessage public class ComputerDataClientMessage extends ComputerClientMessage
{ {
private ComputerState state; private ComputerState state;
private NBTTagCompound userData; private CompoundNBT userData;
public ComputerDataClientMessage( ServerComputer computer ) public ComputerDataClientMessage( ServerComputer computer )
{ {

View File

@ -6,7 +6,7 @@
package dan200.computercraft.shared.network.client; package dan200.computercraft.shared.network.client;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@ -14,9 +14,9 @@ import javax.annotation.Nonnull;
public class ComputerTerminalClientMessage extends ComputerClientMessage 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 ); super( instanceId );
this.tag = tag; this.tag = tag;

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