mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-09-01 01:57:55 +00:00
attempt to use mojmap
currently does not compile
This commit is contained in:
@@ -29,9 +29,9 @@ repositories {
|
||||
}
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath = file("src/main/resources/cc.accesswidener")
|
||||
}
|
||||
//loom {
|
||||
// accessWidenerPath = file("src/main/resources/cc.accesswidener")
|
||||
//}
|
||||
|
||||
configurations {
|
||||
implementation.extendsFrom shade
|
||||
@@ -41,7 +41,8 @@ dependencies {
|
||||
checkstyle 'com.puppycrawl.tools:checkstyle:8.45.1'
|
||||
|
||||
minecraft "com.mojang:minecraft:${mc_version}"
|
||||
mappings "net.fabricmc:yarn:${mc_version}+build.${mappings_version}:v2"
|
||||
//mappings "net.fabricmc:yarn:${mc_version}+build.${mappings_version}:v2"
|
||||
mappings(minecraft.officialMojangMappings())
|
||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
|
||||
|
||||
|
@@ -6,7 +6,7 @@ mod_version=1.97.2
|
||||
|
||||
# Minecraft properties
|
||||
mc_version=1.17.1
|
||||
mappings_version=61
|
||||
#mappings_version=61
|
||||
|
||||
# Dependencies
|
||||
cloth_config_version=5.0.34
|
||||
|
@@ -31,10 +31,10 @@ import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -111,30 +111,30 @@ public final class ComputerCraft implements ModInitializer
|
||||
// Logging
|
||||
public static final Logger log = LogManager.getLogger( MOD_ID );
|
||||
|
||||
public static ItemGroup MAIN_GROUP = FabricItemGroupBuilder.build( new Identifier( MOD_ID, "main" ), () -> new ItemStack( ModBlocks.COMPUTER_NORMAL ) );
|
||||
public static CreativeModeTab MAIN_GROUP = FabricItemGroupBuilder.build( new ResourceLocation( MOD_ID, "main" ), () -> new ItemStack( ModBlocks.COMPUTER_NORMAL ) );
|
||||
|
||||
@Override
|
||||
public void onInitialize()
|
||||
{
|
||||
ComputerCraftProxyCommon.init();
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "colour" ), ColourableRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "computer_upgrade" ), ComputerUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "colour" ), ColourableRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "computer_upgrade" ), ComputerUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER,
|
||||
new Identifier( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ),
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ),
|
||||
PocketComputerUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "disk" ), DiskRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "printout" ), PrintoutRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle" ), TurtleRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle_upgrade" ), TurtleUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shaped" ), ImpostorRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shapeless" ), ImpostorShapelessRecipe.SERIALIZER );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.TYPE );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "disk" ), DiskRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "printout" ), PrintoutRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ), TurtleRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "turtle_upgrade" ), TurtleUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shaped" ), ImpostorRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shapeless" ), ImpostorShapelessRecipe.SERIALIZER );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.TYPE );
|
||||
init();
|
||||
FabricLoader.getInstance().getModContainer( MOD_ID ).ifPresent( modContainer -> {
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "classic" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "overhaul" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new ResourceLocation( MOD_ID, "classic" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new ResourceLocation( MOD_ID, "overhaul" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
@@ -32,15 +32,14 @@ import dan200.computercraft.shared.util.IDAssigner;
|
||||
import dan200.computercraft.shared.wired.WiredNode;
|
||||
import me.shedaniel.cloth.api.utils.v1.GameInstanceUtils;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
@@ -65,7 +64,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).getServerResourceManager().getResourceManager();
|
||||
try
|
||||
{
|
||||
return manager.getResource( new Identifier( domain, subPath ) )
|
||||
return manager.getResource( new ResourceLocation( domain, subPath ) )
|
||||
.getInputStream();
|
||||
}
|
||||
catch( IOException ignored )
|
||||
@@ -93,13 +92,13 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||
public int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath )
|
||||
{
|
||||
return IDAssigner.getNextId( parentSubPath );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
||||
public IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -143,7 +142,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return BundledRedstone.getDefaultOutput( world, pos, side );
|
||||
}
|
||||
@@ -188,7 +187,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileCable )
|
||||
|
@@ -21,13 +21,12 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* The static entry point to the ComputerCraft API.
|
||||
@@ -81,9 +80,9 @@ public final class ComputerCraftAPI
|
||||
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
|
||||
*
|
||||
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.
|
||||
* @see #createSaveDirMount(World, String, long)
|
||||
* @see #createSaveDirMount(Level, String, long)
|
||||
*/
|
||||
public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||
public static int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath )
|
||||
{
|
||||
return getInstance().createUniqueNumberedSaveDir( world, parentSubPath );
|
||||
}
|
||||
@@ -100,14 +99,14 @@ public final class ComputerCraftAPI
|
||||
* @param capacity The amount of data that can be stored in the directory before it fills up, in bytes.
|
||||
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() to mount this on a
|
||||
* Computers' file system.
|
||||
* @see #createUniqueNumberedSaveDir(World, String)
|
||||
* @see #createUniqueNumberedSaveDir(Level, String)
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||
* @see IMount
|
||||
* @see IWritableMount
|
||||
*/
|
||||
@Nullable
|
||||
public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
||||
public static IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity )
|
||||
{
|
||||
return getInstance().createSaveDirMount( world, subPath, capacity );
|
||||
}
|
||||
@@ -192,7 +191,7 @@ public final class ComputerCraftAPI
|
||||
* capable of emitting bundled redstone at the location, -1 will be returned.
|
||||
* @see IBundledRedstoneProvider
|
||||
*/
|
||||
public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public static int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return getInstance().getBundledRedstoneOutput( world, pos, side );
|
||||
}
|
||||
@@ -251,7 +250,7 @@ public final class ComputerCraftAPI
|
||||
* @see IWiredElement#getNode()
|
||||
*/
|
||||
@Nullable
|
||||
public static IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public static IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return getInstance().getWiredElementAt( world, pos, side );
|
||||
}
|
||||
@@ -261,10 +260,10 @@ public final class ComputerCraftAPI
|
||||
@Nonnull
|
||||
String getInstalledVersion();
|
||||
|
||||
int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath );
|
||||
int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath );
|
||||
|
||||
@Nullable
|
||||
IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity );
|
||||
IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity );
|
||||
|
||||
@Nullable
|
||||
IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath );
|
||||
@@ -277,7 +276,7 @@ public final class ComputerCraftAPI
|
||||
|
||||
void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
|
||||
|
||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
|
||||
void registerMediaProvider( @Nonnull IMediaProvider provider );
|
||||
|
||||
@@ -292,6 +291,6 @@ public final class ComputerCraftAPI
|
||||
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
|
||||
|
||||
@Nullable
|
||||
IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,10 @@ package dan200.computercraft.api;
|
||||
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Common functionality between {@link ITurtleUpgrade} and {@link IPocketUpgrade}.
|
||||
@@ -28,7 +27,7 @@ public interface IUpgradeBase
|
||||
* @return The unique ID for this upgrade.
|
||||
*/
|
||||
@Nonnull
|
||||
Identifier getUpgradeID();
|
||||
ResourceLocation getUpgradeID();
|
||||
|
||||
/**
|
||||
* Return an unlocalised string to describe this type of computer in item names.
|
||||
@@ -76,8 +75,8 @@ public interface IUpgradeBase
|
||||
|
||||
// A more expanded form of ItemStack.areShareTagsEqual, but allowing an empty tag to be equal to a
|
||||
// null one.
|
||||
NbtCompound shareTag = stack.getNbt();
|
||||
NbtCompound craftingShareTag = crafting.getNbt();
|
||||
CompoundTag shareTag = stack.getTag();
|
||||
CompoundTag craftingShareTag = crafting.getTag();
|
||||
if( shareTag == craftingShareTag ) return true;
|
||||
if( shareTag == null ) return craftingShareTag.isEmpty();
|
||||
if( craftingShareTag == null ) return shareTag.isEmpty();
|
||||
|
@@ -8,16 +8,15 @@ package dan200.computercraft.api.client;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.BakedModelManager;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.util.math.AffineTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import javax.annotation.Nonnull;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -27,9 +26,9 @@ import java.util.Objects;
|
||||
public final class TransformedModel
|
||||
{
|
||||
private final BakedModel model;
|
||||
private final AffineTransformation matrix;
|
||||
private final Transformation matrix;
|
||||
|
||||
public TransformedModel( @Nonnull BakedModel model, @Nonnull AffineTransformation matrix )
|
||||
public TransformedModel( @Nonnull BakedModel model, @Nonnull Transformation matrix )
|
||||
{
|
||||
this.model = Objects.requireNonNull( model );
|
||||
this.matrix = Objects.requireNonNull( matrix );
|
||||
@@ -38,22 +37,22 @@ public final class TransformedModel
|
||||
public TransformedModel( @Nonnull BakedModel model )
|
||||
{
|
||||
this.model = Objects.requireNonNull( model );
|
||||
matrix = AffineTransformation.identity();
|
||||
matrix = Transformation.identity();
|
||||
}
|
||||
|
||||
public static TransformedModel of( @Nonnull ModelIdentifier location )
|
||||
public static TransformedModel of( @Nonnull ModelResourceLocation location )
|
||||
{
|
||||
BakedModelManager modelManager = MinecraftClient.getInstance()
|
||||
.getBakedModelManager();
|
||||
ModelManager modelManager = Minecraft.getInstance()
|
||||
.getModelManager();
|
||||
return new TransformedModel( modelManager.getModel( location ) );
|
||||
}
|
||||
|
||||
public static TransformedModel of( @Nonnull ItemStack item, @Nonnull AffineTransformation transform )
|
||||
public static TransformedModel of( @Nonnull ItemStack item, @Nonnull Transformation transform )
|
||||
{
|
||||
BakedModel model = MinecraftClient.getInstance()
|
||||
BakedModel model = Minecraft.getInstance()
|
||||
.getItemRenderer()
|
||||
.getModels()
|
||||
.getModel( item );
|
||||
.getItemModelShaper()
|
||||
.getItemModel( item );
|
||||
return new TransformedModel( model, transform );
|
||||
}
|
||||
|
||||
@@ -64,23 +63,23 @@ public final class TransformedModel
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public AffineTransformation getMatrix()
|
||||
public Transformation getMatrix()
|
||||
{
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public void push( MatrixStack matrixStack )
|
||||
public void push( PoseStack matrixStack )
|
||||
{
|
||||
matrixStack.push();
|
||||
matrixStack.pushPose();
|
||||
|
||||
Vec3f translation = matrix.getTranslation();
|
||||
matrixStack.translate( translation.getX(), translation.getY(), translation.getZ() );
|
||||
Vector3f translation = matrix.getTranslation();
|
||||
matrixStack.translate( translation.x(), translation.y(), translation.z() );
|
||||
|
||||
matrixStack.multiply( matrix.getRotation2() );
|
||||
matrixStack.mulPose( matrix.getLeftRotation() );
|
||||
|
||||
Vec3f scale = matrix.getScale();
|
||||
matrixStack.scale( scale.getX(), scale.getY(), scale.getZ() );
|
||||
Vector3f scale = matrix.getScale();
|
||||
matrixStack.scale( scale.x(), scale.y(), scale.z() );
|
||||
|
||||
matrixStack.multiply( matrix.getRotation1() );
|
||||
matrixStack.mulPose( matrix.getRightRotation() );
|
||||
}
|
||||
}
|
||||
|
@@ -8,9 +8,8 @@ package dan200.computercraft.api.filesystem;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.level.Level;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
@@ -19,10 +18,10 @@ import java.util.List;
|
||||
/**
|
||||
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}.
|
||||
*
|
||||
* Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or {@link
|
||||
* Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(Level, String, long)} or {@link
|
||||
* ComputerCraftAPI#createResourceMount(String, String)}, or you're free to implement it yourselves!
|
||||
*
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IWritableMount
|
||||
|
@@ -8,9 +8,8 @@ package dan200.computercraft.api.filesystem;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.level.Level;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
@@ -20,10 +19,10 @@ import java.util.OptionalLong;
|
||||
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)} or {@link
|
||||
* IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
|
||||
*
|
||||
* Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(World, String, long)}, or you're free to
|
||||
* Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(Level, String, long)}, or you're free to
|
||||
* implement it yourselves!
|
||||
*
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||
* @see IMount
|
||||
|
@@ -9,9 +9,8 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||
import dan200.computercraft.core.asm.LuaMethod;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
/**
|
||||
* A generic source of {@link LuaMethod} functions.
|
||||
@@ -54,5 +53,5 @@ public interface GenericSource
|
||||
* @return This source's identifier.
|
||||
*/
|
||||
@Nonnull
|
||||
Identifier id();
|
||||
ResourceLocation id();
|
||||
}
|
||||
|
@@ -7,13 +7,12 @@
|
||||
package dan200.computercraft.api.media;
|
||||
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* Represents an item that can be placed in a disk drive and used by a Computer.
|
||||
@@ -77,11 +76,11 @@ public interface IMedia
|
||||
* dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
|
||||
* @see IMount
|
||||
* @see dan200.computercraft.api.filesystem.IWritableMount
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(String, String)
|
||||
*/
|
||||
@Nullable
|
||||
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
|
||||
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull Level world )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@@ -6,10 +6,9 @@
|
||||
|
||||
package dan200.computercraft.api.media;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This interface is used to provide {@link IMedia} implementations for {@link ItemStack}.
|
||||
|
@@ -6,10 +6,9 @@
|
||||
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
/**
|
||||
* An object on an {@link IPacketNetwork}, capable of receiving packets.
|
||||
@@ -22,7 +21,7 @@ public interface IPacketReceiver
|
||||
* @return The receivers's world.
|
||||
*/
|
||||
@Nonnull
|
||||
World getWorld();
|
||||
Level getWorld();
|
||||
|
||||
/**
|
||||
* Get the position in the world at which this receiver exists.
|
||||
@@ -30,7 +29,7 @@ public interface IPacketReceiver
|
||||
* @return The receiver's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vec3 getPosition();
|
||||
|
||||
/**
|
||||
* Get the maximum distance this receiver can send and receive messages.
|
||||
|
@@ -6,10 +6,9 @@
|
||||
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
/**
|
||||
* An object on a {@link IPacketNetwork}, capable of sending packets.
|
||||
@@ -22,7 +21,7 @@ public interface IPacketSender
|
||||
* @return The sender's world.
|
||||
*/
|
||||
@Nonnull
|
||||
World getWorld();
|
||||
Level getWorld();
|
||||
|
||||
/**
|
||||
* Get the position in the world at which this sender exists.
|
||||
@@ -30,7 +29,7 @@ public interface IPacketSender
|
||||
* @return The sender's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vec3 getPosition();
|
||||
|
||||
/**
|
||||
* Get some sort of identification string for this sender. This does not strictly need to be unique, but you should be able to extract some identifiable
|
||||
|
@@ -13,10 +13,9 @@ import dan200.computercraft.api.lua.ILuaCallback;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.ILuaTask;
|
||||
import dan200.computercraft.api.lua.MethodResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.world.level.Level;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -33,7 +32,7 @@ public interface IComputerAccess
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a file in the desired location.
|
||||
* Store this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount, String)
|
||||
* @see #mountWritable(String, IWritableMount)
|
||||
@@ -55,7 +54,7 @@ public interface IComputerAccess
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a file in the desired location.
|
||||
* Store this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #mountWritable(String, IWritableMount)
|
||||
@@ -84,7 +83,7 @@ public interface IComputerAccess
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store
|
||||
* this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #unmount(String)
|
||||
@@ -105,7 +104,7 @@ public interface IComputerAccess
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store
|
||||
* this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #unmount(String)
|
||||
|
@@ -6,12 +6,11 @@
|
||||
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -34,5 +33,5 @@ public interface IPeripheralProvider
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||
*/
|
||||
@Nonnull
|
||||
IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
IPeripheral getPeripheral( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
|
@@ -5,15 +5,14 @@
|
||||
*/
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* A {@link net.minecraft.block.entity.BlockEntity} which may act as a peripheral.
|
||||
* A {@link net.minecraft.world.level.block.entity.BlockEntity} which may act as a peripheral.
|
||||
*
|
||||
* If you need more complex capabilities (such as handling TEs not belonging to your mod), you should use {@link IPeripheralProvider}.
|
||||
*/
|
||||
@@ -24,7 +23,7 @@ public interface IPeripheralTile
|
||||
*
|
||||
* @param side The side to get the peripheral from.
|
||||
* @return A peripheral, or {@code null} if there is not a peripheral here.
|
||||
* @see IPeripheralProvider#getPeripheral(World, BlockPos, Direction)
|
||||
* @see IPeripheralProvider#getPeripheral(Level, BlockPos, Direction)
|
||||
*/
|
||||
@Nullable
|
||||
IPeripheral getPeripheral( @Nonnull Direction side );
|
||||
|
@@ -7,13 +7,12 @@
|
||||
package dan200.computercraft.api.pocket;
|
||||
|
||||
import dan200.computercraft.shared.util.NonNullSupplier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -23,55 +22,55 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||
{
|
||||
private final Identifier id;
|
||||
private final ResourceLocation id;
|
||||
private final String adjective;
|
||||
private final NonNullSupplier<ItemStack> stack;
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
this.id = id;
|
||||
this.adjective = adjective;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, NonNullSupplier<ItemStack> item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, NonNullSupplier<ItemStack> item )
|
||||
{
|
||||
this( id, Util.createTranslationKey( "upgrade", id ) + ".adjective", item );
|
||||
this( id, Util.makeDescriptionId( "upgrade", id ) + ".adjective", item );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemStack stack )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemStack stack )
|
||||
{
|
||||
this( id, adjective, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, ItemStack stack )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, ItemStack stack )
|
||||
{
|
||||
this( id, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemConvertible item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemLike item )
|
||||
{
|
||||
this( id, adjective, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, ItemConvertible item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, ItemLike item )
|
||||
{
|
||||
this( id, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, adjective, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final Identifier getUpgradeID()
|
||||
public final ResourceLocation getUpgradeID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
@@ -97,11 +96,11 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||
*/
|
||||
private static final class CachedStack implements NonNullSupplier<ItemStack>
|
||||
{
|
||||
private final Supplier<? extends ItemConvertible> provider;
|
||||
private final Supplier<? extends ItemLike> provider;
|
||||
private Item item;
|
||||
private ItemStack stack;
|
||||
|
||||
CachedStack( Supplier<? extends ItemConvertible> provider )
|
||||
CachedStack( Supplier<? extends ItemLike> provider )
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
@@ -7,12 +7,11 @@
|
||||
package dan200.computercraft.api.pocket;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -73,7 +72,7 @@ public interface IPocketAccess
|
||||
* @see #updateUpgradeNBTData()
|
||||
*/
|
||||
@Nonnull
|
||||
NbtCompound getUpgradeNBTData();
|
||||
CompoundTag getUpgradeNBTData();
|
||||
|
||||
/**
|
||||
* Mark the upgrade-specific NBT as dirty.
|
||||
@@ -93,5 +92,5 @@ public interface IPocketAccess
|
||||
* @return A collection of all upgrade names.
|
||||
*/
|
||||
@Nonnull
|
||||
Map<Identifier, IPeripheral> getUpgrades();
|
||||
Map<ResourceLocation, IPeripheral> getUpgrades();
|
||||
}
|
||||
|
@@ -9,10 +9,9 @@ package dan200.computercraft.api.pocket;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.IUpgradeBase;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* Additional peripherals for pocket computers.
|
||||
@@ -55,7 +54,7 @@ public interface IPocketUpgrade extends IUpgradeBase
|
||||
* requiring the player to be sneaking - otherwise they will be unable to access the GUI.
|
||||
* @see #createPeripheral(IPocketAccess)
|
||||
*/
|
||||
default boolean onRightClick( @Nonnull World world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||
default boolean onRightClick( @Nonnull Level world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -6,11 +6,10 @@
|
||||
|
||||
package dan200.computercraft.api.redstone;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* This interface is used to provide bundled redstone output for blocks.
|
||||
@@ -29,5 +28,5 @@ public interface IBundledRedstoneProvider
|
||||
* @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block.
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
||||
*/
|
||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
|
@@ -7,13 +7,12 @@
|
||||
package dan200.computercraft.api.turtle;
|
||||
|
||||
import dan200.computercraft.shared.util.NonNullSupplier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -23,12 +22,12 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
{
|
||||
private final Identifier id;
|
||||
private final ResourceLocation id;
|
||||
private final TurtleUpgradeType type;
|
||||
private final String adjective;
|
||||
private final NonNullSupplier<ItemStack> stack;
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
@@ -36,44 +35,44 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, NonNullSupplier<ItemStack> stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
this( id, type, Util.createTranslationKey( "upgrade", id ) + ".adjective", stack );
|
||||
this( id, type, Util.makeDescriptionId( "upgrade", id ) + ".adjective", stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||
{
|
||||
this( id, type, adjective, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemStack stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, ItemStack stack )
|
||||
{
|
||||
this( id, type, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemConvertible item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemLike item )
|
||||
{
|
||||
this( id, type, adjective, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemConvertible item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, ItemLike item )
|
||||
{
|
||||
this( id, type, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, type, adjective, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, type, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final Identifier getUpgradeID()
|
||||
public final ResourceLocation getUpgradeID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
@@ -106,11 +105,11 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
*/
|
||||
private static final class CachedStack implements NonNullSupplier<ItemStack>
|
||||
{
|
||||
private final Supplier<? extends ItemConvertible> provider;
|
||||
private final Supplier<? extends ItemLike> provider;
|
||||
private Item item;
|
||||
private ItemStack stack;
|
||||
|
||||
CachedStack( Supplier<? extends ItemConvertible> provider )
|
||||
CachedStack( Supplier<? extends ItemLike> provider )
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
@@ -9,31 +9,33 @@ import com.mojang.authlib.GameProfile;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.passive.HorseBaseEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.network.*;
|
||||
import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.VehicleMoveC2SPacket;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.village.TradeOfferList;
|
||||
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.trading.MerchantOffers;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.entity.CommandBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.crypto.Cipher;
|
||||
import java.util.Collection;
|
||||
@@ -41,26 +43,26 @@ import java.util.OptionalInt;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A wrapper for {@link ServerPlayerEntity} which denotes a "fake" player.
|
||||
* A wrapper for {@link ServerPlayer} which denotes a "fake" player.
|
||||
*
|
||||
* Please note that this does not implement any of the traditional fake player behaviour. It simply exists to prevent me passing in normal players.
|
||||
*/
|
||||
public class FakePlayer extends ServerPlayerEntity
|
||||
public class FakePlayer extends ServerPlayer
|
||||
{
|
||||
public FakePlayer( ServerWorld world, GameProfile gameProfile )
|
||||
public FakePlayer( ServerLevel world, GameProfile gameProfile )
|
||||
{
|
||||
super( world.getServer(), world, gameProfile );
|
||||
networkHandler = new FakeNetHandler( this );
|
||||
connection = new FakeNetHandler( this );
|
||||
}
|
||||
|
||||
// region Direct networkHandler access
|
||||
@Override
|
||||
public void enterCombat()
|
||||
public void onEnterCombat()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endCombat()
|
||||
public void onLeaveCombat()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -70,23 +72,23 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTick()
|
||||
public void doTick()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath( DamageSource damage )
|
||||
public void die( DamageSource damage )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity moveToWorld( ServerWorld destination )
|
||||
public Entity changeDimension( ServerLevel destination )
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wakeUp( boolean bl, boolean updateSleepingPlayers )
|
||||
public void stopSleepInBed( boolean bl, boolean updateSleepingPlayers )
|
||||
{
|
||||
|
||||
}
|
||||
@@ -103,33 +105,33 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openEditSignScreen( SignBlockEntity tile )
|
||||
public void openTextEdit( SignBlockEntity tile )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt openHandledScreen( @Nullable NamedScreenHandlerFactory container )
|
||||
public OptionalInt openMenu( @Nullable MenuProvider container )
|
||||
{
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTradeOffers( int id, TradeOfferList list, int level, int experience, boolean levelled, boolean refreshable )
|
||||
public void sendMerchantOffers( int id, MerchantOffers list, int level, int experience, boolean levelled, boolean refreshable )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openHorseInventory( HorseBaseEntity horse, Inventory inventory )
|
||||
public void openHorseInventory( AbstractHorse horse, Container inventory )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useBook( ItemStack stack, Hand hand )
|
||||
public void openItemGui( ItemStack stack, InteractionHand hand )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openCommandBlockScreen( CommandBlockBlockEntity block )
|
||||
public void openCommandBlock( CommandBlockEntity block )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -149,7 +151,7 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void closeHandledScreen()
|
||||
public void closeContainer()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -159,55 +161,55 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int unlockRecipes( Collection<Recipe<?>> recipes )
|
||||
public int awardRecipes( Collection<Recipe<?>> recipes )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Indirect
|
||||
@Override
|
||||
public int lockRecipes( Collection<Recipe<?>> recipes )
|
||||
public int resetRecipes( Collection<Recipe<?>> recipes )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage( Text textComponent, boolean status )
|
||||
public void displayClientMessage( Component textComponent, boolean status )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void consumeItem()
|
||||
protected void completeUsingItem()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookAt( EntityAnchorArgumentType.EntityAnchor anchor, Vec3d vec3d )
|
||||
public void lookAt( EntityAnchorArgument.Anchor anchor, Vec3 vec3d )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookAtEntity( EntityAnchorArgumentType.EntityAnchor self, Entity entity, EntityAnchorArgumentType.EntityAnchor target )
|
||||
public void lookAt( EntityAnchorArgument.Anchor self, Entity entity, EntityAnchorArgument.Anchor target )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectApplied( StatusEffectInstance statusEffectInstance, @Nullable Entity source )
|
||||
protected void onEffectAdded( MobEffectInstance statusEffectInstance, @Nullable Entity source )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectUpgraded( StatusEffectInstance statusEffectInstance, boolean particles, @Nullable Entity source )
|
||||
protected void onEffectUpdated( MobEffectInstance statusEffectInstance, boolean particles, @Nullable Entity source )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectRemoved( StatusEffectInstance statusEffectInstance )
|
||||
protected void onEffectRemoved( MobEffectInstance statusEffectInstance )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestTeleport( double x, double y, double z )
|
||||
public void teleportTo( double x, double y, double z )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -217,13 +219,13 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void sendMessage( Text message, MessageType type, UUID senderUuid )
|
||||
public void sendMessage( Component message, ChatType type, UUID senderUuid )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp()
|
||||
public String getIpAddress()
|
||||
{
|
||||
return "[Fake Player]";
|
||||
}
|
||||
@@ -239,63 +241,63 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void setCameraEntity( Entity entity )
|
||||
public void setCamera( Entity entity )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport( ServerWorld serverWorld, double x, double y, double z, float pitch, float yaw )
|
||||
public void teleportTo( ServerLevel serverWorld, double x, double y, double z, float pitch, float yaw )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInitialChunkPackets( ChunkPos chunkPos, Packet<?> packet, Packet<?> packet2 )
|
||||
public void trackChunk( ChunkPos chunkPos, Packet<?> packet, Packet<?> packet2 )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUnloadChunkPacket( ChunkPos chunkPos )
|
||||
public void untrackChunk( ChunkPos chunkPos )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound( SoundEvent soundEvent, SoundCategory soundCategory, float volume, float pitch )
|
||||
public void playNotifySound( SoundEvent soundEvent, SoundSource soundCategory, float volume, float pitch )
|
||||
{
|
||||
}
|
||||
|
||||
private static class FakeNetHandler extends ServerPlayNetworkHandler
|
||||
private static class FakeNetHandler extends ServerGamePacketListenerImpl
|
||||
{
|
||||
FakeNetHandler( ServerPlayerEntity player )
|
||||
FakeNetHandler( ServerPlayer player )
|
||||
{
|
||||
super( player.server, new FakeConnection(), player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect( Text message )
|
||||
public void disconnect( Component message )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVehicleMove( VehicleMoveC2SPacket move )
|
||||
public void handleMoveVehicle( ServerboundMoveVehiclePacket move )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestCommandCompletions( RequestCommandCompletionsC2SPacket packet )
|
||||
public void handleCustomCommandSuggestions( ServerboundCommandSuggestionPacket packet )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket( Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> listener )
|
||||
public void send( Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> listener )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static class FakeConnection extends ClientConnection
|
||||
private static class FakeConnection extends Connection
|
||||
{
|
||||
FakeConnection()
|
||||
{
|
||||
super( NetworkSide.CLIENTBOUND );
|
||||
super( PacketFlow.CLIENTBOUND );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -304,7 +306,7 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState( NetworkState state )
|
||||
public void setProtocol( ConnectionProtocol state )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -329,18 +331,18 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect( Text message )
|
||||
public void disconnect( Component message )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupEncryption( Cipher cipher, Cipher cipher2 )
|
||||
public void setEncryptionKey( Cipher cipher, Cipher cipher2 )
|
||||
{
|
||||
super.setupEncryption( cipher, cipher2 );
|
||||
super.setEncryptionKey( cipher, cipher2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableAutoRead()
|
||||
public void setReadOnly()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -11,15 +11,14 @@ import dan200.computercraft.api.lua.ILuaCallback;
|
||||
import dan200.computercraft.api.lua.MethodResult;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.shared.util.ItemStorage;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
/**
|
||||
* The interface passed to turtle by turtles, providing methods that they can call.
|
||||
@@ -34,7 +33,7 @@ public interface ITurtleAccess
|
||||
* @return the world in which the turtle resides.
|
||||
*/
|
||||
@Nonnull
|
||||
World getWorld();
|
||||
Level getWorld();
|
||||
|
||||
/**
|
||||
* Returns a vector containing the integer co-ordinates at which the turtle resides.
|
||||
@@ -55,7 +54,7 @@ public interface ITurtleAccess
|
||||
* @return Whether the movement was successful. It may fail if the block was not loaded or the block placement was cancelled.
|
||||
* @throws UnsupportedOperationException When attempting to teleport on the client side.
|
||||
*/
|
||||
boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos );
|
||||
boolean teleportTo( @Nonnull Level world, @Nonnull BlockPos pos );
|
||||
|
||||
/**
|
||||
* Returns a vector containing the floating point co-ordinates at which the turtle is rendered. This will shift when the turtle is moving.
|
||||
@@ -65,7 +64,7 @@ public interface ITurtleAccess
|
||||
* @see #getVisualYaw(float)
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getVisualPosition( float f );
|
||||
Vec3 getVisualPosition( float f );
|
||||
|
||||
/**
|
||||
* Returns the yaw the turtle is facing when it is rendered.
|
||||
@@ -255,7 +254,7 @@ public interface ITurtleAccess
|
||||
* @see #updateUpgradeNBTData(TurtleSide)
|
||||
*/
|
||||
@Nonnull
|
||||
NbtCompound getUpgradeNBTData( @Nullable TurtleSide side );
|
||||
CompoundTag getUpgradeNBTData( @Nullable TurtleSide side );
|
||||
|
||||
/**
|
||||
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the client and persisted.
|
||||
@@ -278,5 +277,5 @@ public interface ITurtleAccess
|
||||
* @return This turtle's inventory
|
||||
*/
|
||||
@Nonnull
|
||||
Inventory getInventory();
|
||||
Container getInventory();
|
||||
}
|
||||
|
@@ -12,8 +12,7 @@ import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@@ -10,9 +10,8 @@ import dan200.computercraft.api.turtle.FakePlayer;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@@ -11,12 +11,11 @@ import dan200.computercraft.api.turtle.FakePlayer;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -31,10 +30,10 @@ import java.util.Objects;
|
||||
*/
|
||||
public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
||||
{
|
||||
private final World world;
|
||||
private final Level world;
|
||||
private final BlockPos pos;
|
||||
|
||||
protected TurtleBlockEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull World world,
|
||||
protected TurtleBlockEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull Level world,
|
||||
@Nonnull BlockPos pos )
|
||||
{
|
||||
super( turtle, action, player );
|
||||
@@ -50,7 +49,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
||||
*
|
||||
* @return The world the turtle is interacting in.
|
||||
*/
|
||||
public World getWorld()
|
||||
public Level getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
@@ -76,7 +75,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
||||
private final ITurtleUpgrade upgrade;
|
||||
private final TurtleSide side;
|
||||
|
||||
public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState block,
|
||||
public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState block,
|
||||
@Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
|
||||
{
|
||||
super( turtle, TurtleAction.DIG, player, world, pos );
|
||||
@@ -130,7 +129,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
||||
*/
|
||||
public static class Move extends TurtleBlockEvent
|
||||
{
|
||||
public Move( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos )
|
||||
public Move( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos )
|
||||
{
|
||||
super( turtle, TurtleAction.MOVE, player, world, pos );
|
||||
}
|
||||
@@ -145,7 +144,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
||||
{
|
||||
private final ItemStack stack;
|
||||
|
||||
public Place( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull ItemStack stack )
|
||||
public Place( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull ItemStack stack )
|
||||
{
|
||||
super( turtle, TurtleAction.PLACE, player, world, pos );
|
||||
|
||||
@@ -177,7 +176,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
||||
private final BlockState state;
|
||||
private final Map<String, Object> data;
|
||||
|
||||
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state,
|
||||
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull BlockState state,
|
||||
@Nonnull Map<String, Object> data )
|
||||
{
|
||||
super( turtle, TurtleAction.INSPECT, player, world, pos );
|
||||
|
@@ -8,9 +8,8 @@ package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.lua.MethodResult;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@@ -8,13 +8,12 @@ package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.turtle.FakePlayer;
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -22,10 +21,10 @@ import java.util.Objects;
|
||||
*/
|
||||
public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
{
|
||||
private final Inventory handler;
|
||||
private final Container handler;
|
||||
|
||||
protected TurtleInventoryEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull World world,
|
||||
@Nonnull BlockPos pos, @Nullable Inventory handler )
|
||||
protected TurtleInventoryEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull Level world,
|
||||
@Nonnull BlockPos pos, @Nullable Container handler )
|
||||
{
|
||||
super( turtle, action, player, world, pos );
|
||||
this.handler = handler;
|
||||
@@ -37,7 +36,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
* @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
|
||||
*/
|
||||
@Nullable
|
||||
public Inventory getItemHandler()
|
||||
public Container getItemHandler()
|
||||
{
|
||||
return handler;
|
||||
}
|
||||
@@ -49,7 +48,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
*/
|
||||
public static class Suck extends TurtleInventoryEvent
|
||||
{
|
||||
public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler )
|
||||
public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nullable Container handler )
|
||||
{
|
||||
super( turtle, TurtleAction.SUCK, player, world, pos, handler );
|
||||
}
|
||||
@@ -64,7 +63,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||
{
|
||||
private final ItemStack stack;
|
||||
|
||||
public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler,
|
||||
public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull Level world, @Nonnull BlockPos pos, @Nullable Container handler,
|
||||
@Nonnull ItemStack stack )
|
||||
{
|
||||
super( turtle, TurtleAction.DROP, player, world, pos, handler );
|
||||
|
@@ -7,10 +7,9 @@
|
||||
package dan200.computercraft.api.turtle.event;
|
||||
|
||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@@ -15,16 +15,15 @@ import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.render.model.ModelRotation;
|
||||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import java.util.HashSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -68,20 +67,20 @@ public final class ClientRegistry
|
||||
|
||||
private ClientRegistry() {}
|
||||
|
||||
public static void onTextureStitchEvent( SpriteAtlasTexture atlasTexture, ClientSpriteRegistryCallback.Registry registry )
|
||||
public static void onTextureStitchEvent( TextureAtlas atlasTexture, ClientSpriteRegistryCallback.Registry registry )
|
||||
{
|
||||
for( String extra : EXTRA_TEXTURES )
|
||||
{
|
||||
registry.register( new Identifier( ComputerCraft.MOD_ID, extra ) );
|
||||
registry.register( new ResourceLocation( ComputerCraft.MOD_ID, extra ) );
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings( "NewExpressionSideOnly" )
|
||||
public static void onModelBakeEvent( ResourceManager manager, Consumer<Identifier> out )
|
||||
public static void onModelBakeEvent( ResourceManager manager, Consumer<ResourceLocation> out )
|
||||
{
|
||||
for( String model : EXTRA_MODELS )
|
||||
{
|
||||
out.accept( new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, model ), "inventory" ) );
|
||||
out.accept( new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, model ), "inventory" ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,14 +113,14 @@ public final class ClientRegistry
|
||||
ComputerCraftRegistry.ModBlocks.TURTLE_ADVANCED );
|
||||
}
|
||||
|
||||
private static BakedModel bake( ModelLoader loader, UnbakedModel model, Identifier identifier )
|
||||
private static BakedModel bake( ModelBakery loader, UnbakedModel model, ResourceLocation identifier )
|
||||
{
|
||||
model.getTextureDependencies( loader::getOrLoadModel, new HashSet<>() );
|
||||
model.getMaterials( loader::getModel, new HashSet<>() );
|
||||
return model.bake( loader,
|
||||
spriteIdentifier -> MinecraftClient.getInstance()
|
||||
.getSpriteAtlas( spriteIdentifier.getAtlasId() )
|
||||
.apply( spriteIdentifier.getTextureId() ),
|
||||
ModelRotation.X0_Y0,
|
||||
spriteIdentifier -> Minecraft.getInstance()
|
||||
.getTextureAtlas( spriteIdentifier.atlasLocation() )
|
||||
.apply( spriteIdentifier.texture() ),
|
||||
BlockModelRotation.X0_Y0,
|
||||
identifier );
|
||||
}
|
||||
}
|
||||
|
@@ -11,15 +11,15 @@ import dan200.computercraft.shared.command.text.ChatHelpers;
|
||||
import dan200.computercraft.shared.command.text.TableBuilder;
|
||||
import dan200.computercraft.shared.command.text.TableFormatter;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.hud.ChatHud;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.components.ChatComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public class ClientTableFormatter implements TableFormatter
|
||||
{
|
||||
@@ -29,7 +29,7 @@ public class ClientTableFormatter implements TableFormatter
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Text getPadding( Text component, int width )
|
||||
public Component getPadding( Component component, int width )
|
||||
{
|
||||
int extraWidth = width - getWidth( component );
|
||||
if( extraWidth <= 0 )
|
||||
@@ -37,18 +37,18 @@ public class ClientTableFormatter implements TableFormatter
|
||||
return null;
|
||||
}
|
||||
|
||||
TextRenderer renderer = renderer();
|
||||
Font renderer = renderer();
|
||||
|
||||
float spaceWidth = renderer.getWidth( " " );
|
||||
int spaces = MathHelper.floor( extraWidth / spaceWidth );
|
||||
float spaceWidth = renderer.width( " " );
|
||||
int spaces = Mth.floor( extraWidth / spaceWidth );
|
||||
int extra = extraWidth - (int) (spaces * spaceWidth);
|
||||
|
||||
return ChatHelpers.coloured( StringUtils.repeat( ' ', spaces ) + StringUtils.repeat( (char) 712, extra ), Formatting.GRAY );
|
||||
return ChatHelpers.coloured( StringUtils.repeat( ' ', spaces ) + StringUtils.repeat( (char) 712, extra ), ChatFormatting.GRAY );
|
||||
}
|
||||
|
||||
private static TextRenderer renderer()
|
||||
private static Font renderer()
|
||||
{
|
||||
return MinecraftClient.getInstance().textRenderer;
|
||||
return Minecraft.getInstance().font;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,16 +58,16 @@ public class ClientTableFormatter implements TableFormatter
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth( Text component )
|
||||
public int getWidth( Component component )
|
||||
{
|
||||
return renderer().getWidth( component );
|
||||
return renderer().width( component );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLine( int id, Text component )
|
||||
public void writeLine( int id, Component component )
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
ChatHud chat = mc.inGameHud.getChatHud();
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
ChatComponent chat = mc.gui.getChat();
|
||||
|
||||
// TODO: Trim the text if it goes over the allowed length
|
||||
// int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() );
|
||||
@@ -79,7 +79,7 @@ public class ClientTableFormatter implements TableFormatter
|
||||
@Override
|
||||
public int display( TableBuilder table )
|
||||
{
|
||||
ChatHud chat = MinecraftClient.getInstance().inGameHud.getChatHud();
|
||||
ChatComponent chat = Minecraft.getInstance().gui.getChat();
|
||||
|
||||
int lastHeight = lastHeights.get( table.getId() );
|
||||
|
||||
|
@@ -5,25 +5,24 @@
|
||||
*/
|
||||
package dan200.computercraft.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.sound.AbstractSoundInstance;
|
||||
import net.minecraft.client.sound.SoundInstance;
|
||||
import net.minecraft.client.sound.TickableSoundInstance;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.resources.sounds.TickableSoundInstance;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class SoundManager
|
||||
{
|
||||
private static final Map<UUID, MoveableSound> sounds = new HashMap<>();
|
||||
|
||||
public static void playSound( UUID source, Vec3d position, Identifier event, float volume, float pitch )
|
||||
public static void playSound( UUID source, Vec3 position, ResourceLocation event, float volume, float pitch )
|
||||
{
|
||||
var soundManager = MinecraftClient.getInstance().getSoundManager();
|
||||
var soundManager = Minecraft.getInstance().getSoundManager();
|
||||
|
||||
MoveableSound oldSound = sounds.get( source );
|
||||
if( oldSound != null ) soundManager.stop( oldSound );
|
||||
@@ -38,10 +37,10 @@ public class SoundManager
|
||||
SoundInstance sound = sounds.remove( source );
|
||||
if( sound == null ) return;
|
||||
|
||||
MinecraftClient.getInstance().getSoundManager().stop( sound );
|
||||
Minecraft.getInstance().getSoundManager().stop( sound );
|
||||
}
|
||||
|
||||
public static void moveSound( UUID source, Vec3d position )
|
||||
public static void moveSound( UUID source, Vec3 position )
|
||||
{
|
||||
MoveableSound sound = sounds.get( source );
|
||||
if( sound != null ) sound.setPosition( position );
|
||||
@@ -54,24 +53,24 @@ public class SoundManager
|
||||
|
||||
private static class MoveableSound extends AbstractSoundInstance implements TickableSoundInstance
|
||||
{
|
||||
protected MoveableSound( Identifier sound, Vec3d position, float volume, float pitch )
|
||||
protected MoveableSound( ResourceLocation sound, Vec3 position, float volume, float pitch )
|
||||
{
|
||||
super( sound, SoundCategory.RECORDS );
|
||||
super( sound, SoundSource.RECORDS );
|
||||
setPosition( position );
|
||||
this.volume = volume;
|
||||
this.pitch = pitch;
|
||||
attenuationType = SoundInstance.AttenuationType.LINEAR;
|
||||
attenuation = SoundInstance.Attenuation.LINEAR;
|
||||
}
|
||||
|
||||
void setPosition( Vec3d position )
|
||||
void setPosition( Vec3 position )
|
||||
{
|
||||
x = (float) position.getX();
|
||||
y = (float) position.getY();
|
||||
z = (float) position.getZ();
|
||||
x = (float) position.x();
|
||||
y = (float) position.y();
|
||||
z = (float) position.z();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone()
|
||||
public boolean isStopped()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
@@ -16,14 +17,13 @@ import dan200.computercraft.shared.computer.upload.UploadResult;
|
||||
import dan200.computercraft.shared.network.NetworkHandler;
|
||||
import dan200.computercraft.shared.network.server.ContinueUploadMessage;
|
||||
import dan200.computercraft.shared.network.server.UploadFileMessage;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
@@ -34,12 +34,12 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ComputerScreenBase<T extends ContainerComputerBase> extends HandledScreen<T>
|
||||
public abstract class ComputerScreenBase<T extends ContainerComputerBase> extends AbstractContainerScreen<T>
|
||||
{
|
||||
|
||||
private static final Text OK = new TranslatableText( "gui.ok" );
|
||||
private static final Text CANCEL = new TranslatableText( "gui.cancel" );
|
||||
private static final Text OVERWRITE = new TranslatableText( "gui.computercraft.upload.overwrite_button" );
|
||||
private static final Component OK = new TranslatableComponent( "gui.ok" );
|
||||
private static final Component CANCEL = new TranslatableComponent( "gui.cancel" );
|
||||
private static final Component OVERWRITE = new TranslatableComponent( "gui.computercraft.upload.overwrite_button" );
|
||||
|
||||
protected WidgetTerminal terminal;
|
||||
protected final ClientComputer computer;
|
||||
@@ -47,7 +47,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
|
||||
protected final int sidebarYOffset;
|
||||
|
||||
public ComputerScreenBase( T container, PlayerInventory player, Text title, int sidebarYOffset )
|
||||
public ComputerScreenBase( T container, Inventory player, Component title, int sidebarYOffset )
|
||||
{
|
||||
super( container, player, title );
|
||||
computer = (ClientComputer) container.getComputer();
|
||||
@@ -61,10 +61,10 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
protected final void init()
|
||||
{
|
||||
super.init();
|
||||
client.keyboard.setRepeatEvents( true );
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( true );
|
||||
|
||||
terminal = addDrawableChild( createTerminal() );
|
||||
ComputerSidebar.addButtons( this, computer, this::addDrawableChild, x, y + sidebarYOffset );
|
||||
terminal = addRenderableWidget( createTerminal() );
|
||||
ComputerSidebar.addButtons( this, computer, this::addRenderableWidget, leftPos, topPos + sidebarYOffset );
|
||||
setFocused( terminal );
|
||||
}
|
||||
|
||||
@@ -72,13 +72,13 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
public final void removed()
|
||||
{
|
||||
super.removed();
|
||||
client.keyboard.setRepeatEvents( false );
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void handledScreenTick()
|
||||
public final void containerTick()
|
||||
{
|
||||
super.handledScreenTick();
|
||||
super.containerTick();
|
||||
terminal.update();
|
||||
}
|
||||
|
||||
@@ -95,11 +95,11 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
public final void render( @Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
drawMouseoverTooltip( stack, mouseX, mouseY );
|
||||
renderTooltip( stack, mouseX, mouseY );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,13 +109,13 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawForeground( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
protected void renderLabels( @Nonnull PoseStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void filesDragged( @Nonnull List<Path> files )
|
||||
public void onFilesDrop( @Nonnull List<Path> files )
|
||||
{
|
||||
if( files.isEmpty() ) return;
|
||||
|
||||
@@ -145,7 +145,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
String name = file.getFileName().toString();
|
||||
if( name.length() > UploadFileMessage.MAX_FILE_NAME )
|
||||
{
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableText( "gui.computercraft.upload.failed.name_too_long" ) );
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableComponent( "gui.computercraft.upload.failed.name_too_long" ) );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
byte[] digest = FileUpload.getDigest( buffer );
|
||||
if( digest == null )
|
||||
{
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableText( "gui.computercraft.upload.failed.corrupted" ) );
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableComponent( "gui.computercraft.upload.failed.corrupted" ) );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,13 +166,13 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
catch( IOException e )
|
||||
{
|
||||
ComputerCraft.log.error( "Failed uploading files", e );
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableText( "gui.computercraft.upload.failed.generic", "Cannot compute checksum" ) );
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableComponent( "gui.computercraft.upload.failed.generic", "Cannot compute checksum" ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( toUpload.size() > UploadFileMessage.MAX_FILES )
|
||||
{
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableText( "gui.computercraft.upload.failed.too_many_files" ) );
|
||||
alert( UploadResult.FAILED_TITLE, new TranslatableComponent( "gui.computercraft.upload.failed.too_many_files" ) );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadResult( UploadResult result, Text message )
|
||||
public void uploadResult( UploadResult result, Component message )
|
||||
{
|
||||
switch( result )
|
||||
{
|
||||
@@ -194,7 +194,7 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
break;
|
||||
case CONFIRM_OVERWRITE:
|
||||
OptionScreen.show(
|
||||
client, UploadResult.UPLOAD_OVERWRITE, message,
|
||||
minecraft, UploadResult.UPLOAD_OVERWRITE, message,
|
||||
Arrays.asList(
|
||||
OptionScreen.newButton( CANCEL, b -> cancelUpload() ),
|
||||
OptionScreen.newButton( OVERWRITE, b -> continueUpload() )
|
||||
@@ -207,21 +207,21 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
|
||||
private void continueUpload()
|
||||
{
|
||||
if( client.currentScreen instanceof OptionScreen ) ((OptionScreen) client.currentScreen).disable();
|
||||
if( minecraft.screen instanceof OptionScreen ) ((OptionScreen) minecraft.screen).disable();
|
||||
NetworkHandler.sendToServer( new ContinueUploadMessage( computer.getInstanceID(), true ) );
|
||||
}
|
||||
|
||||
private void cancelUpload()
|
||||
{
|
||||
client.setScreen( this );
|
||||
minecraft.setScreen( this );
|
||||
NetworkHandler.sendToServer( new ContinueUploadMessage( computer.getInstanceID(), false ) );
|
||||
}
|
||||
|
||||
private void alert( Text title, Text message )
|
||||
private void alert( Component title, Component message )
|
||||
{
|
||||
OptionScreen.show( client, title, message,
|
||||
Collections.singletonList( OptionScreen.newButton( OK, b -> client.setScreen( this ) ) ),
|
||||
() -> client.setScreen( this )
|
||||
OptionScreen.show( minecraft, title, message,
|
||||
Collections.singletonList( OptionScreen.newButton( OK, b -> minecraft.setScreen( this ) ) ),
|
||||
() -> minecraft.setScreen( this )
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -12,18 +12,18 @@ import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.AffineTransformation;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
||||
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Transformation;
|
||||
|
||||
public final class FixedWidthFontRenderer
|
||||
{
|
||||
public static final int FONT_HEIGHT = 9;
|
||||
@@ -31,9 +31,9 @@ public final class FixedWidthFontRenderer
|
||||
public static final float WIDTH = 256.0f;
|
||||
public static final float BACKGROUND_START = (WIDTH - 6.0f) / WIDTH;
|
||||
public static final float BACKGROUND_END = (WIDTH - 4.0f) / WIDTH;
|
||||
private static final Matrix4f IDENTITY = AffineTransformation.identity()
|
||||
private static final Matrix4f IDENTITY = Transformation.identity()
|
||||
.getMatrix();
|
||||
public static final Identifier FONT = new Identifier( "computercraft", "textures/gui/term_font.png" );
|
||||
public static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
|
||||
|
||||
|
||||
private FixedWidthFontRenderer()
|
||||
@@ -157,34 +157,34 @@ public final class FixedWidthFontRenderer
|
||||
|
||||
buffer.vertex( transform, x, y, 0f )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( xStart / WIDTH, yStart / WIDTH )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( xStart / WIDTH, yStart / WIDTH )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y, 0f )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y, 0f )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
}
|
||||
|
||||
private static void drawQuad( Matrix4f transform, VertexConsumer buffer, float x, float y, float width, float height, Palette palette,
|
||||
@@ -210,28 +210,28 @@ public final class FixedWidthFontRenderer
|
||||
{
|
||||
buffer.vertex( transform, x, y, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( BACKGROUND_START, BACKGROUND_START )
|
||||
.next();
|
||||
.uv( BACKGROUND_START, BACKGROUND_START )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x, y + height, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( BACKGROUND_START, BACKGROUND_END )
|
||||
.next();
|
||||
.uv( BACKGROUND_START, BACKGROUND_END )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x + width, y, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( BACKGROUND_END, BACKGROUND_START )
|
||||
.next();
|
||||
.uv( BACKGROUND_END, BACKGROUND_START )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x + width, y, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( BACKGROUND_END, BACKGROUND_START )
|
||||
.next();
|
||||
.uv( BACKGROUND_END, BACKGROUND_START )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x, y + height, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( BACKGROUND_START, BACKGROUND_END )
|
||||
.next();
|
||||
.uv( BACKGROUND_START, BACKGROUND_END )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x + width, y + height, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( BACKGROUND_END, BACKGROUND_END )
|
||||
.next();
|
||||
.uv( BACKGROUND_END, BACKGROUND_END )
|
||||
.endVertex();
|
||||
}
|
||||
|
||||
public static void drawTerminalWithoutCursor( @Nonnull Matrix4f transform, @Nonnull VertexConsumer buffer, float x, float y,
|
||||
@@ -319,12 +319,12 @@ public final class FixedWidthFontRenderer
|
||||
public static void drawTerminal( @Nonnull Matrix4f transform, float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize,
|
||||
float bottomMarginSize, float leftMarginSize, float rightMarginSize )
|
||||
{
|
||||
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance()
|
||||
.getBufferBuilders()
|
||||
.getEntityVertexConsumers();
|
||||
MultiBufferSource.BufferSource renderer = Minecraft.getInstance()
|
||||
.renderBuffers()
|
||||
.bufferSource();
|
||||
VertexConsumer buffer = renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH );
|
||||
drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||
renderer.draw();
|
||||
renderer.endBatch();
|
||||
}
|
||||
|
||||
public static void drawTerminal( float x, float y, @Nonnull Terminal terminal, boolean greyscale, float topMarginSize, float bottomMarginSize,
|
||||
@@ -341,21 +341,21 @@ public final class FixedWidthFontRenderer
|
||||
|
||||
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, float x, float y, float width, float height )
|
||||
{
|
||||
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance()
|
||||
.getBufferBuilders()
|
||||
.getEntityVertexConsumers();
|
||||
MultiBufferSource.BufferSource renderer = Minecraft.getInstance()
|
||||
.renderBuffers()
|
||||
.bufferSource();
|
||||
drawEmptyTerminal( transform, renderer, x, y, width, height );
|
||||
renderer.draw();
|
||||
renderer.endBatch();
|
||||
}
|
||||
|
||||
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull VertexConsumerProvider renderer, float x, float y, float width,
|
||||
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull MultiBufferSource renderer, float x, float y, float width,
|
||||
float height )
|
||||
{
|
||||
Colour colour = Colour.BLACK;
|
||||
drawQuad( transform, renderer.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
||||
}
|
||||
|
||||
public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull VertexConsumerProvider renderer, float x, float y, float width, float height )
|
||||
public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull MultiBufferSource renderer, float x, float y, float width, float height )
|
||||
{
|
||||
Colour colour = Colour.BLACK;
|
||||
drawQuad( transform, renderer.getBuffer( RenderTypes.TERMINAL_BLOCKER ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
||||
|
@@ -13,41 +13,41 @@ import dan200.computercraft.client.render.ComputerBorderRenderer;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.getTexture;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
public final class GuiComputer<T extends ContainerComputerBase> extends ComputerScreenBase<T>
|
||||
{
|
||||
private final int termWidth;
|
||||
private final int termHeight;
|
||||
|
||||
private GuiComputer( T container, PlayerInventory player, Text title, int termWidth, int termHeight )
|
||||
private GuiComputer( T container, Inventory player, Component title, int termWidth, int termHeight )
|
||||
{
|
||||
super( container, player, title, BORDER );
|
||||
this.termWidth = termWidth;
|
||||
this.termHeight = termHeight;
|
||||
|
||||
backgroundWidth = WidgetTerminal.getWidth( termWidth ) + BORDER * 2 + ComputerSidebar.WIDTH;
|
||||
backgroundHeight = WidgetTerminal.getHeight( termHeight ) + BORDER * 2;
|
||||
imageWidth = WidgetTerminal.getWidth( termWidth ) + BORDER * 2 + ComputerSidebar.WIDTH;
|
||||
imageHeight = WidgetTerminal.getHeight( termHeight ) + BORDER * 2;
|
||||
}
|
||||
|
||||
public static GuiComputer<ContainerComputerBase> create( ContainerComputerBase container, PlayerInventory inventory, Text component )
|
||||
public static GuiComputer<ContainerComputerBase> create( ContainerComputerBase container, Inventory inventory, Component component )
|
||||
{
|
||||
return new GuiComputer<>( container, inventory, component, ComputerCraft.computerTermWidth, ComputerCraft.computerTermHeight );
|
||||
}
|
||||
|
||||
public static GuiComputer<ContainerComputerBase> createPocket( ContainerComputerBase container, PlayerInventory inventory, Text component )
|
||||
public static GuiComputer<ContainerComputerBase> createPocket( ContainerComputerBase container, Inventory inventory, Component component )
|
||||
{
|
||||
return new GuiComputer<>( container, inventory, component, ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight );
|
||||
}
|
||||
|
||||
public static GuiComputer<ContainerViewComputer> createView( ContainerViewComputer container, PlayerInventory inventory, Text component )
|
||||
public static GuiComputer<ContainerViewComputer> createView( ContainerViewComputer container, Inventory inventory, Component component )
|
||||
{
|
||||
return new GuiComputer<>( container, inventory, component, container.getWidth(), container.getHeight() );
|
||||
}
|
||||
@@ -56,15 +56,15 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
|
||||
protected WidgetTerminal createTerminal()
|
||||
{
|
||||
return new WidgetTerminal( computer,
|
||||
x + ComputerSidebar.WIDTH + BORDER, y + BORDER, termWidth, termHeight
|
||||
leftPos + ComputerSidebar.WIDTH + BORDER, topPos + BORDER, termWidth, termHeight
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public void drawBackground( @Nonnull MatrixStack stack, float partialTicks, int mouseX, int mouseY )
|
||||
public void renderBg( @Nonnull PoseStack stack, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
ComputerBorderRenderer.render(
|
||||
getTexture( family ), terminal.x, terminal.y, getZOffset(),
|
||||
getTexture( family ), terminal.x, terminal.y, getBlitOffset(),
|
||||
RenderTypes.FULL_BRIGHT_LIGHTMAP, terminal.getWidth(), terminal.getHeight() );
|
||||
ComputerSidebar.renderBackground( stack, x, y + sidebarYOffset );
|
||||
ComputerSidebar.renderBackground( stack, leftPos, topPos + sidebarYOffset );
|
||||
}
|
||||
}
|
||||
|
@@ -7,39 +7,38 @@
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class GuiDiskDrive extends HandledScreen<ContainerDiskDrive>
|
||||
public class GuiDiskDrive extends AbstractContainerScreen<ContainerDiskDrive>
|
||||
{
|
||||
private static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/disk_drive.png" );
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
|
||||
|
||||
public GuiDiskDrive( ContainerDiskDrive container, PlayerInventory player, Text title )
|
||||
public GuiDiskDrive( ContainerDiskDrive container, Inventory player, Component title )
|
||||
{
|
||||
super( container, player, title );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground( transform );
|
||||
super.render( transform, mouseX, mouseY, partialTicks );
|
||||
drawMouseoverTooltip( transform, mouseX, mouseY );
|
||||
renderTooltip( transform, mouseX, mouseY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
protected void renderBg( @Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
RenderSystem.setShader( GameRenderer::getPositionTexShader );
|
||||
RenderSystem.setShaderColor( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
RenderSystem.setShaderTexture( 0, BACKGROUND );
|
||||
drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight );
|
||||
blit( transform, leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
}
|
||||
}
|
||||
|
@@ -7,42 +7,41 @@
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class GuiPrinter extends HandledScreen<ContainerPrinter>
|
||||
public class GuiPrinter extends AbstractContainerScreen<ContainerPrinter>
|
||||
{
|
||||
private static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/printer.png" );
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
||||
|
||||
public GuiPrinter( ContainerPrinter container, PlayerInventory player, Text title )
|
||||
public GuiPrinter( ContainerPrinter container, Inventory player, Component title )
|
||||
{
|
||||
super( container, player, title );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
drawMouseoverTooltip( stack, mouseX, mouseY );
|
||||
renderTooltip( stack, mouseX, mouseY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
protected void renderBg( @Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
RenderSystem.setShaderColor( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
RenderSystem.setShaderTexture( 0, BACKGROUND );
|
||||
drawTexture( transform, x, y, 0, 0, backgroundWidth, backgroundHeight );
|
||||
blit( transform, leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
|
||||
if( getScreenHandler().isPrinting() )
|
||||
if( getMenu().isPrinting() )
|
||||
{
|
||||
drawTexture( transform, x + 34, y + 21, 176, 0, 25, 45 );
|
||||
blit( transform, leftPos + 34, topPos + 21, 176, 0, 25, 45 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,24 +7,24 @@
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
|
||||
|
||||
public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem>
|
||||
{
|
||||
private final boolean book;
|
||||
private final int pages;
|
||||
@@ -32,11 +32,11 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
private final TextBuffer[] colours;
|
||||
private int page;
|
||||
|
||||
public GuiPrintout( ContainerHeldItem container, PlayerInventory player, Text title )
|
||||
public GuiPrintout( ContainerHeldItem container, Inventory player, Component title )
|
||||
{
|
||||
super( container, player, title );
|
||||
|
||||
backgroundHeight = Y_SIZE;
|
||||
imageHeight = Y_SIZE;
|
||||
|
||||
String[] text = ItemPrintout.getText( container.getStack() );
|
||||
this.text = new TextBuffer[text.length];
|
||||
@@ -89,37 +89,37 @@ public class GuiPrintout extends HandledScreen<ContainerHeldItem>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
// We must take the background further back in order to not overlap with our printed pages.
|
||||
setZOffset( getZOffset() - 1 );
|
||||
setBlitOffset( getBlitOffset() - 1 );
|
||||
renderBackground( stack );
|
||||
setZOffset( getZOffset() + 1 );
|
||||
setBlitOffset( getBlitOffset() + 1 );
|
||||
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawForeground( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
protected void renderLabels( @Nonnull PoseStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
protected void renderBg( @Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw the printout
|
||||
RenderSystem.setShaderColor( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
VertexConsumerProvider.Immediate renderer = MinecraftClient.getInstance()
|
||||
.getBufferBuilders()
|
||||
.getEntityVertexConsumers();
|
||||
Matrix4f matrix = transform.peek()
|
||||
.getModel();
|
||||
drawBorder( matrix, renderer, x, y, getZOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP );
|
||||
drawText( matrix, renderer, x + X_TEXT_MARGIN, y + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours );
|
||||
renderer.draw();
|
||||
MultiBufferSource.BufferSource renderer = Minecraft.getInstance()
|
||||
.renderBuffers()
|
||||
.bufferSource();
|
||||
Matrix4f matrix = transform.last()
|
||||
.pose();
|
||||
drawBorder( matrix, renderer, leftPos, topPos, getBlitOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP );
|
||||
drawText( matrix, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours );
|
||||
renderer.endBatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -7,38 +7,37 @@
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import dan200.computercraft.client.render.ComputerBorderRenderer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
import static dan200.computercraft.shared.turtle.inventory.ContainerTurtle.BORDER;
|
||||
|
||||
public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
|
||||
{
|
||||
private static final Identifier BACKGROUND_NORMAL = new Identifier( "computercraft", "textures/gui/turtle_normal.png" );
|
||||
private static final Identifier BACKGROUND_ADVANCED = new Identifier( "computercraft", "textures/gui/turtle_advanced.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 int TEX_WIDTH = 254;
|
||||
private static final int TEX_HEIGHT = 217;
|
||||
|
||||
private final ComputerFamily family;
|
||||
|
||||
public GuiTurtle( ContainerTurtle container, PlayerInventory player, Text title )
|
||||
public GuiTurtle( ContainerTurtle container, Inventory player, Component title )
|
||||
{
|
||||
super( container, player, title, BORDER );
|
||||
|
||||
family = container.getFamily();
|
||||
backgroundWidth = TEX_WIDTH + ComputerSidebar.WIDTH;
|
||||
backgroundHeight = TEX_HEIGHT;
|
||||
imageWidth = TEX_WIDTH + ComputerSidebar.WIDTH;
|
||||
imageHeight = TEX_HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
@@ -46,25 +45,25 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
|
||||
protected WidgetTerminal createTerminal()
|
||||
{
|
||||
return new WidgetTerminal(
|
||||
computer, x + BORDER + ComputerSidebar.WIDTH, y + BORDER,
|
||||
computer, leftPos + BORDER + ComputerSidebar.WIDTH, topPos + BORDER,
|
||||
ComputerCraft.turtleTermWidth, ComputerCraft.turtleTermHeight
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
public void renderBg( @Nonnull PoseStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
boolean advanced = family == ComputerFamily.ADVANCED;
|
||||
RenderSystem.setShaderTexture( 0, advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
drawTexture( transform, x + ComputerSidebar.WIDTH, y, 0, 0, TEX_WIDTH, TEX_HEIGHT );
|
||||
blit( transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT );
|
||||
|
||||
// Draw selection slot
|
||||
int slot = getScreenHandler().getSelectedSlot();
|
||||
int slot = getMenu().getSelectedSlot();
|
||||
if( slot >= 0 )
|
||||
{
|
||||
int slotX = slot % 4;
|
||||
int slotY = slot / 4;
|
||||
drawTexture( transform, x + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18, y + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18,
|
||||
blit( transform, leftPos + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18, topPos + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18,
|
||||
0,
|
||||
217,
|
||||
24,
|
||||
@@ -72,6 +71,6 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
|
||||
}
|
||||
|
||||
RenderSystem.setShaderTexture( 0, advanced ? ComputerBorderRenderer.BACKGROUND_ADVANCED : ComputerBorderRenderer.BACKGROUND_NORMAL );
|
||||
ComputerSidebar.renderBackground( transform, x, y + sidebarYOffset );
|
||||
ComputerSidebar.renderBackground( transform, leftPos, topPos + sidebarYOffset );
|
||||
}
|
||||
}
|
||||
|
@@ -5,29 +5,29 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.text.OrderedText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.MenuAccess;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import java.util.List;
|
||||
|
||||
public class NoTermComputerScreen<T extends ContainerComputerBase> extends Screen implements ScreenHandlerProvider<T>
|
||||
public class NoTermComputerScreen<T extends ContainerComputerBase> extends Screen implements MenuAccess<T>
|
||||
{
|
||||
private final T menu;
|
||||
private WidgetTerminal terminal;
|
||||
|
||||
public NoTermComputerScreen( T menu, PlayerInventory player, Text title )
|
||||
public NoTermComputerScreen( T menu, Inventory player, Component title )
|
||||
{
|
||||
super( title );
|
||||
this.menu = menu;
|
||||
@@ -35,7 +35,7 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public T getScreenHandler()
|
||||
public T getMenu()
|
||||
{
|
||||
return menu;
|
||||
}
|
||||
@@ -44,12 +44,12 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
||||
protected void init()
|
||||
{
|
||||
this.passEvents = true;
|
||||
client.mouse.lockCursor();
|
||||
client.currentScreen = this;
|
||||
minecraft.mouseHandler.grabMouse();
|
||||
minecraft.screen = this;
|
||||
super.init();
|
||||
client.keyboard.setRepeatEvents( true );
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( true );
|
||||
|
||||
terminal = addSelectableChild( new WidgetTerminal( (ClientComputer) menu.getComputer(), 0, 0, ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight ) );
|
||||
terminal = addWidget( new WidgetTerminal( (ClientComputer) menu.getComputer(), 0, 0, ComputerCraft.pocketTermWidth, ComputerCraft.pocketTermHeight ) );
|
||||
terminal.visible = false;
|
||||
terminal.active = false;
|
||||
setFocused( terminal );
|
||||
@@ -59,7 +59,7 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
||||
public final void removed()
|
||||
{
|
||||
super.removed();
|
||||
client.keyboard.setRepeatEvents( false );
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,14 +72,14 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
||||
@Override
|
||||
public boolean mouseScrolled( double pMouseX, double pMouseY, double pDelta )
|
||||
{
|
||||
client.player.getInventory().scrollInHotbar( pDelta );
|
||||
minecraft.player.getInventory().swapPaint( pDelta );
|
||||
return super.mouseScrolled( pMouseX, pMouseY, pDelta );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose()
|
||||
{
|
||||
client.player.closeHandledScreen();
|
||||
minecraft.player.closeContainer();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@@ -102,16 +102,16 @@ public class NoTermComputerScreen<T extends ContainerComputerBase> extends Scree
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
public void render( PoseStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
super.render( transform, mouseX, mouseY, partialTicks );
|
||||
|
||||
TextRenderer font = client.textRenderer;
|
||||
List<OrderedText> lines = font.wrapLines( new TranslatableText( "gui.computercraft.pocket_computer_overlay" ), (int) (width * 0.8) );
|
||||
Font font = minecraft.font;
|
||||
List<FormattedCharSequence> lines = font.split( new TranslatableComponent( "gui.computercraft.pocket_computer_overlay" ), (int) (width * 0.8) );
|
||||
float y = 10.0f;
|
||||
for( OrderedText line : lines )
|
||||
for( FormattedCharSequence line : lines )
|
||||
{
|
||||
font.drawWithShadow( transform, line, (float) ((width / 2) - (client.textRenderer.getWidth( line ) / 2)), y, 0xFFFFFF );
|
||||
font.drawShadow( transform, line, (float) ((width / 2) - (minecraft.font.width( line ) / 2)), y, 0xFFFFFF );
|
||||
y += 9.0f;
|
||||
}
|
||||
}
|
||||
|
@@ -6,21 +6,20 @@
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.MultilineText;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.MultiLineLabel;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import java.util.List;
|
||||
|
||||
public final class OptionScreen extends Screen
|
||||
{
|
||||
private static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/blank_screen.png" );
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/blank_screen.png" );
|
||||
|
||||
public static final int BUTTON_WIDTH = 100;
|
||||
public static final int BUTTON_HEIGHT = 20;
|
||||
@@ -33,14 +32,14 @@ public final class OptionScreen extends Screen
|
||||
private int innerWidth;
|
||||
private int innerHeight;
|
||||
|
||||
private MultilineText messageRenderer;
|
||||
private final Text message;
|
||||
private final List<ClickableWidget> buttons;
|
||||
private MultiLineLabel messageRenderer;
|
||||
private final Component message;
|
||||
private final List<AbstractWidget> buttons;
|
||||
private final Runnable exit;
|
||||
|
||||
private final Screen originalScreen;
|
||||
|
||||
private OptionScreen( Text title, Text message, List<ClickableWidget> buttons, Runnable exit, Screen originalScreen )
|
||||
private OptionScreen( Component title, Component message, List<AbstractWidget> buttons, Runnable exit, Screen originalScreen )
|
||||
{
|
||||
super( title );
|
||||
this.message = message;
|
||||
@@ -49,9 +48,9 @@ public final class OptionScreen extends Screen
|
||||
this.originalScreen = originalScreen;
|
||||
}
|
||||
|
||||
public static void show( MinecraftClient client, Text title, Text message, List<ClickableWidget> buttons, Runnable exit )
|
||||
public static void show( Minecraft client, Component title, Component message, List<AbstractWidget> buttons, Runnable exit )
|
||||
{
|
||||
client.setScreen( new OptionScreen( title, message, buttons, exit, unwrap( client.currentScreen ) ) );
|
||||
client.setScreen( new OptionScreen( title, message, buttons, exit, unwrap( client.screen ) ) );
|
||||
}
|
||||
|
||||
public static Screen unwrap( Screen screen )
|
||||
@@ -67,40 +66,40 @@ public final class OptionScreen extends Screen
|
||||
int buttonWidth = BUTTON_WIDTH * buttons.size() + PADDING * (buttons.size() - 1);
|
||||
int innerWidth = this.innerWidth = Math.max( 256, buttonWidth + PADDING * 2 );
|
||||
|
||||
messageRenderer = MultilineText.create( textRenderer, message, innerWidth - PADDING * 2 );
|
||||
messageRenderer = MultiLineLabel.create( font, message, innerWidth - PADDING * 2 );
|
||||
|
||||
int textHeight = messageRenderer.count() * FONT_HEIGHT + PADDING * 2;
|
||||
int textHeight = messageRenderer.getLineCount() * FONT_HEIGHT + PADDING * 2;
|
||||
innerHeight = textHeight + (buttons.isEmpty() ? 0 : buttons.get( 0 ).getHeight()) + PADDING;
|
||||
|
||||
x = (width - innerWidth) / 2;
|
||||
y = (height - innerHeight) / 2;
|
||||
|
||||
int x = (width - buttonWidth) / 2;
|
||||
for( ClickableWidget button : buttons )
|
||||
for( AbstractWidget button : buttons )
|
||||
{
|
||||
button.x = x;
|
||||
button.y = y + textHeight;
|
||||
addDrawableChild( button );
|
||||
addRenderableWidget( button );
|
||||
|
||||
x += BUTTON_WIDTH + PADDING;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground( transform );
|
||||
|
||||
// Render the actual texture.
|
||||
RenderSystem.setShaderTexture( 0, BACKGROUND );
|
||||
drawTexture( transform, x, y, 0, 0, innerWidth, PADDING );
|
||||
drawTexture( transform,
|
||||
blit( transform, x, y, 0, 0, innerWidth, PADDING );
|
||||
blit( transform,
|
||||
x, y + PADDING, 0, PADDING, innerWidth, innerHeight - PADDING * 2,
|
||||
innerWidth, PADDING
|
||||
);
|
||||
drawTexture( transform, x, y + innerHeight - PADDING, 0, 256 - PADDING, innerWidth, PADDING );
|
||||
blit( transform, x, y + innerHeight - PADDING, 0, 256 - PADDING, innerWidth, PADDING );
|
||||
|
||||
messageRenderer.draw( transform, x + PADDING, y + PADDING, FONT_HEIGHT, 0x404040 );
|
||||
messageRenderer.renderLeftAlignedNoShadow( transform, x + PADDING, y + PADDING, FONT_HEIGHT, 0x404040 );
|
||||
super.render( transform, mouseX, mouseY, partialTicks );
|
||||
}
|
||||
|
||||
@@ -110,14 +109,14 @@ public final class OptionScreen extends Screen
|
||||
exit.run();
|
||||
}
|
||||
|
||||
public static ClickableWidget newButton( Text component, ButtonWidget.PressAction clicked )
|
||||
public static AbstractWidget newButton( Component component, Button.OnPress clicked )
|
||||
{
|
||||
return new ButtonWidget( 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, component, clicked );
|
||||
return new Button( 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, component, clicked );
|
||||
}
|
||||
|
||||
public void disable()
|
||||
{
|
||||
for( ClickableWidget widget : buttons ) widget.active = false;
|
||||
for( AbstractWidget widget : buttons ) widget.active = false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@@ -5,26 +5,25 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.render.ComputerBorderRenderer;
|
||||
import dan200.computercraft.shared.command.text.ChatHelpers;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Registers buttons to interact with a computer.
|
||||
*/
|
||||
public final class ComputerSidebar
|
||||
{
|
||||
private static final Identifier TEXTURE = new Identifier( ComputerCraft.MOD_ID, "textures/gui/buttons.png" );
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/buttons.png" );
|
||||
|
||||
private static final int TEX_SIZE = 64;
|
||||
|
||||
@@ -45,7 +44,7 @@ public final class ComputerSidebar
|
||||
{
|
||||
}
|
||||
|
||||
public static void addButtons( Screen screen, ClientComputer computer, Consumer<ClickableWidget> add, int x, int y )
|
||||
public static void addButtons( Screen screen, ClientComputer computer, Consumer<AbstractWidget> add, int x, int y )
|
||||
{
|
||||
x += CORNERS_BORDER + 1;
|
||||
y += CORNERS_BORDER + ICON_MARGIN;
|
||||
@@ -54,11 +53,11 @@ public final class ComputerSidebar
|
||||
screen, x, y, ICON_WIDTH, ICON_HEIGHT, () -> computer.isOn() ? 15 : 1, 1, ICON_TEX_Y_DIFF,
|
||||
TEXTURE, TEX_SIZE, TEX_SIZE, b -> toggleComputer( computer ),
|
||||
() -> computer.isOn() ? Arrays.asList(
|
||||
new TranslatableText( "gui.computercraft.tooltip.turn_off" ),
|
||||
ChatHelpers.coloured( new TranslatableText( "gui.computercraft.tooltip.turn_off.key" ), Formatting.GRAY )
|
||||
new TranslatableComponent( "gui.computercraft.tooltip.turn_off" ),
|
||||
ChatHelpers.coloured( new TranslatableComponent( "gui.computercraft.tooltip.turn_off.key" ), ChatFormatting.GRAY )
|
||||
) : Arrays.asList(
|
||||
new TranslatableText( "gui.computercraft.tooltip.turn_on" ),
|
||||
ChatHelpers.coloured( new TranslatableText( "gui.computercraft.tooltip.turn_off.key" ), Formatting.GRAY )
|
||||
new TranslatableComponent( "gui.computercraft.tooltip.turn_on" ),
|
||||
ChatHelpers.coloured( new TranslatableComponent( "gui.computercraft.tooltip.turn_off.key" ), ChatFormatting.GRAY )
|
||||
)
|
||||
) );
|
||||
|
||||
@@ -68,26 +67,26 @@ public final class ComputerSidebar
|
||||
screen, x, y, ICON_WIDTH, ICON_HEIGHT, 29, 1, ICON_TEX_Y_DIFF,
|
||||
TEXTURE, TEX_SIZE, TEX_SIZE, b -> computer.queueEvent( "terminate" ),
|
||||
Arrays.asList(
|
||||
new TranslatableText( "gui.computercraft.tooltip.terminate" ),
|
||||
ChatHelpers.coloured( new TranslatableText( "gui.computercraft.tooltip.terminate.key" ), Formatting.GRAY )
|
||||
new TranslatableComponent( "gui.computercraft.tooltip.terminate" ),
|
||||
ChatHelpers.coloured( new TranslatableComponent( "gui.computercraft.tooltip.terminate.key" ), ChatFormatting.GRAY )
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
public static void renderBackground( MatrixStack transform, int x, int y )
|
||||
public static void renderBackground( PoseStack transform, int x, int y )
|
||||
{
|
||||
Screen.drawTexture( transform,
|
||||
Screen.blit( transform,
|
||||
x, y, 0, 102, WIDTH, FULL_BORDER,
|
||||
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
|
||||
);
|
||||
|
||||
Screen.drawTexture( transform,
|
||||
Screen.blit( transform,
|
||||
x, y + FULL_BORDER, WIDTH, HEIGHT - FULL_BORDER * 2,
|
||||
0, 107, WIDTH, 4,
|
||||
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
|
||||
);
|
||||
|
||||
Screen.drawTexture( transform,
|
||||
Screen.blit( transform,
|
||||
x, y + HEIGHT - FULL_BORDER, 0, 111, WIDTH, FULL_BORDER,
|
||||
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
|
||||
);
|
||||
|
@@ -6,37 +6,36 @@
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import java.util.List;
|
||||
import java.util.function.IntSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Version of {@link net.minecraft.client.gui.widget.TexturedButtonWidget} which allows changing some properties
|
||||
* Version of {@link net.minecraft.client.gui.components.ImageButton} which allows changing some properties
|
||||
* dynamically.
|
||||
*/
|
||||
public class DynamicImageButton extends ButtonWidget
|
||||
public class DynamicImageButton extends Button
|
||||
{
|
||||
private final Screen screen;
|
||||
private final Identifier texture;
|
||||
private final ResourceLocation texture;
|
||||
private final IntSupplier xTexStart;
|
||||
private final int yTexStart;
|
||||
private final int yDiffTex;
|
||||
private final int textureWidth;
|
||||
private final int textureHeight;
|
||||
private final Supplier<List<Text>> tooltip;
|
||||
private final Supplier<List<Component>> tooltip;
|
||||
|
||||
public DynamicImageButton(
|
||||
Screen screen, int x, int y, int width, int height, int xTexStart, int yTexStart, int yDiffTex,
|
||||
Identifier texture, int textureWidth, int textureHeight,
|
||||
PressAction onPress, List<Text> tooltip
|
||||
ResourceLocation texture, int textureWidth, int textureHeight,
|
||||
OnPress onPress, List<Component> tooltip
|
||||
)
|
||||
{
|
||||
this(
|
||||
@@ -49,11 +48,11 @@ public class DynamicImageButton extends ButtonWidget
|
||||
|
||||
public DynamicImageButton(
|
||||
Screen screen, int x, int y, int width, int height, IntSupplier xTexStart, int yTexStart, int yDiffTex,
|
||||
Identifier texture, int textureWidth, int textureHeight,
|
||||
PressAction onPress, Supplier<List<Text>> tooltip
|
||||
ResourceLocation texture, int textureWidth, int textureHeight,
|
||||
OnPress onPress, Supplier<List<Component>> tooltip
|
||||
)
|
||||
{
|
||||
super( x, y, width, height, LiteralText.EMPTY, onPress );
|
||||
super( x, y, width, height, TextComponent.EMPTY, onPress );
|
||||
this.screen = screen;
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
@@ -65,7 +64,7 @@ public class DynamicImageButton extends ButtonWidget
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderButton( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
public void renderButton( @Nonnull PoseStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
RenderSystem.setShaderTexture( 0, texture );
|
||||
RenderSystem.disableDepthTest();
|
||||
@@ -73,7 +72,7 @@ public class DynamicImageButton extends ButtonWidget
|
||||
int yTex = yTexStart;
|
||||
if( isHovered() ) yTex += yDiffTex;
|
||||
|
||||
drawTexture( stack, x, y, xTexStart.getAsInt(), yTex, width, height, textureWidth, textureHeight );
|
||||
blit( stack, x, y, xTexStart.getAsInt(), yTex, width, height, textureWidth, textureHeight );
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
if( isHovered() ) renderToolTip( stack, mouseX, mouseY );
|
||||
@@ -81,20 +80,20 @@ public class DynamicImageButton extends ButtonWidget
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Text getMessage()
|
||||
public Component getMessage()
|
||||
{
|
||||
List<Text> tooltip = this.tooltip.get();
|
||||
return tooltip.isEmpty() ? LiteralText.EMPTY : tooltip.get( 0 );
|
||||
List<Component> tooltip = this.tooltip.get();
|
||||
return tooltip.isEmpty() ? TextComponent.EMPTY : tooltip.get( 0 );
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void renderToolTip( @Nonnull MatrixStack stack, int mouseX, int mouseY )
|
||||
public void renderToolTip( @Nonnull PoseStack stack, int mouseX, int mouseY )
|
||||
{
|
||||
List<Text> tooltip = this.tooltip.get();
|
||||
List<Component> tooltip = this.tooltip.get();
|
||||
|
||||
if( !tooltip.isEmpty() )
|
||||
{
|
||||
screen.renderTooltip( stack, tooltip, mouseX, mouseY );
|
||||
screen.renderComponentTooltip( stack, tooltip, mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,12 +10,10 @@ import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.narration.NarrationElementOutput;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -25,7 +23,10 @@ import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN;
|
||||
|
||||
public class WidgetTerminal extends ClickableWidget
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
||||
public class WidgetTerminal extends AbstractWidget
|
||||
{
|
||||
private static final float TERMINATE_TIME = 0.5f;
|
||||
|
||||
@@ -49,7 +50,7 @@ public class WidgetTerminal extends ClickableWidget
|
||||
|
||||
public WidgetTerminal( @Nonnull ClientComputer computer, int x, int y, int termWidth, int termHeight )
|
||||
{
|
||||
super( x, y, termWidth * FONT_WIDTH + MARGIN * 2, termHeight * FONT_HEIGHT + MARGIN * 2, LiteralText.EMPTY );
|
||||
super( x, y, termWidth * FONT_WIDTH + MARGIN * 2, termHeight * FONT_HEIGHT + MARGIN * 2, TextComponent.EMPTY );
|
||||
|
||||
this.computer = computer;
|
||||
|
||||
@@ -207,7 +208,7 @@ public class WidgetTerminal extends ClickableWidget
|
||||
|
||||
case GLFW.GLFW_KEY_V:
|
||||
// Ctrl+V for paste
|
||||
String clipboard = MinecraftClient.getInstance().keyboard.getClipboard();
|
||||
String clipboard = Minecraft.getInstance().keyboardHandler.getClipboard();
|
||||
if( clipboard != null )
|
||||
{
|
||||
// Clip to the first occurrence of \r or \n
|
||||
@@ -227,7 +228,7 @@ public class WidgetTerminal extends ClickableWidget
|
||||
}
|
||||
|
||||
// Filter the string
|
||||
clipboard = SharedConstants.stripInvalidChars( clipboard );
|
||||
clipboard = SharedConstants.filterText( clipboard );
|
||||
if( !clipboard.isEmpty() )
|
||||
{
|
||||
// Clip to 512 characters and queue the event
|
||||
@@ -346,10 +347,10 @@ public class WidgetTerminal extends ClickableWidget
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
if( !visible ) return;
|
||||
Matrix4f matrix = transform.peek().getModel();
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
Terminal terminal = computer.getTerminal();
|
||||
if( terminal != null )
|
||||
{
|
||||
@@ -362,7 +363,7 @@ public class WidgetTerminal extends ClickableWidget
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendNarrations( NarrationMessageBuilder builder )
|
||||
public void updateNarration( NarrationElementOutput builder )
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -39,12 +39,11 @@ import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
|
||||
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
|
||||
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
|
||||
import net.minecraft.client.item.UnclampedModelPredicateProvider;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.screen.PlayerScreenHandler;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.world.item.Item;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Environment( EnvType.CLIENT )
|
||||
@@ -73,11 +72,11 @@ public final class ComputerCraftProxyClient implements ClientModInitializer
|
||||
registerContainers();
|
||||
|
||||
// While turtles themselves are not transparent, their upgrades may be.
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.TURTLE_NORMAL, RenderLayer.getTranslucent() );
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.TURTLE_ADVANCED, RenderLayer.getTranslucent() );
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.TURTLE_NORMAL, RenderType.translucent() );
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.TURTLE_ADVANCED, RenderType.translucent() );
|
||||
// Monitors' textures have transparent fronts and so count as cutouts.
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.MONITOR_NORMAL, RenderLayer.getCutout() );
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.MONITOR_ADVANCED, RenderLayer.getCutout() );
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.MONITOR_NORMAL, RenderType.cutout() );
|
||||
BlockRenderLayerMap.INSTANCE.putBlock( ComputerCraftRegistry.ModBlocks.MONITOR_ADVANCED, RenderType.cutout() );
|
||||
|
||||
// Setup TESRs
|
||||
BlockEntityRendererRegistry.register( ComputerCraftRegistry.ModTiles.MONITOR_NORMAL, TileEntityMonitorRenderer::new );
|
||||
@@ -85,7 +84,7 @@ public final class ComputerCraftProxyClient implements ClientModInitializer
|
||||
BlockEntityRendererRegistry.register( ComputerCraftRegistry.ModTiles.TURTLE_NORMAL, TileEntityTurtleRenderer::new );
|
||||
BlockEntityRendererRegistry.register( ComputerCraftRegistry.ModTiles.TURTLE_ADVANCED, TileEntityTurtleRenderer::new );
|
||||
|
||||
ClientSpriteRegistryCallback.event( PlayerScreenHandler.BLOCK_ATLAS_TEXTURE )
|
||||
ClientSpriteRegistryCallback.event( InventoryMenu.BLOCK_ATLAS )
|
||||
.register( ClientRegistry::onTextureStitchEvent );
|
||||
ModelLoadingRegistry.INSTANCE.registerModelProvider( ClientRegistry::onModelBakeEvent );
|
||||
ModelLoadingRegistry.INSTANCE.registerResourceProvider( loader -> ( name, context ) -> TurtleModelLoader.INSTANCE.accepts( name ) ?
|
||||
@@ -127,9 +126,9 @@ public final class ComputerCraftProxyClient implements ClientModInitializer
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static void registerItemProperty( String name, UnclampedModelPredicateProvider getter, Supplier<? extends Item>... items )
|
||||
private static void registerItemProperty( String name, ClampedItemPropertyFunction getter, Supplier<? extends Item>... items )
|
||||
{
|
||||
Identifier id = new Identifier( ComputerCraft.MOD_ID, name );
|
||||
ResourceLocation id = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
||||
for( Supplier<? extends Item> item : items )
|
||||
{
|
||||
FabricModelPredicateProviderRegistry.register( item.get(), id, getter );
|
||||
|
@@ -6,21 +6,26 @@
|
||||
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix3f;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.shared.ComputerCraftRegistry;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
@Environment( EnvType.CLIENT )
|
||||
public final class CableHighlightRenderer
|
||||
@@ -29,21 +34,21 @@ public final class CableHighlightRenderer
|
||||
{
|
||||
}
|
||||
|
||||
public static boolean drawHighlight( MatrixStack stack, VertexConsumer consumer, Entity entity, double d, double e, double f, BlockPos pos,
|
||||
public static boolean drawHighlight( PoseStack stack, VertexConsumer consumer, Entity entity, double d, double e, double f, BlockPos pos,
|
||||
BlockState state )
|
||||
{
|
||||
Camera info = MinecraftClient.getInstance().gameRenderer.getCamera();
|
||||
Camera info = Minecraft.getInstance().gameRenderer.getMainCamera();
|
||||
|
||||
// We only care about instances with both cable and modem.
|
||||
if( state.getBlock() != ComputerCraftRegistry.ModBlocks.CABLE || state.get( BlockCable.MODEM )
|
||||
.getFacing() == null || !state.get( BlockCable.CABLE ) )
|
||||
if( state.getBlock() != ComputerCraftRegistry.ModBlocks.CABLE || state.getValue( BlockCable.MODEM )
|
||||
.getFacing() == null || !state.getValue( BlockCable.CABLE ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
HitResult hitResult = MinecraftClient.getInstance().crosshairTarget;
|
||||
HitResult hitResult = Minecraft.getInstance().hitResult;
|
||||
|
||||
Vec3d hitPos = hitResult != null ? hitResult.getPos() : new Vec3d( d, e, f );
|
||||
Vec3 hitPos = hitResult != null ? hitResult.getLocation() : new Vec3( d, e, f );
|
||||
|
||||
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ),
|
||||
hitPos.subtract( pos.getX(),
|
||||
@@ -51,19 +56,19 @@ public final class CableHighlightRenderer
|
||||
pos.getZ() ) ) ? CableShapes.getModemShape( state ) : CableShapes.getCableShape(
|
||||
state );
|
||||
|
||||
Vec3d cameraPos = info.getPos();
|
||||
Vec3 cameraPos = info.getPosition();
|
||||
|
||||
double xOffset = pos.getX() - cameraPos.getX();
|
||||
double yOffset = pos.getY() - cameraPos.getY();
|
||||
double zOffset = pos.getZ() - cameraPos.getZ();
|
||||
Matrix4f matrix4f = stack.peek()
|
||||
.getModel();
|
||||
Matrix3f normal = stack.peek().getNormal();
|
||||
shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> {
|
||||
double xOffset = pos.getX() - cameraPos.x();
|
||||
double yOffset = pos.getY() - cameraPos.y();
|
||||
double zOffset = pos.getZ() - cameraPos.z();
|
||||
Matrix4f matrix4f = stack.last()
|
||||
.pose();
|
||||
Matrix3f normal = stack.last().normal();
|
||||
shape.forAllEdges( ( x1, y1, z1, x2, y2, z2 ) -> {
|
||||
float xDelta = (float) (x2 - x1);
|
||||
float yDelta = (float) (y2 - y1);
|
||||
float zDelta = (float) (z2 - z1);
|
||||
float len = MathHelper.sqrt( xDelta * xDelta + yDelta * yDelta + zDelta * zDelta );
|
||||
float len = Mth.sqrt( xDelta * xDelta + yDelta * yDelta + zDelta * zDelta );
|
||||
xDelta = xDelta / len;
|
||||
yDelta = yDelta / len;
|
||||
zDelta = zDelta / len;
|
||||
@@ -71,11 +76,11 @@ public final class CableHighlightRenderer
|
||||
consumer.vertex( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) )
|
||||
.color( 0, 0, 0, 0.4f )
|
||||
.normal( normal, xDelta, yDelta, zDelta )
|
||||
.next();
|
||||
.endVertex();
|
||||
consumer.vertex( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) )
|
||||
.color( 0, 0, 0, 0.4f )
|
||||
.normal( normal, xDelta, yDelta, zDelta )
|
||||
.next();
|
||||
.endVertex();
|
||||
} );
|
||||
|
||||
return true;
|
||||
|
@@ -5,23 +5,22 @@
|
||||
*/
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.Tessellator;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class ComputerBorderRenderer
|
||||
{
|
||||
public static final Identifier BACKGROUND_NORMAL = new Identifier( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" );
|
||||
public static final Identifier BACKGROUND_ADVANCED = new Identifier( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" );
|
||||
public static final Identifier BACKGROUND_COMMAND = new Identifier( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" );
|
||||
public static final Identifier BACKGROUND_COLOUR = new Identifier( ComputerCraft.MOD_ID, "textures/gui/corners_colour.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_COMMAND = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" );
|
||||
public static final ResourceLocation BACKGROUND_COLOUR = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_colour.png" );
|
||||
/**
|
||||
* The margin between the terminal and its border.
|
||||
*/
|
||||
@@ -45,7 +44,7 @@ public class ComputerBorderRenderer
|
||||
|
||||
static
|
||||
{
|
||||
IDENTITY.loadIdentity();
|
||||
IDENTITY.setIdentity();
|
||||
}
|
||||
|
||||
private final Matrix4f transform;
|
||||
@@ -68,7 +67,7 @@ public class ComputerBorderRenderer
|
||||
|
||||
|
||||
@Nonnull
|
||||
public static Identifier getTexture( @Nonnull ComputerFamily family )
|
||||
public static ResourceLocation getTexture( @Nonnull ComputerFamily family )
|
||||
{
|
||||
switch( family )
|
||||
{
|
||||
@@ -82,11 +81,11 @@ public class ComputerBorderRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public static void render( Identifier location, int x, int y, int z, int light, int width, int height )
|
||||
public static void render( ResourceLocation location, int x, int y, int z, int light, int width, int height )
|
||||
{
|
||||
VertexConsumerProvider.Immediate source = VertexConsumerProvider.immediate( Tessellator.getInstance().getBuffer() );
|
||||
render( IDENTITY, source.getBuffer( RenderLayer.getText( location ) ), x, y, z, light, width, height, false, 1, 1, 1 );
|
||||
source.draw();
|
||||
MultiBufferSource.BufferSource source = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() );
|
||||
render( IDENTITY, source.getBuffer( RenderType.text( location ) ), x, y, z, light, width, height, false, 1, 1, 1 );
|
||||
source.endBatch();
|
||||
}
|
||||
|
||||
|
||||
@@ -144,23 +143,23 @@ public class ComputerBorderRenderer
|
||||
{
|
||||
builder.vertex( transform, x, y + height, z )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
builder.vertex( transform, x + width, y + height, z )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
builder.vertex( transform, x + width, y, z )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
builder.vertex( transform, x, y, z )
|
||||
.color( r, g, b, 1.0f )
|
||||
.texture( u * TEX_SCALE, v * TEX_SCALE )
|
||||
.light( light )
|
||||
.next();
|
||||
.uv( u * TEX_SCALE, v * TEX_SCALE )
|
||||
.uv2( light )
|
||||
.endVertex();
|
||||
}
|
||||
}
|
||||
|
@@ -6,32 +6,32 @@
|
||||
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.fabric.mixin.HeldItemRendererAccess;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Arm;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ItemInHandRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
@Environment( EnvType.CLIENT )
|
||||
public abstract class ItemMapLikeRenderer
|
||||
{
|
||||
public void renderItemFirstPerson(
|
||||
MatrixStack transform, VertexConsumerProvider render, int lightTexture, Hand hand, float pitch, float equipProgress,
|
||||
PoseStack transform, MultiBufferSource render, int lightTexture, InteractionHand hand, float pitch, float equipProgress,
|
||||
float swingProgress, ItemStack stack
|
||||
)
|
||||
{
|
||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||
Player player = Minecraft.getInstance().player;
|
||||
|
||||
transform.push();
|
||||
if( hand == Hand.MAIN_HAND && player.getOffHandStack().isEmpty() )
|
||||
transform.pushPose();
|
||||
if( hand == InteractionHand.MAIN_HAND && player.getOffhandItem().isEmpty() )
|
||||
{
|
||||
renderItemFirstPersonCenter( transform, render, lightTexture, pitch, equipProgress, swingProgress, stack );
|
||||
}
|
||||
@@ -40,12 +40,12 @@ public abstract class ItemMapLikeRenderer
|
||||
renderItemFirstPersonSide( transform,
|
||||
render,
|
||||
lightTexture,
|
||||
hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(),
|
||||
hand == InteractionHand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(),
|
||||
equipProgress,
|
||||
swingProgress,
|
||||
stack );
|
||||
}
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,34 +59,34 @@ public abstract class ItemMapLikeRenderer
|
||||
* @param swingProgress The swing progress of this item
|
||||
* @param stack The stack to render
|
||||
*/
|
||||
private void renderItemFirstPersonCenter( MatrixStack transform, VertexConsumerProvider render, int combinedLight, float pitch, float equipProgress,
|
||||
private void renderItemFirstPersonCenter( PoseStack transform, MultiBufferSource render, int combinedLight, float pitch, float equipProgress,
|
||||
float swingProgress, ItemStack stack )
|
||||
{
|
||||
MinecraftClient minecraft = MinecraftClient.getInstance();
|
||||
HeldItemRenderer renderer = minecraft.getHeldItemRenderer();
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
ItemInHandRenderer renderer = minecraft.getItemInHandRenderer();
|
||||
|
||||
// Setup the appropriate transformations. This is just copied from the
|
||||
// corresponding method in ItemRenderer.
|
||||
float swingRt = MathHelper.sqrt( swingProgress );
|
||||
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
||||
float swingRt = Mth.sqrt( swingProgress );
|
||||
float tX = -0.2f * Mth.sin( swingProgress * (float) Math.PI );
|
||||
float tZ = -0.4f * Mth.sin( swingRt * (float) Math.PI );
|
||||
transform.translate( 0, -tX / 2, tZ );
|
||||
|
||||
HeldItemRendererAccess access = (HeldItemRendererAccess) renderer;
|
||||
float pitchAngle = access.callGetMapAngle( pitch );
|
||||
transform.translate( 0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
||||
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( pitchAngle * -85.0f ) );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( pitchAngle * -85.0f ) );
|
||||
if( !minecraft.player.isInvisible() )
|
||||
{
|
||||
transform.push();
|
||||
transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( 90.0F ) );
|
||||
access.callRenderArm( transform, render, combinedLight, Arm.RIGHT );
|
||||
access.callRenderArm( transform, render, combinedLight, Arm.LEFT );
|
||||
transform.pop();
|
||||
transform.pushPose();
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( 90.0F ) );
|
||||
access.callRenderArm( transform, render, combinedLight, HumanoidArm.RIGHT );
|
||||
access.callRenderArm( transform, render, combinedLight, HumanoidArm.LEFT );
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
||||
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( rX * 20.0F ) );
|
||||
float rX = Mth.sin( swingRt * (float) Math.PI );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( rX * 20.0F ) );
|
||||
transform.scale( 2.0F, 2.0F, 2.0F );
|
||||
|
||||
renderItem( transform, render, stack, combinedLight );
|
||||
@@ -103,39 +103,39 @@ public abstract class ItemMapLikeRenderer
|
||||
* @param swingProgress The swing progress of this item
|
||||
* @param stack The stack to render
|
||||
*/
|
||||
private void renderItemFirstPersonSide( MatrixStack transform, VertexConsumerProvider render, int combinedLight, Arm side, float equipProgress,
|
||||
private void renderItemFirstPersonSide( PoseStack transform, MultiBufferSource render, int combinedLight, HumanoidArm side, float equipProgress,
|
||||
float swingProgress, ItemStack stack )
|
||||
{
|
||||
MinecraftClient minecraft = MinecraftClient.getInstance();
|
||||
float offset = side == Arm.RIGHT ? 1f : -1f;
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
float offset = side == HumanoidArm.RIGHT ? 1f : -1f;
|
||||
transform.translate( offset * 0.125f, -0.125f, 0f );
|
||||
|
||||
// If the player is not invisible then render a single arm
|
||||
if( !minecraft.player.isInvisible() )
|
||||
{
|
||||
transform.push();
|
||||
transform.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( offset * 10f ) );
|
||||
((HeldItemRendererAccess) minecraft.getHeldItemRenderer())
|
||||
transform.pushPose();
|
||||
transform.mulPose( Vector3f.ZP.rotationDegrees( offset * 10f ) );
|
||||
((HeldItemRendererAccess) minecraft.getItemInHandRenderer())
|
||||
.callRenderArmHoldingItem( transform, render, combinedLight, equipProgress, swingProgress, side );
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
// Setup the appropriate transformations. This is just copied from the
|
||||
// corresponding method in ItemRenderer.
|
||||
transform.push();
|
||||
transform.pushPose();
|
||||
transform.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
||||
float f1 = MathHelper.sqrt( swingProgress );
|
||||
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
||||
float f1 = Mth.sqrt( swingProgress );
|
||||
float f2 = Mth.sin( f1 * (float) Math.PI );
|
||||
float f3 = -0.5f * f2;
|
||||
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
||||
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||
float f4 = 0.4f * Mth.sin( f1 * ((float) Math.PI * 2f) );
|
||||
float f5 = -0.3f * Mth.sin( swingProgress * (float) Math.PI );
|
||||
transform.translate( offset * f3, f4 - 0.3f * f2, f5 );
|
||||
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( f2 * -45f ) );
|
||||
transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( offset * f2 * -30f ) );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( f2 * -45f ) );
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) );
|
||||
|
||||
renderItem( transform, render, stack, combinedLight );
|
||||
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,5 +146,5 @@ public abstract class ItemMapLikeRenderer
|
||||
* @param stack The stack to render
|
||||
* @param light TODO rebase
|
||||
*/
|
||||
protected abstract void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light );
|
||||
protected abstract void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack, int light );
|
||||
}
|
||||
|
@@ -7,6 +7,13 @@
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
@@ -14,13 +21,12 @@ import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||
@@ -38,7 +44,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light )
|
||||
protected void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack, int light )
|
||||
{
|
||||
ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
|
||||
Terminal terminal = computer == null ? null : computer.getTerminal();
|
||||
@@ -60,9 +66,9 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
|
||||
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
||||
// in ItemRenderer
|
||||
transform.push();
|
||||
transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( 180f ) );
|
||||
transform.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( 180f ) );
|
||||
transform.pushPose();
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( 180f ) );
|
||||
transform.mulPose( Vector3f.ZP.rotationDegrees( 180f ) );
|
||||
transform.scale( 0.5f, 0.5f, 0.5f );
|
||||
|
||||
float scale = 0.75f / Math.max( width + BORDER * 2, height + BORDER * 2 + LIGHT_HEIGHT );
|
||||
@@ -74,8 +80,8 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
ComputerFamily family = item.getFamily();
|
||||
int frameColour = item.getColour( stack );
|
||||
|
||||
Matrix4f matrix = transform.peek()
|
||||
.getModel();
|
||||
Matrix4f matrix = transform.last()
|
||||
.pose();
|
||||
renderFrame( matrix, render, family, frameColour, light, width, height );
|
||||
|
||||
// Render the light
|
||||
@@ -92,7 +98,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
matrix, render.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH ),
|
||||
MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN
|
||||
);
|
||||
FixedWidthFontRenderer.drawBlocker( transform.peek().getModel(), render, 0, 0, width, height );
|
||||
FixedWidthFontRenderer.drawBlocker( transform.last().pose(), render, 0, 0, width, height );
|
||||
|
||||
}
|
||||
else
|
||||
@@ -100,23 +106,23 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
FixedWidthFontRenderer.drawEmptyTerminal( matrix, 0, 0, width, height );
|
||||
}
|
||||
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
private static void renderFrame( Matrix4f transform, VertexConsumerProvider render, ComputerFamily family, int colour, int light, int width, int height )
|
||||
private static void renderFrame( Matrix4f transform, MultiBufferSource render, ComputerFamily family, int colour, int light, int width, int height )
|
||||
{
|
||||
RenderSystem.enableBlend();
|
||||
MinecraftClient.getInstance()
|
||||
Minecraft.getInstance()
|
||||
.getTextureManager()
|
||||
.bindTexture( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) );
|
||||
.bindForSetup( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) );
|
||||
|
||||
Identifier texture = colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family );
|
||||
ResourceLocation texture = colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family );
|
||||
|
||||
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
||||
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
||||
float b = (colour & 0xFF) / 255.0f;
|
||||
|
||||
ComputerBorderRenderer.render( transform, render.getBuffer( RenderLayer.getText( texture ) ), 0, 0, 0, light, width, height, true, r, g, b );
|
||||
ComputerBorderRenderer.render( transform, render.getBuffer( RenderType.text( texture ) ), 0, 0, 0, light, width, height, true, r, g, b );
|
||||
}
|
||||
|
||||
private static void renderLight( Matrix4f transform, int colour, int width, int height )
|
||||
@@ -127,23 +133,23 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
||||
float b = (colour & 0xFF) / 255.0f;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin( VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR );
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuilder();
|
||||
buffer.begin( VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR );
|
||||
buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.next();
|
||||
.endVertex();
|
||||
buffer.vertex( transform, width, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.next();
|
||||
.endVertex();
|
||||
buffer.vertex( transform, width, height + BORDER / 2.0f, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.next();
|
||||
.endVertex();
|
||||
buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, 0 )
|
||||
.color( r, g, b, 1.0f )
|
||||
.next();
|
||||
.endVertex();
|
||||
|
||||
tessellator.draw();
|
||||
tessellator.end();
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
}
|
||||
|
@@ -7,11 +7,8 @@
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||
@@ -19,6 +16,10 @@ import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||
import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE;
|
||||
import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
/**
|
||||
* Emulates map and item-frame rendering for printouts.
|
||||
*/
|
||||
@@ -31,16 +32,16 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderItem( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light )
|
||||
protected void renderItem( PoseStack transform, MultiBufferSource render, ItemStack stack, int light )
|
||||
{
|
||||
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( 180f ) );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( 180f ) );
|
||||
transform.scale( 0.42f, 0.42f, -0.42f );
|
||||
transform.translate( -0.5f, -0.48f, 0.0f );
|
||||
|
||||
drawPrintout( transform, render, stack, light );
|
||||
}
|
||||
|
||||
private static void drawPrintout( MatrixStack transform, VertexConsumerProvider render, ItemStack stack, int light )
|
||||
private static void drawPrintout( PoseStack transform, MultiBufferSource render, ItemStack stack, int light )
|
||||
{
|
||||
int pages = ItemPrintout.getPageCount( stack );
|
||||
boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK;
|
||||
@@ -70,13 +71,13 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||
transform.scale( scale, scale, scale );
|
||||
transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
|
||||
|
||||
Matrix4f matrix = transform.peek()
|
||||
.getModel();
|
||||
Matrix4f matrix = transform.last()
|
||||
.pose();
|
||||
drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book, light );
|
||||
drawText( matrix, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, light, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) );
|
||||
}
|
||||
|
||||
public boolean renderInFrame( MatrixStack matrixStack, VertexConsumerProvider consumerProvider, ItemStack stack, int light )
|
||||
public boolean renderInFrame( PoseStack matrixStack, MultiBufferSource consumerProvider, ItemStack stack, int light )
|
||||
{
|
||||
if( !(stack.getItem() instanceof ItemPrintout) )
|
||||
{
|
||||
@@ -85,7 +86,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||
|
||||
// Move a little bit forward to ensure we're not clipping with the frame
|
||||
matrixStack.translate( 0.0f, 0.0f, -0.001f );
|
||||
matrixStack.multiply( Vec3f.POSITIVE_Z.getDegreesQuaternion( 180f ) );
|
||||
matrixStack.mulPose( Vector3f.ZP.rotationDegrees( 180f ) );
|
||||
matrixStack.scale( 0.95f, 0.95f, -0.95f );
|
||||
matrixStack.translate( -0.5f, -0.5f, 0.0f );
|
||||
|
||||
|
@@ -7,13 +7,12 @@ package dan200.computercraft.client.render;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.client.render.VertexFormatElement;
|
||||
import net.minecraft.client.render.VertexFormats;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Vector4f;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector4f;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -27,7 +26,7 @@ public final class ModelTransformer
|
||||
static
|
||||
{
|
||||
identity = new Matrix4f();
|
||||
identity.loadIdentity();
|
||||
identity.setIdentity();
|
||||
}
|
||||
|
||||
private ModelTransformer()
|
||||
@@ -36,7 +35,7 @@ public final class ModelTransformer
|
||||
|
||||
public static void transformQuadsTo( List<BakedQuad> output, List<BakedQuad> input, Matrix4f transform )
|
||||
{
|
||||
transformQuadsTo( VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL, output, input, transform );
|
||||
transformQuadsTo( DefaultVertexFormat.BLOCK, output, input, transform );
|
||||
}
|
||||
|
||||
public static void transformQuadsTo( VertexFormat format, List<BakedQuad> output, List<BakedQuad> input, Matrix4f transform )
|
||||
@@ -56,8 +55,8 @@ public final class ModelTransformer
|
||||
|
||||
private static BakedQuad doTransformQuad( VertexFormat format, BakedQuad quad, Matrix4f transform )
|
||||
{
|
||||
int[] vertexData = quad.getVertexData().clone();
|
||||
BakedQuad copy = new BakedQuad( vertexData, -1, quad.getFace(), quad.getSprite(), true );
|
||||
int[] vertexData = quad.getVertices().clone();
|
||||
BakedQuad copy = new BakedQuad( vertexData, -1, quad.getDirection(), quad.getSprite(), true );
|
||||
|
||||
int offsetBytes = 0;
|
||||
for( int v = 0; v < 4; ++v )
|
||||
@@ -65,7 +64,7 @@ public final class ModelTransformer
|
||||
for( VertexFormatElement element : format.getElements() ) // For each vertex element
|
||||
{
|
||||
int start = offsetBytes / Integer.BYTES;
|
||||
if( element.getType() == VertexFormatElement.Type.POSITION && element.getDataType() == VertexFormatElement.DataType.FLOAT ) // When we find a position element
|
||||
if( element.getUsage() == VertexFormatElement.Usage.POSITION && element.getType() == VertexFormatElement.Type.FLOAT ) // When we find a position element
|
||||
{
|
||||
Vector4f pos = new Vector4f( Float.intBitsToFloat( vertexData[start] ),
|
||||
Float.intBitsToFloat( vertexData[start + 1] ),
|
||||
@@ -76,11 +75,11 @@ public final class ModelTransformer
|
||||
pos.transform( transform );
|
||||
|
||||
// Insert the position
|
||||
vertexData[start] = Float.floatToRawIntBits( pos.getX() );
|
||||
vertexData[start + 1] = Float.floatToRawIntBits( pos.getY() );
|
||||
vertexData[start + 2] = Float.floatToRawIntBits( pos.getZ() );
|
||||
vertexData[start] = Float.floatToRawIntBits( pos.x() );
|
||||
vertexData[start + 1] = Float.floatToRawIntBits( pos.y() );
|
||||
vertexData[start + 2] = Float.floatToRawIntBits( pos.z() );
|
||||
}
|
||||
offsetBytes += element.getByteLength();
|
||||
offsetBytes += element.getByteSize();
|
||||
}
|
||||
}
|
||||
return copy;
|
||||
|
@@ -9,17 +9,22 @@ package dan200.computercraft.client.render;
|
||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import java.util.EnumSet;
|
||||
import static net.minecraft.util.math.Direction.*;
|
||||
import static net.minecraft.core.Direction.*;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix3f;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
||||
/**
|
||||
* Overrides monitor highlighting to only render the outline of the <em>whole</em> monitor, rather than the current block. This means you do not get an
|
||||
@@ -32,15 +37,15 @@ public final class MonitorHighlightRenderer
|
||||
{
|
||||
}
|
||||
|
||||
public static boolean drawHighlight( MatrixStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos pos, BlockState blockState )
|
||||
public static boolean drawHighlight( PoseStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos pos, BlockState blockState )
|
||||
{
|
||||
// Preserve normal behaviour when crouching.
|
||||
if( entity.isInSneakingPose() )
|
||||
if( entity.isCrouching() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = entity.getEntityWorld();
|
||||
Level world = entity.getCommandSenderWorld();
|
||||
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( !(tile instanceof TileMonitor monitor) )
|
||||
@@ -71,15 +76,15 @@ public final class MonitorHighlightRenderer
|
||||
faces.remove( monitor.getDown() );
|
||||
}
|
||||
|
||||
Vec3d cameraPos = MinecraftClient.getInstance().gameRenderer.getCamera()
|
||||
.getPos();
|
||||
matrixStack.push();
|
||||
matrixStack.translate( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() );
|
||||
Vec3 cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera()
|
||||
.getPosition();
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate( pos.getX() - cameraPos.x(), pos.getY() - cameraPos.y(), pos.getZ() - cameraPos.z() );
|
||||
|
||||
// I wish I could think of a better way to do this
|
||||
Matrix4f transform = matrixStack.peek()
|
||||
.getModel();
|
||||
Matrix3f normal = matrixStack.peek().getNormal();
|
||||
Matrix4f transform = matrixStack.last()
|
||||
.pose();
|
||||
Matrix3f normal = matrixStack.last().normal();
|
||||
if( faces.contains( NORTH ) || faces.contains( WEST ) )
|
||||
{
|
||||
line( vertexConsumer, transform, normal, 0, 0, 0, UP );
|
||||
@@ -129,7 +134,7 @@ public final class MonitorHighlightRenderer
|
||||
line( vertexConsumer, transform, normal, 1, 1, 0, SOUTH );
|
||||
}
|
||||
|
||||
matrixStack.pop();
|
||||
matrixStack.popPose();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -138,11 +143,11 @@ public final class MonitorHighlightRenderer
|
||||
{
|
||||
buffer.vertex( transform, x, y, z )
|
||||
.color( 0, 0, 0, 0.4f )
|
||||
.normal( normal, direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ() )
|
||||
.next();
|
||||
buffer.vertex( transform, x + direction.getOffsetX(), y + direction.getOffsetY(), z + direction.getOffsetZ() )
|
||||
.normal( normal, direction.getStepX(), direction.getStepY(), direction.getStepZ() )
|
||||
.endVertex();
|
||||
buffer.vertex( transform, x + direction.getStepX(), y + direction.getStepY(), z + direction.getStepZ() )
|
||||
.color( 0, 0, 0, 0.4f )
|
||||
.normal( normal, direction.getOffsetX(), direction.getOffsetY(), direction.getOffsetZ() )
|
||||
.next();
|
||||
.normal( normal, direction.getStepX(), direction.getStepY(), direction.getStepZ() )
|
||||
.endVertex();
|
||||
}
|
||||
}
|
||||
|
@@ -5,40 +5,40 @@
|
||||
*/
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.shaders.Uniform;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.gl.GlUniform;
|
||||
import net.minecraft.client.render.Shader;
|
||||
import net.minecraft.client.render.VertexFormat;
|
||||
import net.minecraft.resource.ResourceFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.server.packs.resources.ResourceProvider;
|
||||
import java.io.IOException;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class MonitorTextureBufferShader extends Shader
|
||||
public class MonitorTextureBufferShader extends ShaderInstance
|
||||
{
|
||||
static final int TEXTURE_INDEX = GL13.GL_TEXTURE3;
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private final GlUniform palette;
|
||||
private final GlUniform width;
|
||||
private final GlUniform height;
|
||||
private final Uniform palette;
|
||||
private final Uniform width;
|
||||
private final Uniform height;
|
||||
|
||||
public MonitorTextureBufferShader( ResourceFactory factory, String name, VertexFormat format ) throws IOException
|
||||
public MonitorTextureBufferShader( ResourceProvider factory, String name, VertexFormat format ) throws IOException
|
||||
{
|
||||
super( factory, name, format );
|
||||
|
||||
width = getUniformChecked( "Width" );
|
||||
height = getUniformChecked( "Height" );
|
||||
palette = new GlUniform( "Palette", GlUniform.field_32044 /* UT_FLOAT3 */, 16 * 3, this );
|
||||
palette = new Uniform( "Palette", Uniform.UT_FLOAT3 /* UT_FLOAT3 */, 16 * 3, this );
|
||||
updateUniformLocation( palette );
|
||||
|
||||
GlUniform tbo = getUniformChecked( "Tbo" );
|
||||
Uniform tbo = getUniformChecked( "Tbo" );
|
||||
if( tbo != null ) tbo.set( TEXTURE_INDEX - GL13.GL_TEXTURE0 );
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MonitorTextureBufferShader extends Shader
|
||||
{
|
||||
if( this.palette == null ) return;
|
||||
|
||||
FloatBuffer paletteBuffer = this.palette.getFloatData();
|
||||
FloatBuffer paletteBuffer = this.palette.getFloatBuffer();
|
||||
paletteBuffer.rewind();
|
||||
for( int i = 0; i < 16; i++ )
|
||||
{
|
||||
@@ -71,9 +71,9 @@ public class MonitorTextureBufferShader extends Shader
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind()
|
||||
public void apply()
|
||||
{
|
||||
super.bind();
|
||||
super.apply();
|
||||
palette.upload();
|
||||
}
|
||||
|
||||
@@ -84,23 +84,23 @@ public class MonitorTextureBufferShader extends Shader
|
||||
super.close();
|
||||
}
|
||||
|
||||
private void updateUniformLocation( GlUniform uniform )
|
||||
private void updateUniformLocation( Uniform uniform )
|
||||
{
|
||||
int id = GlUniform.getUniformLocation( getProgramRef(), uniform.getName() );
|
||||
int id = Uniform.glGetUniformLocation( getId(), uniform.getName() );
|
||||
if( id == -1 )
|
||||
{
|
||||
LOGGER.warn( "Shader {} could not find uniform named {} in the specified shader program.", getName(), uniform.getName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
uniform.setLoc( id );
|
||||
uniform.setLocation( id );
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GlUniform getUniformChecked( String name )
|
||||
private Uniform getUniformChecked( String name )
|
||||
{
|
||||
GlUniform uniform = getUniform( name );
|
||||
Uniform uniform = getUniform( name );
|
||||
if( uniform == null )
|
||||
{
|
||||
LOGGER.warn( "Monitor shader {} should have uniform {}, but it was not present.", getName(), name );
|
||||
|
@@ -9,13 +9,14 @@ package dan200.computercraft.client.render;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAGE;
|
||||
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
|
||||
public final class PrintoutRenderer
|
||||
{
|
||||
/**
|
||||
@@ -48,7 +49,7 @@ public final class PrintoutRenderer
|
||||
|
||||
private PrintoutRenderer() {}
|
||||
|
||||
public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours )
|
||||
public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours )
|
||||
{
|
||||
VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT );
|
||||
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
|
||||
@@ -68,7 +69,7 @@ public final class PrintoutRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawText( Matrix4f transform, VertexConsumerProvider renderer, int x, int y, int start, int light, String[] text, String[] colours )
|
||||
public static void drawText( Matrix4f transform, MultiBufferSource renderer, int x, int y, int start, int light, String[] text, String[] colours )
|
||||
{
|
||||
VertexConsumer buffer = renderer.getBuffer( RenderTypes.PRINTOUT_TEXT );
|
||||
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
|
||||
@@ -88,7 +89,7 @@ public final class PrintoutRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawBorder( Matrix4f transform, VertexConsumerProvider renderer, float x, float y, float z, int page, int pages, boolean isBook, int light )
|
||||
public static void drawBorder( Matrix4f transform, MultiBufferSource renderer, float x, float y, float z, int page, int pages, boolean isBook, int light )
|
||||
{
|
||||
int leftPages = page;
|
||||
int rightPages = pages - page - 1;
|
||||
@@ -173,6 +174,6 @@ public final class PrintoutRenderer
|
||||
|
||||
private static void vertex( VertexConsumer buffer, Matrix4f matrix, float x, float y, float z, float u, float v, int light )
|
||||
{
|
||||
buffer.vertex( matrix, x, y, z ).color( 255, 255, 255, 255 ).texture( u, v ).light( light ).next();
|
||||
buffer.vertex( matrix, x, y, z ).color( 255, 255, 255, 255 ).uv( u, v ).uv2( light ).endVertex();
|
||||
}
|
||||
}
|
||||
|
@@ -5,10 +5,14 @@
|
||||
*/
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.minecraft.client.renderer.RenderStateShard;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -21,17 +25,17 @@ public class RenderTypes
|
||||
public static MonitorTextureBufferShader monitorTboShader;
|
||||
|
||||
@Nullable
|
||||
public static Shader terminalShader;
|
||||
public static ShaderInstance terminalShader;
|
||||
|
||||
public static final RenderLayer TERMINAL_WITHOUT_DEPTH = Types.TERMINAL_WITHOUT_DEPTH;
|
||||
public static final RenderLayer MONITOR_TBO = Types.MONITOR_TBO;
|
||||
public static final RenderLayer TERMINAL_BLOCKER = Types.BLOCKER;
|
||||
public static final RenderLayer TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH;
|
||||
public static final RenderLayer PRINTOUT_TEXT = Types.PRINTOUT_TEXT;
|
||||
public static final RenderType TERMINAL_WITHOUT_DEPTH = Types.TERMINAL_WITHOUT_DEPTH;
|
||||
public static final RenderType MONITOR_TBO = Types.MONITOR_TBO;
|
||||
public static final RenderType TERMINAL_BLOCKER = Types.BLOCKER;
|
||||
public static final RenderType TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH;
|
||||
public static final RenderType PRINTOUT_TEXT = Types.PRINTOUT_TEXT;
|
||||
|
||||
public static final RenderLayer PRINTOUT_BACKGROUND = RenderLayer.getText( new Identifier( "computercraft", "textures/gui/printout.png" ) );
|
||||
public static final RenderType PRINTOUT_BACKGROUND = RenderType.text( new ResourceLocation( "computercraft", "textures/gui/printout.png" ) );
|
||||
|
||||
public static final RenderLayer POSITION_COLOR = Types.POSITION_COLOR;
|
||||
public static final RenderType POSITION_COLOR = Types.POSITION_COLOR;
|
||||
|
||||
@Nonnull
|
||||
static MonitorTextureBufferShader getMonitorTextureBufferShader()
|
||||
@@ -41,72 +45,72 @@ public class RenderTypes
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
static Shader getTerminalShader()
|
||||
static ShaderInstance getTerminalShader()
|
||||
{
|
||||
if( terminalShader == null ) throw new NullPointerException( "MonitorTboShader has not been registered" );
|
||||
return terminalShader;
|
||||
}
|
||||
|
||||
private static final class Types extends RenderPhase
|
||||
private static final class Types extends RenderStateShard
|
||||
{
|
||||
private static final VertexFormat.DrawMode GL_MODE = VertexFormat.DrawMode.TRIANGLES;
|
||||
private static final VertexFormat FORMAT = VertexFormats.POSITION_COLOR_TEXTURE;
|
||||
private static final Shader TERM_SHADER = new Shader( RenderTypes::getTerminalShader );
|
||||
private static final VertexFormat.Mode GL_MODE = VertexFormat.Mode.TRIANGLES;
|
||||
private static final VertexFormat FORMAT = DefaultVertexFormat.POSITION_COLOR_TEX;
|
||||
private static final ShaderStateShard TERM_SHADER = new ShaderStateShard( RenderTypes::getTerminalShader );
|
||||
|
||||
private static final RenderPhase.Texture TERM_FONT_TEXTURE = new RenderPhase.Texture(
|
||||
private static final RenderStateShard.TextureStateShard TERM_FONT_TEXTURE = new RenderStateShard.TextureStateShard(
|
||||
FixedWidthFontRenderer.FONT,
|
||||
false, false // blur, minimap
|
||||
);
|
||||
|
||||
public static final RenderLayer MONITOR_TBO = RenderLayer.of( "monitor_tbo", VertexFormats.POSITION_TEXTURE, VertexFormat.DrawMode.TRIANGLE_STRIP, 128, false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture( TERM_FONT_TEXTURE ) // blur, minimap
|
||||
.shader( new RenderPhase.Shader( RenderTypes::getMonitorTextureBufferShader ) )
|
||||
.writeMaskState( RenderLayer.ALL_MASK )
|
||||
.build( false ) );
|
||||
public static final RenderType MONITOR_TBO = RenderType.create( "monitor_tbo", DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.TRIANGLE_STRIP, 128, false, false, // useDelegate, needsSorting
|
||||
RenderType.CompositeState.builder()
|
||||
.setTextureState( TERM_FONT_TEXTURE ) // blur, minimap
|
||||
.setShaderState( new RenderStateShard.ShaderStateShard( RenderTypes::getMonitorTextureBufferShader ) )
|
||||
.setWriteMaskState( RenderType.COLOR_DEPTH_WRITE )
|
||||
.createCompositeState( false ) );
|
||||
|
||||
static final RenderLayer TERMINAL_WITHOUT_DEPTH = RenderLayer.of(
|
||||
static final RenderType TERMINAL_WITHOUT_DEPTH = RenderType.create(
|
||||
"terminal_without_depth", FORMAT, GL_MODE, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture( TERM_FONT_TEXTURE )
|
||||
.shader( TERM_SHADER )
|
||||
.writeMaskState( COLOR_MASK )
|
||||
.build( false )
|
||||
RenderType.CompositeState.builder()
|
||||
.setTextureState( TERM_FONT_TEXTURE )
|
||||
.setShaderState( TERM_SHADER )
|
||||
.setWriteMaskState( COLOR_WRITE )
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
static final RenderLayer BLOCKER = RenderLayer.of( "terminal_blocker", FORMAT, GL_MODE, 256, false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture( TERM_FONT_TEXTURE )
|
||||
.shader( TERM_SHADER )
|
||||
.writeMaskState( DEPTH_MASK )
|
||||
.build( false ) );
|
||||
static final RenderType BLOCKER = RenderType.create( "terminal_blocker", FORMAT, GL_MODE, 256, false, false, // useDelegate, needsSorting
|
||||
RenderType.CompositeState.builder()
|
||||
.setTextureState( TERM_FONT_TEXTURE )
|
||||
.setShaderState( TERM_SHADER )
|
||||
.setWriteMaskState( DEPTH_WRITE )
|
||||
.createCompositeState( false ) );
|
||||
|
||||
static final RenderLayer TERMINAL_WITH_DEPTH = RenderLayer.of(
|
||||
static final RenderType TERMINAL_WITH_DEPTH = RenderType.create(
|
||||
"terminal_with_depth", FORMAT, GL_MODE, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture( TERM_FONT_TEXTURE )
|
||||
.shader( TERM_SHADER )
|
||||
.build( false )
|
||||
RenderType.CompositeState.builder()
|
||||
.setTextureState( TERM_FONT_TEXTURE )
|
||||
.setShaderState( TERM_SHADER )
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
static final RenderLayer PRINTOUT_TEXT = RenderLayer.of(
|
||||
"printout_text", VertexFormats.POSITION_COLOR_TEXTURE_LIGHT, GL_MODE, 1024,
|
||||
static final RenderType PRINTOUT_TEXT = RenderType.create(
|
||||
"printout_text", DefaultVertexFormat.POSITION_COLOR_TEX_LIGHTMAP, GL_MODE, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.texture( TERM_FONT_TEXTURE )
|
||||
.shader( RenderPhase.TEXT_SHADER )
|
||||
.lightmap( RenderPhase.ENABLE_LIGHTMAP )
|
||||
.build( false )
|
||||
RenderType.CompositeState.builder()
|
||||
.setTextureState( TERM_FONT_TEXTURE )
|
||||
.setShaderState( RenderStateShard.RENDERTYPE_TEXT_SHADER )
|
||||
.setLightmapState( RenderStateShard.LIGHTMAP )
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
static final RenderLayer POSITION_COLOR = RenderLayer.of(
|
||||
"position_color", VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.QUADS, 128,
|
||||
static final RenderType POSITION_COLOR = RenderType.create(
|
||||
"position_color", DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS, 128,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.shader( COLOR_SHADER )
|
||||
.build( false )
|
||||
RenderType.CompositeState.builder()
|
||||
.setShaderState( POSITION_COLOR_SHADER )
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
private Types( String name, Runnable setup, Runnable destroy )
|
||||
|
@@ -8,6 +8,14 @@ package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexBuffer;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
@@ -18,11 +26,13 @@ import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.DirectionUtil;
|
||||
import net.minecraft.client.gl.VertexBuffer;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.math.*;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
@@ -32,7 +42,7 @@ import javax.annotation.Nonnull;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
|
||||
import static net.minecraft.client.util.GlAllocationUtils.allocateByteBuffer;
|
||||
import static com.mojang.blaze3d.platform.MemoryTracker.create;
|
||||
|
||||
public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonitor>
|
||||
{
|
||||
@@ -40,16 +50,16 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
* {@link TileMonitor#RENDER_MARGIN}, but a tiny bit of additional padding to ensure that there is no space between the monitor frame and contents.
|
||||
*/
|
||||
private static final float MARGIN = (float) (TileMonitor.RENDER_MARGIN * 1.1);
|
||||
private static final Matrix4f IDENTITY = AffineTransformation.identity()
|
||||
private static final Matrix4f IDENTITY = Transformation.identity()
|
||||
.getMatrix();
|
||||
private static ByteBuffer tboContents;
|
||||
|
||||
public TileEntityMonitorRenderer( BlockEntityRendererFactory.Context context )
|
||||
public TileEntityMonitorRenderer( BlockEntityRendererProvider.Context context )
|
||||
{
|
||||
// super( context );
|
||||
}
|
||||
@Override
|
||||
public void render( @Nonnull TileMonitor monitor, float partialTicks, @Nonnull MatrixStack transform, @Nonnull VertexConsumerProvider renderer,
|
||||
public void render( @Nonnull TileMonitor monitor, float partialTicks, @Nonnull PoseStack transform, @Nonnull MultiBufferSource renderer,
|
||||
int lightmapCoord, int overlayLight )
|
||||
{
|
||||
// Render from the origin monitor
|
||||
@@ -57,7 +67,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
|
||||
if( originTerminal == null ) return;
|
||||
TileMonitor origin = originTerminal.getOrigin();
|
||||
BlockPos monitorPos = monitor.getPos();
|
||||
BlockPos monitorPos = monitor.getBlockPos();
|
||||
|
||||
// Ensure each monitor terminal is rendered only once. We allow rendering a specific tile
|
||||
// multiple times in a single frame to ensure compatibility with shaders which may run a
|
||||
@@ -71,22 +81,22 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
originTerminal.lastRenderFrame = renderFrame;
|
||||
originTerminal.lastRenderPos = monitorPos;
|
||||
|
||||
BlockPos originPos = origin.getPos();
|
||||
BlockPos originPos = origin.getBlockPos();
|
||||
|
||||
// Determine orientation
|
||||
Direction dir = origin.getDirection();
|
||||
Direction front = origin.getFront();
|
||||
float yaw = dir.asRotation();
|
||||
float yaw = dir.toYRot();
|
||||
float pitch = DirectionUtil.toPitchAngle( front );
|
||||
|
||||
// Setup initial transform
|
||||
transform.push();
|
||||
transform.pushPose();
|
||||
transform.translate( originPos.getX() - monitorPos.getX() + 0.5,
|
||||
originPos.getY() - monitorPos.getY() + 0.5,
|
||||
originPos.getZ() - monitorPos.getZ() + 0.5 );
|
||||
|
||||
transform.multiply( Vec3f.NEGATIVE_Y.getDegreesQuaternion( yaw ) );
|
||||
transform.multiply( Vec3f.POSITIVE_X.getDegreesQuaternion( pitch ) );
|
||||
transform.mulPose( Vector3f.YN.rotationDegrees( yaw ) );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( pitch ) );
|
||||
transform.translate( -0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
|
||||
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0,
|
||||
0.50 );
|
||||
@@ -102,10 +112,10 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
int pixelWidth = width * FONT_WIDTH, pixelHeight = height * FONT_HEIGHT;
|
||||
double xScale = xSize / pixelWidth;
|
||||
double yScale = ySize / pixelHeight;
|
||||
transform.push();
|
||||
transform.pushPose();
|
||||
transform.scale( (float) xScale, (float) -yScale, 1.0f );
|
||||
|
||||
Matrix4f matrix = transform.peek().getModel();
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
|
||||
renderTerminal( renderer, matrix, originTerminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale) );
|
||||
|
||||
@@ -113,21 +123,21 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
// reasonable.
|
||||
FixedWidthFontRenderer.drawCursor( matrix, renderer.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH ), 0, 0, terminal, !originTerminal.isColour() );
|
||||
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
|
||||
// Draw the background blocker
|
||||
FixedWidthFontRenderer.drawBlocker(
|
||||
transform.peek().getModel(), renderer,
|
||||
transform.last().pose(), renderer,
|
||||
-MARGIN, MARGIN,
|
||||
(float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2)
|
||||
);
|
||||
|
||||
renderer.getBuffer( RenderLayer.getSolid() );
|
||||
renderer.getBuffer( RenderType.solid() );
|
||||
}
|
||||
else
|
||||
{
|
||||
FixedWidthFontRenderer.drawEmptyTerminal( transform.peek()
|
||||
.getModel(),
|
||||
FixedWidthFontRenderer.drawEmptyTerminal( transform.last()
|
||||
.pose(),
|
||||
renderer,
|
||||
-MARGIN,
|
||||
MARGIN,
|
||||
@@ -135,10 +145,10 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
(float) -(ySize + MARGIN * 2) );
|
||||
}
|
||||
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
private static void renderTerminal( VertexConsumerProvider renderer, Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin )
|
||||
private static void renderTerminal( MultiBufferSource renderer, Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin )
|
||||
{
|
||||
Terminal terminal = monitor.getTerminal();
|
||||
|
||||
@@ -162,7 +172,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
int size = width * height * 3;
|
||||
if( tboContents == null || tboContents.capacity() < size )
|
||||
{
|
||||
tboContents = allocateByteBuffer( size );
|
||||
tboContents = create( size );
|
||||
}
|
||||
|
||||
ByteBuffer monitorBuffer = tboContents;
|
||||
@@ -207,9 +217,9 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
VertexBuffer vbo = monitor.buffer;
|
||||
if( redraw )
|
||||
{
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder builder = tessellator.getBuffer();
|
||||
builder.begin( RenderTypes.TERMINAL_WITHOUT_DEPTH.getDrawMode(), RenderTypes.TERMINAL_WITHOUT_DEPTH.getVertexFormat() );
|
||||
Tesselator tessellator = Tesselator.getInstance();
|
||||
BufferBuilder builder = tessellator.getBuilder();
|
||||
builder.begin( RenderTypes.TERMINAL_WITHOUT_DEPTH.mode(), RenderTypes.TERMINAL_WITHOUT_DEPTH.format() );
|
||||
FixedWidthFontRenderer.drawTerminalWithoutCursor( IDENTITY,
|
||||
builder,
|
||||
0,
|
||||
@@ -227,8 +237,8 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
|
||||
renderer.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH );
|
||||
|
||||
RenderTypes.TERMINAL_WITHOUT_DEPTH.startDrawing();
|
||||
vbo.setShader( matrix, RenderSystem.getProjectionMatrix(), RenderTypes.getTerminalShader() );
|
||||
RenderTypes.TERMINAL_WITHOUT_DEPTH.setupRenderState();
|
||||
vbo.drawWithShader( matrix, RenderSystem.getProjectionMatrix(), RenderTypes.getTerminalShader() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,11 +246,11 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
private static void tboVertex( VertexConsumer builder, Matrix4f matrix, float x, float y )
|
||||
{
|
||||
// We encode position in the UV, as that's not transformed by the matrix.
|
||||
builder.vertex( matrix, x, y, 0 ).texture( x, y ).next();
|
||||
builder.vertex( matrix, x, y, 0 ).uv( x, y ).endVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRenderDistance()
|
||||
public int getViewDistance()
|
||||
{
|
||||
return ComputerCraft.monitorDistance;
|
||||
}
|
||||
|
@@ -5,6 +5,10 @@
|
||||
*/
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
@@ -13,48 +17,43 @@ import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||
import dan200.computercraft.shared.util.DirectionUtil;
|
||||
import dan200.computercraft.shared.util.Holiday;
|
||||
import dan200.computercraft.shared.util.HolidayUtil;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.render.TexturedRenderLayers;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.BakedModelManager;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.Sheets;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
||||
{
|
||||
private static final ModelIdentifier NORMAL_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_normal", "inventory" );
|
||||
private static final ModelIdentifier ADVANCED_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_advanced", "inventory" );
|
||||
private static final ModelIdentifier COLOUR_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_colour", "inventory" );
|
||||
private static final ModelIdentifier ELF_OVERLAY_MODEL = new ModelIdentifier( "computercraft:turtle_elf_overlay", "inventory" );
|
||||
private static final ModelResourceLocation NORMAL_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_normal", "inventory" );
|
||||
private static final ModelResourceLocation ADVANCED_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_advanced", "inventory" );
|
||||
private static final ModelResourceLocation COLOUR_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_colour", "inventory" );
|
||||
private static final ModelResourceLocation ELF_OVERLAY_MODEL = new ModelResourceLocation( "computercraft:turtle_elf_overlay", "inventory" );
|
||||
|
||||
private final Random random = new Random( 0 );
|
||||
|
||||
BlockEntityRenderDispatcher renderer;
|
||||
|
||||
public TileEntityTurtleRenderer( BlockEntityRendererFactory.Context context )
|
||||
public TileEntityTurtleRenderer( BlockEntityRendererProvider.Context context )
|
||||
{
|
||||
renderer = context.getRenderDispatcher();
|
||||
renderer = context.getBlockEntityRenderDispatcher();
|
||||
}
|
||||
|
||||
public static ModelIdentifier getTurtleModel( ComputerFamily family, boolean coloured )
|
||||
public static ModelResourceLocation getTurtleModel( ComputerFamily family, boolean coloured )
|
||||
{
|
||||
switch( family )
|
||||
{
|
||||
@@ -66,11 +65,11 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
||||
}
|
||||
}
|
||||
|
||||
public static ModelIdentifier getTurtleOverlayModel( Identifier overlay, boolean christmas )
|
||||
public static ModelResourceLocation getTurtleOverlayModel( ResourceLocation overlay, boolean christmas )
|
||||
{
|
||||
if( overlay != null )
|
||||
{
|
||||
return new ModelIdentifier( overlay, "inventory" );
|
||||
return new ModelResourceLocation( overlay, "inventory" );
|
||||
}
|
||||
if( christmas )
|
||||
{
|
||||
@@ -80,44 +79,44 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull MatrixStack transform, @Nonnull VertexConsumerProvider buffers,
|
||||
public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull PoseStack transform, @Nonnull MultiBufferSource buffers,
|
||||
int lightmapCoord, int overlayLight )
|
||||
{
|
||||
// Render the label
|
||||
String label = turtle.createProxy()
|
||||
.getLabel();
|
||||
HitResult hit = renderer.crosshairTarget;
|
||||
if( label != null && hit.getType() == HitResult.Type.BLOCK && turtle.getPos()
|
||||
HitResult hit = renderer.cameraHitResult;
|
||||
if( label != null && hit.getType() == HitResult.Type.BLOCK && turtle.getBlockPos()
|
||||
.equals( ((BlockHitResult) hit).getBlockPos() ) )
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
TextRenderer font = mc.textRenderer;
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
Font font = mc.font;
|
||||
|
||||
transform.push();
|
||||
transform.pushPose();
|
||||
transform.translate( 0.5, 1.2, 0.5 );
|
||||
transform.multiply( mc.getEntityRenderDispatcher()
|
||||
.getRotation() );
|
||||
transform.mulPose( mc.getEntityRenderDispatcher()
|
||||
.cameraOrientation() );
|
||||
transform.scale( -0.025f, -0.025f, 0.025f );
|
||||
|
||||
Matrix4f matrix = transform.peek()
|
||||
.getModel();
|
||||
int opacity = (int) (mc.options.getTextBackgroundOpacity( 0.25f ) * 255) << 24;
|
||||
float width = -font.getWidth( label ) / 2.0f;
|
||||
font.draw( label, width, (float) 0, 0x20ffffff, false, matrix, buffers, true, opacity, lightmapCoord );
|
||||
font.draw( label, width, (float) 0, 0xffffffff, false, matrix, buffers, false, 0, lightmapCoord );
|
||||
Matrix4f matrix = transform.last()
|
||||
.pose();
|
||||
int opacity = (int) (mc.options.getBackgroundOpacity( 0.25f ) * 255) << 24;
|
||||
float width = -font.width( label ) / 2.0f;
|
||||
font.drawInBatch( label, width, (float) 0, 0x20ffffff, false, matrix, buffers, true, opacity, lightmapCoord );
|
||||
font.drawInBatch( label, width, (float) 0, 0xffffffff, false, matrix, buffers, false, 0, lightmapCoord );
|
||||
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
transform.push();
|
||||
transform.pushPose();
|
||||
|
||||
// Setup the transform.
|
||||
Vec3d offset = turtle.getRenderOffset( partialTicks );
|
||||
Vec3 offset = turtle.getRenderOffset( partialTicks );
|
||||
float yaw = turtle.getRenderYaw( partialTicks );
|
||||
transform.translate( offset.x, offset.y, offset.z );
|
||||
|
||||
transform.translate( 0.5f, 0.5f, 0.5f );
|
||||
transform.multiply( Vec3f.POSITIVE_Y.getDegreesQuaternion( 180.0f - yaw ) );
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( 180.0f - yaw ) );
|
||||
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
||||
{
|
||||
// Flip the model
|
||||
@@ -128,13 +127,13 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
||||
// Render the turtle
|
||||
int colour = turtle.getColour();
|
||||
ComputerFamily family = turtle.getFamily();
|
||||
Identifier overlay = turtle.getOverlay();
|
||||
ResourceLocation overlay = turtle.getOverlay();
|
||||
|
||||
VertexConsumer buffer = buffers.getBuffer( TexturedRenderLayers.getEntityTranslucentCull() );
|
||||
VertexConsumer buffer = buffers.getBuffer( Sheets.translucentCullBlockSheet() );
|
||||
renderModel( transform, buffer, lightmapCoord, overlayLight, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
|
||||
|
||||
// Render the overlay
|
||||
ModelIdentifier overlayModel = getTurtleOverlayModel( overlay, HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS );
|
||||
ModelResourceLocation overlayModel = getTurtleOverlayModel( overlay, HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS );
|
||||
if( overlayModel != null )
|
||||
{
|
||||
renderModel( transform, buffer, lightmapCoord, overlayLight, overlayModel, null );
|
||||
@@ -144,10 +143,10 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
||||
renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.LEFT, partialTicks );
|
||||
renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.RIGHT, partialTicks );
|
||||
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
private void renderUpgrade( @Nonnull MatrixStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, TileTurtle turtle,
|
||||
private void renderUpgrade( @Nonnull PoseStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, TileTurtle turtle,
|
||||
TurtleSide side, float f )
|
||||
{
|
||||
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
||||
@@ -155,32 +154,32 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
||||
{
|
||||
return;
|
||||
}
|
||||
transform.push();
|
||||
transform.pushPose();
|
||||
|
||||
float toolAngle = turtle.getToolRenderAngle( side, f );
|
||||
transform.translate( 0.0f, 0.5f, 0.5f );
|
||||
transform.multiply( Vec3f.NEGATIVE_X.getDegreesQuaternion( toolAngle ) );
|
||||
transform.mulPose( Vector3f.XN.rotationDegrees( toolAngle ) );
|
||||
transform.translate( 0.0f, -0.5f, -0.5f );
|
||||
|
||||
TransformedModel model = upgrade.getModel( turtle.getAccess(), side );
|
||||
model.push( transform );
|
||||
renderModel( transform, renderer, lightmapCoord, overlayLight, model.getModel(), null );
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
|
||||
transform.pop();
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
private void renderModel( @Nonnull MatrixStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight,
|
||||
ModelIdentifier modelLocation, int[] tints )
|
||||
private void renderModel( @Nonnull PoseStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight,
|
||||
ModelResourceLocation modelLocation, int[] tints )
|
||||
{
|
||||
BakedModelManager modelManager = MinecraftClient.getInstance()
|
||||
ModelManager modelManager = Minecraft.getInstance()
|
||||
.getItemRenderer()
|
||||
.getModels()
|
||||
.getItemModelShaper()
|
||||
.getModelManager();
|
||||
renderModel( transform, renderer, lightmapCoord, overlayLight, modelManager.getModel( modelLocation ), tints );
|
||||
}
|
||||
|
||||
private void renderModel( @Nonnull MatrixStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, BakedModel model,
|
||||
private void renderModel( @Nonnull PoseStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, BakedModel model,
|
||||
int[] tints )
|
||||
{
|
||||
random.setSeed( 0 );
|
||||
@@ -191,27 +190,27 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
|
||||
}
|
||||
}
|
||||
|
||||
private static void renderQuads( @Nonnull MatrixStack transform, @Nonnull VertexConsumer buffer, int lightmapCoord, int overlayLight,
|
||||
private static void renderQuads( @Nonnull PoseStack transform, @Nonnull VertexConsumer buffer, int lightmapCoord, int overlayLight,
|
||||
List<BakedQuad> quads, int[] tints )
|
||||
{
|
||||
MatrixStack.Entry matrix = transform.peek();
|
||||
PoseStack.Pose matrix = transform.last();
|
||||
|
||||
for( BakedQuad bakedquad : quads )
|
||||
{
|
||||
int tint = -1;
|
||||
if( tints != null && bakedquad.hasColor() )
|
||||
if( tints != null && bakedquad.isTinted() )
|
||||
{
|
||||
int idx = bakedquad.getColorIndex();
|
||||
int idx = bakedquad.getTintIndex();
|
||||
if( idx >= 0 && idx < tints.length )
|
||||
{
|
||||
tint = tints[bakedquad.getColorIndex()];
|
||||
tint = tints[bakedquad.getTintIndex()];
|
||||
}
|
||||
}
|
||||
|
||||
float f = (float) (tint >> 16 & 255) / 255.0F;
|
||||
float f1 = (float) (tint >> 8 & 255) / 255.0F;
|
||||
float f2 = (float) (tint & 255) / 255.0F;
|
||||
buffer.quad( matrix,
|
||||
buffer.putBulkData( matrix,
|
||||
bakedquad,
|
||||
new float[] { 1.0F, 1.0F, 1.0F, 1.0F },
|
||||
f,
|
||||
|
@@ -10,14 +10,13 @@ import com.mojang.datafixers.util.Pair;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||
import net.minecraft.client.render.model.ModelLoader;
|
||||
import net.minecraft.client.render.model.UnbakedModel;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -29,15 +28,15 @@ import java.util.stream.Collectors;
|
||||
public final class TurtleModelLoader
|
||||
{
|
||||
public static final TurtleModelLoader INSTANCE = new TurtleModelLoader();
|
||||
private static final Identifier NORMAL_TURTLE_MODEL = new Identifier( ComputerCraft.MOD_ID, "block/turtle_normal" );
|
||||
private static final Identifier ADVANCED_TURTLE_MODEL = new Identifier( ComputerCraft.MOD_ID, "block/turtle_advanced" );
|
||||
private static final Identifier COLOUR_TURTLE_MODEL = new Identifier( ComputerCraft.MOD_ID, "block/turtle_colour" );
|
||||
private static final ResourceLocation NORMAL_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_normal" );
|
||||
private static final ResourceLocation ADVANCED_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_advanced" );
|
||||
private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_colour" );
|
||||
|
||||
private TurtleModelLoader()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean accepts( @Nonnull Identifier name )
|
||||
public boolean accepts( @Nonnull ResourceLocation name )
|
||||
{
|
||||
return name.getNamespace()
|
||||
.equals( ComputerCraft.MOD_ID ) && (name.getPath()
|
||||
@@ -46,7 +45,7 @@ public final class TurtleModelLoader
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public UnbakedModel loadModel( @Nonnull Identifier name )
|
||||
public UnbakedModel loadModel( @Nonnull ResourceLocation name )
|
||||
{
|
||||
if( name.getNamespace()
|
||||
.equals( ComputerCraft.MOD_ID ) )
|
||||
@@ -65,39 +64,39 @@ public final class TurtleModelLoader
|
||||
|
||||
private static final class TurtleModel implements UnbakedModel
|
||||
{
|
||||
private final Identifier family;
|
||||
private final ResourceLocation family;
|
||||
|
||||
private TurtleModel( Identifier family )
|
||||
private TurtleModel( ResourceLocation family )
|
||||
{
|
||||
this.family = family;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SpriteIdentifier> getTextureDependencies( Function<Identifier, UnbakedModel> modelGetter,
|
||||
public Collection<Material> getMaterials( Function<ResourceLocation, UnbakedModel> modelGetter,
|
||||
Set<Pair<String, String>> missingTextureErrors )
|
||||
{
|
||||
return getModelDependencies()
|
||||
return getDependencies()
|
||||
.stream()
|
||||
.flatMap( x -> modelGetter.apply( x )
|
||||
.getTextureDependencies( modelGetter, missingTextureErrors )
|
||||
.getMaterials( modelGetter, missingTextureErrors )
|
||||
.stream() )
|
||||
.collect( Collectors.toSet() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Collection<Identifier> getModelDependencies()
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return Arrays.asList( family, COLOUR_TURTLE_MODEL );
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel bake( @Nonnull ModelLoader loader, @Nonnull Function<SpriteIdentifier, Sprite> spriteGetter, @Nonnull ModelBakeSettings state,
|
||||
Identifier modelId )
|
||||
public BakedModel bake( @Nonnull ModelBakery loader, @Nonnull Function<Material, TextureAtlasSprite> spriteGetter, @Nonnull ModelState state,
|
||||
ResourceLocation modelId )
|
||||
{
|
||||
return new TurtleSmartItemModel( loader.getOrLoadModel( family )
|
||||
return new TurtleSmartItemModel( loader.getModel( family )
|
||||
.bake( loader, spriteGetter, state, modelId ),
|
||||
loader.getOrLoadModel( COLOUR_TURTLE_MODEL )
|
||||
loader.getModel( COLOUR_TURTLE_MODEL )
|
||||
.bake( loader, spriteGetter, state, modelId ) );
|
||||
}
|
||||
}
|
||||
|
@@ -6,18 +6,17 @@
|
||||
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.math.Transformation;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.util.math.AffineTransformation;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
|
||||
@@ -26,13 +25,13 @@ public class TurtleMultiModel implements BakedModel
|
||||
{
|
||||
private final BakedModel baseModel;
|
||||
private final BakedModel overlayModel;
|
||||
private final AffineTransformation generalTransform;
|
||||
private final Transformation generalTransform;
|
||||
private final TransformedModel leftUpgradeModel;
|
||||
private final TransformedModel rightUpgradeModel;
|
||||
private List<BakedQuad> generalQuads = null;
|
||||
private final Map<Direction, List<BakedQuad>> faceQuads = new EnumMap<>( Direction.class );
|
||||
|
||||
public TurtleMultiModel( BakedModel baseModel, BakedModel overlayModel, AffineTransformation generalTransform, TransformedModel leftUpgradeModel,
|
||||
public TurtleMultiModel( BakedModel baseModel, BakedModel overlayModel, Transformation generalTransform, TransformedModel leftUpgradeModel,
|
||||
TransformedModel rightUpgradeModel )
|
||||
{
|
||||
// Get the models
|
||||
@@ -77,14 +76,14 @@ public class TurtleMultiModel implements BakedModel
|
||||
}
|
||||
if( leftUpgradeModel != null )
|
||||
{
|
||||
AffineTransformation upgradeTransform = generalTransform.multiply( leftUpgradeModel.getMatrix() );
|
||||
Transformation upgradeTransform = generalTransform.compose( leftUpgradeModel.getMatrix() );
|
||||
ModelTransformer.transformQuadsTo( quads, leftUpgradeModel.getModel()
|
||||
.getQuads( state, side, rand ),
|
||||
upgradeTransform.getMatrix() );
|
||||
}
|
||||
if( rightUpgradeModel != null )
|
||||
{
|
||||
AffineTransformation upgradeTransform = generalTransform.multiply( rightUpgradeModel.getMatrix() );
|
||||
Transformation upgradeTransform = generalTransform.compose( rightUpgradeModel.getMatrix() );
|
||||
ModelTransformer.transformQuadsTo( quads, rightUpgradeModel.getModel()
|
||||
.getQuads( state, side, rand ),
|
||||
upgradeTransform.getMatrix() );
|
||||
@@ -100,43 +99,43 @@ public class TurtleMultiModel implements BakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth()
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return baseModel.hasDepth();
|
||||
return baseModel.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit()
|
||||
public boolean usesBlockLight()
|
||||
{
|
||||
return baseModel.isSideLit();
|
||||
return baseModel.usesBlockLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin()
|
||||
public boolean isCustomRenderer()
|
||||
{
|
||||
return baseModel.isBuiltin();
|
||||
return baseModel.isCustomRenderer();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public Sprite getParticleSprite()
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
{
|
||||
return baseModel.getParticleSprite();
|
||||
return baseModel.getParticleIcon();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public ModelTransformation getTransformation()
|
||||
public ItemTransforms getTransforms()
|
||||
{
|
||||
return baseModel.getTransformation();
|
||||
return baseModel.getTransforms();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ModelOverrideList getOverrides()
|
||||
public ItemOverrides getOverrides()
|
||||
{
|
||||
return ModelOverrideList.EMPTY;
|
||||
return ItemOverrides.EMPTY;
|
||||
}
|
||||
}
|
||||
|
@@ -5,31 +5,30 @@
|
||||
*/
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.shared.turtle.core.TurtlePlayer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.EntityRenderer;
|
||||
import net.minecraft.client.render.entity.EntityRendererFactory;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class TurtlePlayerRenderer extends EntityRenderer<TurtlePlayer>
|
||||
{ //FIXME Make sure this isn't an issue. Context was EntityRenderDispatcher.
|
||||
public TurtlePlayerRenderer( EntityRendererFactory.Context context )
|
||||
public TurtlePlayerRenderer( EntityRendererProvider.Context context )
|
||||
{
|
||||
super( context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull TurtlePlayer entityIn, float entityYaw, float partialTicks, @Nonnull MatrixStack transform,
|
||||
@Nonnull VertexConsumerProvider buffer, int packedLightIn )
|
||||
public void render( @Nonnull TurtlePlayer entityIn, float entityYaw, float partialTicks, @Nonnull PoseStack transform,
|
||||
@Nonnull MultiBufferSource buffer, int packedLightIn )
|
||||
{
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Identifier getTexture( @Nonnull TurtlePlayer entity )
|
||||
public ResourceLocation getTexture( @Nonnull TurtlePlayer entity )
|
||||
{
|
||||
return ComputerBorderRenderer.BACKGROUND_NORMAL;
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Transformation;
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.api.turtle.TurtleSide;
|
||||
@@ -14,23 +16,20 @@ import dan200.computercraft.shared.util.Holiday;
|
||||
import dan200.computercraft.shared.util.HolidayUtil;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.BakedModelManager;
|
||||
import net.minecraft.client.render.model.BakedQuad;
|
||||
import net.minecraft.client.render.model.json.ModelOverrideList;
|
||||
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.AffineTransformation;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
@@ -41,17 +40,17 @@ import java.util.Random;
|
||||
@Environment( EnvType.CLIENT )
|
||||
public class TurtleSmartItemModel implements BakedModel
|
||||
{
|
||||
private static final AffineTransformation identity, flip;
|
||||
private static final Transformation identity, flip;
|
||||
|
||||
static
|
||||
{
|
||||
MatrixStack stack = new MatrixStack();
|
||||
PoseStack stack = new PoseStack();
|
||||
stack.scale( 0, -1, 0 );
|
||||
stack.translate( 0, 0, 1 );
|
||||
|
||||
identity = AffineTransformation.identity();
|
||||
flip = new AffineTransformation( stack.peek()
|
||||
.getModel() );
|
||||
identity = Transformation.identity();
|
||||
flip = new Transformation( stack.last()
|
||||
.pose() );
|
||||
}
|
||||
|
||||
private static class TurtleModelCombination
|
||||
@@ -59,11 +58,11 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
final boolean colour;
|
||||
final ITurtleUpgrade leftUpgrade;
|
||||
final ITurtleUpgrade rightUpgrade;
|
||||
final Identifier overlay;
|
||||
final ResourceLocation overlay;
|
||||
final boolean christmas;
|
||||
final boolean flip;
|
||||
|
||||
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, Identifier overlay, boolean christmas,
|
||||
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas,
|
||||
boolean flip )
|
||||
{
|
||||
this.colour = colour;
|
||||
@@ -109,7 +108,7 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
private final BakedModel colourModel;
|
||||
|
||||
private final HashMap<TurtleModelCombination, BakedModel> cachedModels = new HashMap<>();
|
||||
private final ModelOverrideList overrides;
|
||||
private final ItemOverrides overrides;
|
||||
|
||||
public TurtleSmartItemModel( BakedModel familyModel, BakedModel colourModel )
|
||||
{
|
||||
@@ -117,17 +116,17 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
this.colourModel = colourModel;
|
||||
|
||||
// this actually works I think, trust me
|
||||
overrides = new ModelOverrideList( null, null, null, Collections.emptyList() )
|
||||
overrides = new ItemOverrides( null, null, null, Collections.emptyList() )
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
public BakedModel apply( BakedModel originalModel, ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity, int seed )
|
||||
public BakedModel resolve( BakedModel originalModel, ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int seed )
|
||||
{
|
||||
ItemTurtle turtle = (ItemTurtle) stack.getItem();
|
||||
int colour = turtle.getColour( stack );
|
||||
ITurtleUpgrade leftUpgrade = turtle.getUpgrade( stack, TurtleSide.LEFT );
|
||||
ITurtleUpgrade rightUpgrade = turtle.getUpgrade( stack, TurtleSide.RIGHT );
|
||||
Identifier overlay = turtle.getOverlay( stack );
|
||||
ResourceLocation overlay = turtle.getOverlay( stack );
|
||||
boolean christmas = HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS;
|
||||
String label = turtle.getLabel( stack );
|
||||
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
|
||||
@@ -145,15 +144,15 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
|
||||
private BakedModel buildModel( TurtleModelCombination combo )
|
||||
{
|
||||
MinecraftClient mc = MinecraftClient.getInstance();
|
||||
BakedModelManager modelManager = mc.getItemRenderer()
|
||||
.getModels()
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
ModelManager modelManager = mc.getItemRenderer()
|
||||
.getItemModelShaper()
|
||||
.getModelManager();
|
||||
ModelIdentifier overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
|
||||
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
|
||||
|
||||
BakedModel baseModel = combo.colour ? colourModel : familyModel;
|
||||
BakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
|
||||
AffineTransformation transform = combo.flip ? flip : identity;
|
||||
Transformation transform = combo.flip ? flip : identity;
|
||||
TransformedModel leftModel = combo.leftUpgrade != null ? combo.leftUpgrade.getModel( null, TurtleSide.LEFT ) : null;
|
||||
TransformedModel rightModel = combo.rightUpgrade != null ? combo.rightUpgrade.getModel( null, TurtleSide.RIGHT ) : null;
|
||||
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel, rightModel );
|
||||
@@ -174,33 +173,33 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDepth()
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return familyModel.hasDepth();
|
||||
return familyModel.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideLit()
|
||||
public boolean usesBlockLight()
|
||||
{
|
||||
return familyModel.isSideLit();
|
||||
return familyModel.usesBlockLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltin()
|
||||
public boolean isCustomRenderer()
|
||||
{
|
||||
return familyModel.isBuiltin();
|
||||
return familyModel.isCustomRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public Sprite getParticleSprite()
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
{
|
||||
return familyModel.getParticleSprite();
|
||||
return familyModel.getParticleIcon();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ModelOverrideList getOverrides()
|
||||
public ItemOverrides getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
}
|
||||
@@ -208,9 +207,9 @@ public class TurtleSmartItemModel implements BakedModel
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public ModelTransformation getTransformation()
|
||||
public ItemTransforms getTransforms()
|
||||
{
|
||||
return familyModel.getTransformation();
|
||||
return familyModel.getTransforms();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,10 +5,9 @@
|
||||
*/
|
||||
package dan200.computercraft.core.computer;
|
||||
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
/**
|
||||
* A side on a computer. Unlike {@link Direction}, this is relative to the direction the computer is
|
||||
|
@@ -9,9 +9,8 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
||||
import dan200.computercraft.core.tracking.Tracking;
|
||||
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@@ -13,15 +13,14 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||
import dan200.computercraft.shared.util.IoUtil;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.resource.Resource;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.resource.SynchronousResourceReloader;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.InvalidIdentifierException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.ResourceLocationException;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -61,7 +60,7 @@ public final class ResourceMount implements IMount
|
||||
/**
|
||||
* Maintain a cache of currently loaded resource mounts. This cache is invalidated when currentManager changes.
|
||||
*/
|
||||
private static final Map<ReloadableResourceManager, Map<Identifier, ResourceMount>> MOUNT_CACHE = new WeakHashMap<>( 2 );
|
||||
private static final Map<ReloadableResourceManager, Map<ResourceLocation, ResourceMount>> MOUNT_CACHE = new WeakHashMap<>( 2 );
|
||||
|
||||
private final String namespace;
|
||||
private final String subPath;
|
||||
@@ -72,7 +71,7 @@ public final class ResourceMount implements IMount
|
||||
|
||||
public static ResourceMount get( String namespace, String subPath, ReloadableResourceManager manager )
|
||||
{
|
||||
Map<Identifier, ResourceMount> cache;
|
||||
Map<ResourceLocation, ResourceMount> cache;
|
||||
|
||||
synchronized( MOUNT_CACHE )
|
||||
{
|
||||
@@ -80,7 +79,7 @@ public final class ResourceMount implements IMount
|
||||
if( cache == null ) MOUNT_CACHE.put( manager, cache = CACHE_TEMPLATE.makeMap() );
|
||||
}
|
||||
|
||||
Identifier path = new Identifier( namespace, subPath );
|
||||
ResourceLocation path = new ResourceLocation( namespace, subPath );
|
||||
synchronized( cache )
|
||||
{
|
||||
ResourceMount mount = cache.get( path );
|
||||
@@ -104,8 +103,8 @@ public final class ResourceMount implements IMount
|
||||
boolean hasAny = false;
|
||||
String existingNamespace = null;
|
||||
|
||||
FileEntry newRoot = new FileEntry( new Identifier( namespace, subPath ) );
|
||||
for( Identifier file : manager.findResources( subPath, s -> true ) )
|
||||
FileEntry newRoot = new FileEntry( new ResourceLocation( namespace, subPath ) );
|
||||
for( ResourceLocation file : manager.listResources( subPath, s -> true ) )
|
||||
{
|
||||
existingNamespace = file.getNamespace();
|
||||
|
||||
@@ -160,12 +159,12 @@ public final class ResourceMount implements IMount
|
||||
FileEntry nextEntry = lastEntry.children.get( part );
|
||||
if( nextEntry == null )
|
||||
{
|
||||
Identifier childPath;
|
||||
ResourceLocation childPath;
|
||||
try
|
||||
{
|
||||
childPath = new Identifier( namespace, subPath + "/" + path );
|
||||
childPath = new ResourceLocation( namespace, subPath + "/" + path );
|
||||
}
|
||||
catch( InvalidIdentifierException e )
|
||||
catch( ResourceLocationException e )
|
||||
{
|
||||
ComputerCraft.log.warn( "Cannot create resource location for {} ({})", part, e.getMessage() );
|
||||
return;
|
||||
@@ -271,11 +270,11 @@ public final class ResourceMount implements IMount
|
||||
|
||||
private static class FileEntry
|
||||
{
|
||||
final Identifier identifier;
|
||||
final ResourceLocation identifier;
|
||||
Map<String, FileEntry> children;
|
||||
long size = -1;
|
||||
|
||||
FileEntry( Identifier identifier )
|
||||
FileEntry( ResourceLocation identifier )
|
||||
{
|
||||
this.identifier = identifier;
|
||||
}
|
||||
@@ -297,7 +296,7 @@ public final class ResourceMount implements IMount
|
||||
* While people should really be keeping a permanent reference to this, some people construct it every
|
||||
* method call, so let's make this as small as possible.
|
||||
*/
|
||||
static class Listener implements SynchronousResourceReloader
|
||||
static class Listener implements ResourceManagerReloadListener
|
||||
{
|
||||
private static final Listener INSTANCE = new Listener();
|
||||
|
||||
@@ -305,14 +304,14 @@ public final class ResourceMount implements IMount
|
||||
private final Set<ReloadableResourceManager> managers = Collections.newSetFromMap( new WeakHashMap<>() );
|
||||
|
||||
@Override
|
||||
public void reload( @Nonnull ResourceManager manager )
|
||||
public void onResourceManagerReload( @Nonnull ResourceManager manager )
|
||||
{
|
||||
for( ResourceMount mount : mounts ) mount.load();
|
||||
}
|
||||
|
||||
synchronized void add( ReloadableResourceManager manager, ResourceMount mount )
|
||||
{
|
||||
if( managers.add( manager ) ) manager.registerReloader( this );
|
||||
if( managers.add( manager ) ) manager.registerReloadListener( this );
|
||||
mounts.add( mount );
|
||||
}
|
||||
}
|
||||
|
@@ -7,10 +7,9 @@ package dan200.computercraft.core.terminal;
|
||||
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
public class Terminal
|
||||
{
|
||||
@@ -310,7 +309,7 @@ public class Terminal
|
||||
if( onChanged != null ) onChanged.run();
|
||||
}
|
||||
|
||||
public synchronized void write( PacketByteBuf buffer )
|
||||
public synchronized void write( FriendlyByteBuf buffer )
|
||||
{
|
||||
buffer.writeInt( cursorX );
|
||||
buffer.writeInt( cursorY );
|
||||
@@ -336,7 +335,7 @@ public class Terminal
|
||||
palette.write( buffer );
|
||||
}
|
||||
|
||||
public synchronized void read( PacketByteBuf buffer )
|
||||
public synchronized void read( FriendlyByteBuf buffer )
|
||||
{
|
||||
cursorX = buffer.readInt();
|
||||
cursorY = buffer.readInt();
|
||||
@@ -366,7 +365,7 @@ public class Terminal
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public synchronized NbtCompound writeToNBT( NbtCompound nbt )
|
||||
public synchronized CompoundTag writeToNBT( CompoundTag nbt )
|
||||
{
|
||||
nbt.putInt( "term_cursorX", cursorX );
|
||||
nbt.putInt( "term_cursorY", cursorY );
|
||||
@@ -384,7 +383,7 @@ public class Terminal
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public synchronized void readFromNBT( NbtCompound nbt )
|
||||
public synchronized void readFromNBT( CompoundTag nbt )
|
||||
{
|
||||
cursorX = nbt.getInt( "term_cursorX" );
|
||||
cursorY = nbt.getInt( "term_cursorY" );
|
||||
|
@@ -5,16 +5,16 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import net.minecraft.client.gui.hud.ChatHud;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.client.gui.components.ChatComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin( ChatHud.class )
|
||||
@Mixin( ChatComponent.class )
|
||||
public interface ChatHudAccess
|
||||
{
|
||||
@Invoker
|
||||
void callAddMessage( Text text, int messageId );
|
||||
void callAddMessage( Component text, int messageId );
|
||||
|
||||
@Invoker
|
||||
void callRemoveMessage( int messageId );
|
||||
|
@@ -5,22 +5,22 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Arm;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.ItemInHandRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin( HeldItemRenderer.class )
|
||||
@Mixin( ItemInHandRenderer.class )
|
||||
public interface HeldItemRendererAccess
|
||||
{
|
||||
@Invoker
|
||||
float callGetMapAngle( float tickDelta );
|
||||
|
||||
@Invoker
|
||||
void callRenderArm( MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, Arm arm );
|
||||
void callRenderArm( PoseStack matrices, MultiBufferSource vertexConsumers, int light, HumanoidArm arm );
|
||||
|
||||
@Invoker
|
||||
void callRenderArmHoldingItem( MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float equipProgress, float swingProgress, Arm arm );
|
||||
void callRenderArmHoldingItem( PoseStack matrices, MultiBufferSource vertexConsumers, int light, float equipProgress, float swingProgress, HumanoidArm arm );
|
||||
}
|
||||
|
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import net.minecraft.resource.ServerResourceManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerResources;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@@ -14,5 +14,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
public interface MinecraftServerAccess
|
||||
{
|
||||
@Accessor
|
||||
ServerResourceManager getServerResourceManager();
|
||||
ServerResources getServerResourceManager();
|
||||
}
|
||||
|
@@ -6,14 +6,12 @@
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import dan200.computercraft.shared.util.DropConsumer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -23,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
/**
|
||||
* Captures block drops.
|
||||
*
|
||||
* @see Block#dropStack(World, BlockPos, ItemStack)
|
||||
* @see Block#popResource(Level, BlockPos, ItemStack)
|
||||
*/
|
||||
@Mixin( Block.class )
|
||||
public class MixinBlock
|
||||
@@ -35,9 +33,9 @@ public class MixinBlock
|
||||
),
|
||||
locals = LocalCapture.CAPTURE_FAILSOFT,
|
||||
cancellable = true )
|
||||
private static void dropStack( World world, Supplier<ItemEntity> itemEntitySupplier, ItemStack stack, CallbackInfo callbackInfo, ItemEntity itemEntity )
|
||||
private static void dropStack( Level world, Supplier<ItemEntity> itemEntitySupplier, ItemStack stack, CallbackInfo callbackInfo, ItemEntity itemEntity )
|
||||
{
|
||||
if( DropConsumer.onHarvestDrops( world, itemEntity.getBlockPos(), stack ) )
|
||||
if( DropConsumer.onHarvestDrops( world, itemEntity.blockPosition(), stack ) )
|
||||
{
|
||||
callbackInfo.cancel();
|
||||
}
|
||||
|
@@ -6,9 +6,9 @@
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import dan200.computercraft.shared.util.DropConsumer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
/**
|
||||
* Captures entities.
|
||||
*
|
||||
* @see Entity#dropStack(ItemStack, float)
|
||||
* @see Entity#spawnAtLocation(ItemStack, float)
|
||||
*/
|
||||
@Mixin( Entity.class )
|
||||
public class MixinEntity
|
||||
|
@@ -6,13 +6,10 @@
|
||||
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import com.mojang.blaze3d.shaders.Program;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import dan200.computercraft.client.render.MonitorTextureBufferShader;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import net.minecraft.client.gl.Program;
|
||||
import net.minecraft.client.render.GameRenderer;
|
||||
import net.minecraft.client.render.Shader;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -22,22 +19,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
||||
@Mixin( GameRenderer.class )
|
||||
public class MixinGameRenderer
|
||||
{
|
||||
@Inject( method = "loadShaders", at = @At( value = "INVOKE_ASSIGN", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 53 ), locals = LocalCapture.CAPTURE_FAILSOFT )
|
||||
private void loadShaders( ResourceManager manager, CallbackInfo info, List<Program> list, List<Pair<Shader, Consumer<Shader>>> list2 ) throws IOException
|
||||
private void loadShaders( ResourceManager manager, CallbackInfo info, List<Program> list, List<Pair<ShaderInstance, Consumer<ShaderInstance>>> list2 ) throws IOException
|
||||
{
|
||||
list2.add( Pair.of( new Shader(
|
||||
list2.add( Pair.of( new ShaderInstance(
|
||||
manager,
|
||||
"terminal",
|
||||
RenderTypes.TERMINAL_WITHOUT_DEPTH.getVertexFormat()
|
||||
RenderTypes.TERMINAL_WITHOUT_DEPTH.format()
|
||||
), shader -> RenderTypes.terminalShader = shader ) );
|
||||
list2.add( Pair.of( new MonitorTextureBufferShader(
|
||||
manager,
|
||||
"monitor_tbo",
|
||||
RenderTypes.MONITOR_TBO.getVertexFormat()
|
||||
RenderTypes.MONITOR_TBO.format()
|
||||
), shader -> RenderTypes.monitorTboShader = (MonitorTextureBufferShader) shader ) );
|
||||
}
|
||||
}
|
||||
|
@@ -6,20 +6,20 @@
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import net.minecraft.client.gui.Element;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin( HandledScreen.class )
|
||||
public class MixinHandledScreen<T extends ScreenHandler> extends Screen
|
||||
@Mixin( AbstractContainerScreen.class )
|
||||
public class MixinHandledScreen<T extends AbstractContainerMenu> extends Screen
|
||||
{
|
||||
protected MixinHandledScreen( Text title )
|
||||
protected MixinHandledScreen( Component title )
|
||||
{
|
||||
super( title );
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class MixinHandledScreen<T extends ScreenHandler> extends Screen
|
||||
@Inject( method = "mouseReleased", at = @At ( "HEAD" ) )
|
||||
public void mouseReleased( double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> cir )
|
||||
{
|
||||
for ( Element child : this.children() )
|
||||
for ( GuiEventListener child : this.children() )
|
||||
{
|
||||
if ( child instanceof WidgetTerminal )
|
||||
{
|
||||
|
@@ -5,32 +5,32 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.client.render.ItemPocketRenderer;
|
||||
import dan200.computercraft.client.render.ItemPrintoutRenderer;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Arm;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.ItemInHandRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin( HeldItemRenderer.class )
|
||||
@Mixin( ItemInHandRenderer.class )
|
||||
@Environment( EnvType.CLIENT )
|
||||
public class MixinHeldItemRenderer
|
||||
{
|
||||
@Shadow
|
||||
private void renderArmHoldingItem( MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float equipProgress, float swingProgress,
|
||||
Arm arm )
|
||||
private void renderArmHoldingItem( PoseStack matrices, MultiBufferSource vertexConsumers, int light, float equipProgress, float swingProgress,
|
||||
HumanoidArm arm )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ public class MixinHeldItemRenderer
|
||||
at = @At( "HEAD" ),
|
||||
cancellable = true )
|
||||
public void renderFirstPersonItem(
|
||||
AbstractClientPlayerEntity player, float var2, float pitch, Hand hand, float swingProgress,
|
||||
ItemStack stack, float equipProgress, MatrixStack matrixStack, VertexConsumerProvider provider, int light,
|
||||
AbstractClientPlayer player, float var2, float pitch, InteractionHand hand, float swingProgress,
|
||||
ItemStack stack, float equipProgress, PoseStack matrixStack, MultiBufferSource provider, int light,
|
||||
CallbackInfo callback
|
||||
)
|
||||
{
|
||||
|
@@ -5,22 +5,22 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dan200.computercraft.client.render.ItemPrintoutRenderer;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.ItemFrameEntityRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.ItemFrameRenderer;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin( ItemFrameEntityRenderer.class )
|
||||
@Mixin( ItemFrameRenderer.class )
|
||||
@Environment( EnvType.CLIENT )
|
||||
public class MixinItemFrameEntityRenderer
|
||||
{
|
||||
@@ -34,17 +34,17 @@ public class MixinItemFrameEntityRenderer
|
||||
),
|
||||
cancellable = true )
|
||||
private void renderItem(
|
||||
ItemFrameEntity itemFrameEntity, float f, float g, MatrixStack matrixStack,
|
||||
VertexConsumerProvider vertexConsumerProvider, int itemFrameEntityLight, CallbackInfo info
|
||||
ItemFrame itemFrameEntity, float f, float g, PoseStack matrixStack,
|
||||
MultiBufferSource vertexConsumerProvider, int itemFrameEntityLight, CallbackInfo info
|
||||
)
|
||||
{
|
||||
ItemStack stack = itemFrameEntity.getHeldItemStack();
|
||||
ItemStack stack = itemFrameEntity.getItem();
|
||||
if( stack.getItem() instanceof ItemPrintout )
|
||||
{
|
||||
int light = itemFrameEntity.getType() == EntityType.GLOW_ITEM_FRAME ? 0xf000d2 : itemFrameEntityLight; // See getLightVal.
|
||||
ItemPrintoutRenderer.INSTANCE.renderInFrame( matrixStack, vertexConsumerProvider, stack, light );
|
||||
// TODO: need to find how to make if statement instead return, like it doing Forge
|
||||
matrixStack.pop();
|
||||
matrixStack.popPose();
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonParseException;
|
||||
import dan200.computercraft.shared.peripheral.generic.data.ItemData;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.util.Language;
|
||||
import net.minecraft.locale.Language;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.fabric.mixininterface.IMatrix4f;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
|
@@ -7,15 +7,15 @@ package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.fabric.events.ClientUnloadWorldEvent;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin( MinecraftClient.class )
|
||||
@Mixin( Minecraft.class )
|
||||
public abstract class MixinMinecraftClient
|
||||
{
|
||||
@Inject( method = "render", at = @At( "HEAD" ) )
|
||||
@@ -31,7 +31,7 @@ public abstract class MixinMinecraftClient
|
||||
}
|
||||
|
||||
@Inject( method = "joinWorld", at = @At( "RETURN" ) )
|
||||
private void joinWorldAfter( ClientWorld world, CallbackInfo info )
|
||||
private void joinWorldAfter( ClientLevel world, CallbackInfo info )
|
||||
{
|
||||
ClientUnloadWorldEvent.EVENT.invoker().onClientUnloadWorld();
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ package dan200.computercraft.fabric.mixin;
|
||||
import dan200.computercraft.shared.command.ClientCommands;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
@@ -6,35 +6,35 @@
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import dan200.computercraft.shared.ComputerCraftRegistry;
|
||||
import net.minecraft.advancement.criterion.Criteria;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin( ServerPlayerInteractionManager.class )
|
||||
@Mixin( ServerPlayerGameMode.class )
|
||||
public class MixinServerPlayerInteractionManager
|
||||
{
|
||||
@Inject( at = @At( value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;copy()Lnet/minecraft/item/ItemStack;", ordinal = 0 ), method = "interactBlock(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;", cancellable = true )
|
||||
private void interact( ServerPlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir )
|
||||
private void interact( ServerPlayer player, Level world, ItemStack stack, InteractionHand hand, BlockHitResult hitResult, CallbackInfoReturnable<InteractionResult> cir )
|
||||
{
|
||||
BlockPos pos = hitResult.getBlockPos();
|
||||
BlockState state = world.getBlockState( pos );
|
||||
if( player.getMainHandStack().getItem() == ComputerCraftRegistry.ModItems.DISK && state.getBlock() == ComputerCraftRegistry.ModBlocks.DISK_DRIVE )
|
||||
if( player.getMainHandItem().getItem() == ComputerCraftRegistry.ModItems.DISK && state.getBlock() == ComputerCraftRegistry.ModBlocks.DISK_DRIVE )
|
||||
{
|
||||
ActionResult actionResult = state.onUse( world, player, hand, hitResult );
|
||||
if( actionResult.isAccepted() )
|
||||
InteractionResult actionResult = state.use( world, player, hand, hitResult );
|
||||
if( actionResult.consumesAction() )
|
||||
{
|
||||
Criteria.ITEM_USED_ON_BLOCK.trigger( player, pos, stack );
|
||||
CriteriaTriggers.ITEM_USED_ON_BLOCK.trigger( player, pos, stack );
|
||||
cir.setReturnValue( actionResult );
|
||||
}
|
||||
}
|
||||
|
@@ -6,8 +6,8 @@
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import dan200.computercraft.shared.util.DropConsumer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -16,9 +16,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
/**
|
||||
* Captures item stacks spawned into the world.
|
||||
*
|
||||
* @see ServerWorld#spawnEntity(Entity)
|
||||
* @see ServerLevel#addFreshEntity(Entity)
|
||||
*/
|
||||
@Mixin( ServerWorld.class )
|
||||
@Mixin( ServerLevel.class )
|
||||
public class MixinServerWorld
|
||||
{
|
||||
@Inject( method = "spawnEntity", at = @At( "HEAD" ), cancellable = true )
|
||||
|
@@ -6,9 +6,6 @@
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import dan200.computercraft.shared.common.TileGeneric;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -16,6 +13,9 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -23,7 +23,7 @@ import java.util.Collection;
|
||||
*
|
||||
* Forge does this, this is just a bodge to get Fabric in line with that behaviour.
|
||||
*/
|
||||
@Mixin( World.class )
|
||||
@Mixin( Level.class )
|
||||
public class MixinWorld
|
||||
{
|
||||
@Shadow
|
||||
@@ -38,7 +38,7 @@ public class MixinWorld
|
||||
@Inject( method = "addBlockEntity", at = @At( "HEAD" ) )
|
||||
public void addBlockEntity( @Nullable BlockEntity entity, CallbackInfo info )
|
||||
{
|
||||
if( entity != null && !entity.isRemoved() && this.isInBuildLimit( entity.getPos() ) && iteratingTickingBlockEntities )
|
||||
if( entity != null && !entity.isRemoved() && this.isInBuildLimit( entity.getBlockPos() ) && iteratingTickingBlockEntities )
|
||||
{
|
||||
setWorld( entity, this );
|
||||
}
|
||||
@@ -46,9 +46,9 @@ public class MixinWorld
|
||||
|
||||
private static void setWorld( BlockEntity entity, Object world )
|
||||
{
|
||||
if( entity.getWorld() != world && entity instanceof TileGeneric )
|
||||
if( entity.getLevel() != world && entity instanceof TileGeneric )
|
||||
{
|
||||
entity.setWorld( (World) world );
|
||||
entity.setLevel( (Level) world );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,27 +5,27 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import dan200.computercraft.client.render.CableHighlightRenderer;
|
||||
import dan200.computercraft.client.render.MonitorHighlightRenderer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin( WorldRenderer.class )
|
||||
@Mixin( LevelRenderer.class )
|
||||
@Environment( EnvType.CLIENT )
|
||||
public class MixinWorldRenderer
|
||||
{
|
||||
@Inject( method = "drawBlockOutline", cancellable = true, at = @At( "HEAD" ) )
|
||||
public void drawBlockOutline( MatrixStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos blockPos,
|
||||
public void drawBlockOutline( PoseStack matrixStack, VertexConsumer vertexConsumer, Entity entity, double d, double e, double f, BlockPos blockPos,
|
||||
BlockState blockState, CallbackInfo info )
|
||||
{
|
||||
if( CableHighlightRenderer.drawHighlight( matrixStack,
|
||||
|
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@@ -14,5 +14,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
public interface SignBlockEntityAccess
|
||||
{
|
||||
@Accessor
|
||||
Text[] getTexts();
|
||||
Component[] getTexts();
|
||||
}
|
||||
|
@@ -5,15 +5,15 @@
|
||||
*/
|
||||
package dan200.computercraft.fabric.mixin;
|
||||
|
||||
import net.minecraft.util.WorldSavePath;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@Mixin( WorldSavePath.class )
|
||||
@Mixin( LevelResource.class )
|
||||
public interface WorldSavePathAccess
|
||||
{
|
||||
@Invoker( "<init>" )
|
||||
static WorldSavePath createWorldSavePath( String relativePath )
|
||||
static LevelResource createWorldSavePath( String relativePath )
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@@ -9,11 +9,10 @@ package dan200.computercraft.shared;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -29,20 +28,20 @@ public final class BundledRedstone
|
||||
if( !providers.contains( provider ) ) providers.add( provider );
|
||||
}
|
||||
|
||||
public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public static int getDefaultOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return world.isInBuildLimit( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1;
|
||||
return world.isInWorldBounds( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1;
|
||||
}
|
||||
|
||||
public static int getOutput( World world, BlockPos pos, Direction side )
|
||||
public static int getOutput( Level world, BlockPos pos, Direction side )
|
||||
{
|
||||
int signal = getUnmaskedOutput( world, pos, side );
|
||||
return signal >= 0 ? signal : 0;
|
||||
}
|
||||
|
||||
private static int getUnmaskedOutput( World world, BlockPos pos, Direction side )
|
||||
private static int getUnmaskedOutput( Level world, BlockPos pos, Direction side )
|
||||
{
|
||||
if( !world.isInBuildLimit( pos ) )
|
||||
if( !world.isInWorldBounds( pos ) )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@@ -51,24 +51,28 @@ import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityT
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static net.minecraft.util.registry.Registry.BLOCK_ENTITY_TYPE;
|
||||
import static net.minecraft.core.Registry.BLOCK_ENTITY_TYPE;
|
||||
|
||||
public final class ComputerCraftRegistry
|
||||
{
|
||||
@@ -122,10 +126,10 @@ public final class ComputerCraftRegistry
|
||||
{
|
||||
//return FabricBlockSettings.copyOf(Blocks.GLASS)
|
||||
// .strength(2);
|
||||
return AbstractBlock.Settings.of( Material.GLASS )
|
||||
return BlockBehaviour.Properties.of( Material.GLASS )
|
||||
.strength( 2F )
|
||||
.sounds( BlockSoundGroup.STONE )
|
||||
.nonOpaque();
|
||||
.sound( SoundType.STONE )
|
||||
.noOcclusion();
|
||||
}
|
||||
|
||||
private static Block.Settings turtleProperties()
|
||||
@@ -144,7 +148,7 @@ public final class ComputerCraftRegistry
|
||||
|
||||
public static <T extends Block> T register( String id, T value )
|
||||
{
|
||||
return Registry.register( Registry.BLOCK, new Identifier( MOD_ID, id ), value );
|
||||
return Registry.register( Registry.BLOCK, new ResourceLocation( MOD_ID, id ), value );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +198,7 @@ public final class ComputerCraftRegistry
|
||||
{
|
||||
BlockEntityType<T> blockEntityType = FabricBlockEntityTypeBuilder.create( factory::apply, block ).build();
|
||||
return Registry.register( BLOCK_ENTITY_TYPE,
|
||||
new Identifier( MOD_ID, id ),
|
||||
new ResourceLocation( MOD_ID, id ),
|
||||
blockEntityType
|
||||
);
|
||||
}
|
||||
@@ -202,22 +206,22 @@ public final class ComputerCraftRegistry
|
||||
|
||||
public static final class ModItems
|
||||
{
|
||||
private static final ItemGroup mainItemGroup = ComputerCraft.MAIN_GROUP;
|
||||
private static final CreativeModeTab mainItemGroup = ComputerCraft.MAIN_GROUP;
|
||||
public static final ItemComputer COMPUTER_NORMAL = ofBlock( ModBlocks.COMPUTER_NORMAL, ItemComputer::new );
|
||||
public static final ItemComputer COMPUTER_ADVANCED = ofBlock( ModBlocks.COMPUTER_ADVANCED, ItemComputer::new );
|
||||
public static final ItemComputer COMPUTER_COMMAND = ofBlock( ModBlocks.COMPUTER_COMMAND, ItemComputer::new );
|
||||
public static final ItemPocketComputer POCKET_COMPUTER_NORMAL = register( "pocket_computer_normal",
|
||||
new ItemPocketComputer( properties().maxCount( 1 ), ComputerFamily.NORMAL ) );
|
||||
new ItemPocketComputer( properties().stacksTo( 1 ), ComputerFamily.NORMAL ) );
|
||||
public static final ItemPocketComputer POCKET_COMPUTER_ADVANCED = register( "pocket_computer_advanced",
|
||||
new ItemPocketComputer( properties().maxCount( 1 ),
|
||||
new ItemPocketComputer( properties().stacksTo( 1 ),
|
||||
ComputerFamily.ADVANCED ) );
|
||||
public static final ItemTurtle TURTLE_NORMAL = ofBlock( ModBlocks.TURTLE_NORMAL, ItemTurtle::new );
|
||||
public static final ItemTurtle TURTLE_ADVANCED = ofBlock( ModBlocks.TURTLE_ADVANCED, ItemTurtle::new );
|
||||
public static final ItemDisk DISK = register( "disk", new ItemDisk( properties().maxCount( 1 ) ) );
|
||||
public static final ItemTreasureDisk TREASURE_DISK = register( "treasure_disk", new ItemTreasureDisk( properties().maxCount( 1 ) ) );
|
||||
public static final ItemPrintout PRINTED_PAGE = register( "printed_page", new ItemPrintout( properties().maxCount( 1 ), ItemPrintout.Type.PAGE ) );
|
||||
public static final ItemPrintout PRINTED_PAGES = register( "printed_pages", new ItemPrintout( properties().maxCount( 1 ), ItemPrintout.Type.PAGES ) );
|
||||
public static final ItemPrintout PRINTED_BOOK = register( "printed_book", new ItemPrintout( properties().maxCount( 1 ), ItemPrintout.Type.BOOK ) );
|
||||
public static final ItemDisk DISK = register( "disk", new ItemDisk( properties().stacksTo( 1 ) ) );
|
||||
public static final ItemTreasureDisk TREASURE_DISK = register( "treasure_disk", new ItemTreasureDisk( properties().stacksTo( 1 ) ) );
|
||||
public static final ItemPrintout PRINTED_PAGE = register( "printed_page", new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.PAGE ) );
|
||||
public static final ItemPrintout PRINTED_PAGES = register( "printed_pages", new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.PAGES ) );
|
||||
public static final ItemPrintout PRINTED_BOOK = register( "printed_book", new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.BOOK ) );
|
||||
public static final BlockItem SPEAKER = ofBlock( ModBlocks.SPEAKER, BlockItem::new );
|
||||
public static final BlockItem DISK_DRIVE = ofBlock( ModBlocks.DISK_DRIVE, BlockItem::new );
|
||||
public static final BlockItem PRINTER = ofBlock( ModBlocks.PRINTER, BlockItem::new );
|
||||
@@ -229,29 +233,29 @@ public final class ComputerCraftRegistry
|
||||
public static final ItemBlockCable.Cable CABLE = register( "cable", new ItemBlockCable.Cable( ModBlocks.CABLE, properties() ) );
|
||||
public static final ItemBlockCable.WiredModem WIRED_MODEM = register( "wired_modem", new ItemBlockCable.WiredModem( ModBlocks.CABLE, properties() ) );
|
||||
|
||||
private static <B extends Block, I extends Item> I ofBlock( B parent, BiFunction<B, Item.Settings, I> supplier )
|
||||
private static <B extends Block, I extends Item> I ofBlock( B parent, BiFunction<B, Item.Properties, I> supplier )
|
||||
{
|
||||
return Registry.register( Registry.ITEM, Registry.BLOCK.getId( parent ), supplier.apply( parent, properties() ) );
|
||||
return Registry.register( Registry.ITEM, Registry.BLOCK.getKey( parent ), supplier.apply( parent, properties() ) );
|
||||
}
|
||||
|
||||
private static Item.Settings properties()
|
||||
private static Item.Properties properties()
|
||||
{
|
||||
return new Item.Settings().group( mainItemGroup );
|
||||
return new Item.Properties().tab( mainItemGroup );
|
||||
}
|
||||
|
||||
private static <T extends Item> T register( String id, T item )
|
||||
{
|
||||
return Registry.register( Registry.ITEM, new Identifier( MOD_ID, id ), item );
|
||||
return Registry.register( Registry.ITEM, new ResourceLocation( MOD_ID, id ), item );
|
||||
}
|
||||
}
|
||||
|
||||
public static class ModEntities
|
||||
{
|
||||
public static final EntityType<TurtlePlayer> TURTLE_PLAYER = Registry.register( Registry.ENTITY_TYPE,
|
||||
new Identifier( MOD_ID, "turtle_player" ),
|
||||
EntityType.Builder.<TurtlePlayer>create( SpawnGroup.MISC ).disableSaving()
|
||||
.disableSummon()
|
||||
.setDimensions(
|
||||
new ResourceLocation( MOD_ID, "turtle_player" ),
|
||||
EntityType.Builder.<TurtlePlayer>createNothing( MobCategory.MISC ).noSave()
|
||||
.noSummon()
|
||||
.sized(
|
||||
0,
|
||||
0 )
|
||||
.build(
|
||||
@@ -260,36 +264,36 @@ public final class ComputerCraftRegistry
|
||||
|
||||
public static class ModContainers
|
||||
{
|
||||
public static final ScreenHandlerType<ContainerComputerBase> COMPUTER = ContainerData.toType( new Identifier( MOD_ID, "computer" ), ModContainers.COMPUTER, ComputerContainerData::new, ComputerMenuWithoutInventory::new );
|
||||
public static final ScreenHandlerType<ContainerComputerBase> POCKET_COMPUTER = ContainerData.toType( new Identifier( MOD_ID, "pocket_computer" ), ModContainers.POCKET_COMPUTER, ComputerContainerData::new, ComputerMenuWithoutInventory::new );
|
||||
public static final ScreenHandlerType<ContainerComputerBase> POCKET_COMPUTER_NO_TERM = ContainerData.toType( new Identifier( MOD_ID, "pocket_computer_no_term" ), ModContainers.POCKET_COMPUTER_NO_TERM, ComputerContainerData::new, ComputerMenuWithoutInventory::new );
|
||||
public static final ScreenHandlerType<ContainerTurtle> TURTLE = ContainerData.toType( new Identifier( MOD_ID, "turtle" ), ComputerContainerData::new, ContainerTurtle::new );
|
||||
public static final ScreenHandlerType<ContainerDiskDrive> DISK_DRIVE = registerSimple( "disk_drive", ContainerDiskDrive::new );
|
||||
public static final ScreenHandlerType<ContainerPrinter> PRINTER = registerSimple( "printer", ContainerPrinter::new );
|
||||
public static final ScreenHandlerType<ContainerHeldItem> PRINTOUT = ContainerData.toType( new Identifier( MOD_ID, "printout" ), HeldItemContainerData::new, ContainerHeldItem::createPrintout );
|
||||
public static final ScreenHandlerType<ContainerViewComputer> VIEW_COMPUTER = ContainerData.toType( new Identifier( MOD_ID, "view_computer" ), ViewComputerContainerData::new, ContainerViewComputer::new );
|
||||
public static final MenuType<ContainerComputerBase> COMPUTER = ContainerData.toType( new ResourceLocation( MOD_ID, "computer" ), ModContainers.COMPUTER, ComputerContainerData::new, ComputerMenuWithoutInventory::new );
|
||||
public static final MenuType<ContainerComputerBase> POCKET_COMPUTER = ContainerData.toType( new ResourceLocation( MOD_ID, "pocket_computer" ), ModContainers.POCKET_COMPUTER, ComputerContainerData::new, ComputerMenuWithoutInventory::new );
|
||||
public static final MenuType<ContainerComputerBase> POCKET_COMPUTER_NO_TERM = ContainerData.toType( new ResourceLocation( MOD_ID, "pocket_computer_no_term" ), ModContainers.POCKET_COMPUTER_NO_TERM, ComputerContainerData::new, ComputerMenuWithoutInventory::new );
|
||||
public static final MenuType<ContainerTurtle> TURTLE = ContainerData.toType( new ResourceLocation( MOD_ID, "turtle" ), ComputerContainerData::new, ContainerTurtle::new );
|
||||
public static final MenuType<ContainerDiskDrive> DISK_DRIVE = registerSimple( "disk_drive", ContainerDiskDrive::new );
|
||||
public static final MenuType<ContainerPrinter> PRINTER = registerSimple( "printer", ContainerPrinter::new );
|
||||
public static final MenuType<ContainerHeldItem> PRINTOUT = ContainerData.toType( new ResourceLocation( MOD_ID, "printout" ), HeldItemContainerData::new, ContainerHeldItem::createPrintout );
|
||||
public static final MenuType<ContainerViewComputer> VIEW_COMPUTER = ContainerData.toType( new ResourceLocation( MOD_ID, "view_computer" ), ViewComputerContainerData::new, ContainerViewComputer::new );
|
||||
|
||||
private static <T extends ScreenHandler> ScreenHandlerType<T> registerSimple( String id,
|
||||
private static <T extends AbstractContainerMenu> MenuType<T> registerSimple( String id,
|
||||
ScreenHandlerRegistry.SimpleClientHandlerFactory<T> function )
|
||||
{
|
||||
return ScreenHandlerRegistry.registerSimple( new Identifier( MOD_ID, id ), function );
|
||||
return ScreenHandlerRegistry.registerSimple( new ResourceLocation( MOD_ID, id ), function );
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TurtleUpgrades
|
||||
{
|
||||
public static TurtleModem wirelessModemNormal = new TurtleModem( false, new Identifier( ComputerCraft.MOD_ID, "wireless_modem_normal" ) );
|
||||
public static TurtleModem wirelessModemAdvanced = new TurtleModem( true, new Identifier( ComputerCraft.MOD_ID, "wireless_modem_advanced" ) );
|
||||
public static TurtleSpeaker speaker = new TurtleSpeaker( new Identifier( ComputerCraft.MOD_ID, "speaker" ) );
|
||||
public static TurtleModem wirelessModemNormal = new TurtleModem( false, new ResourceLocation( ComputerCraft.MOD_ID, "wireless_modem_normal" ) );
|
||||
public static TurtleModem wirelessModemAdvanced = new TurtleModem( true, new ResourceLocation( ComputerCraft.MOD_ID, "wireless_modem_advanced" ) );
|
||||
public static TurtleSpeaker speaker = new TurtleSpeaker( new ResourceLocation( ComputerCraft.MOD_ID, "speaker" ) );
|
||||
|
||||
public static TurtleCraftingTable craftingTable = new TurtleCraftingTable( new Identifier( "minecraft", "crafting_table" ) );
|
||||
public static TurtleSword diamondSword = new TurtleSword( new Identifier( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD );
|
||||
public static TurtleShovel diamondShovel = new TurtleShovel( new Identifier( "minecraft", "diamond_shovel" ), Items.DIAMOND_SHOVEL );
|
||||
public static TurtleTool diamondPickaxe = new TurtleTool( new Identifier( "minecraft", "diamond_pickaxe" ), Items.DIAMOND_PICKAXE );
|
||||
public static TurtleAxe diamondAxe = new TurtleAxe( new Identifier( "minecraft", "diamond_axe" ), Items.DIAMOND_AXE );
|
||||
public static TurtleHoe diamondHoe = new TurtleHoe( new Identifier( "minecraft", "diamond_hoe" ), Items.DIAMOND_HOE );
|
||||
public static TurtleCraftingTable craftingTable = new TurtleCraftingTable( new ResourceLocation( "minecraft", "crafting_table" ) );
|
||||
public static TurtleSword diamondSword = new TurtleSword( new ResourceLocation( "minecraft", "diamond_sword" ), Items.DIAMOND_SWORD );
|
||||
public static TurtleShovel diamondShovel = new TurtleShovel( new ResourceLocation( "minecraft", "diamond_shovel" ), Items.DIAMOND_SHOVEL );
|
||||
public static TurtleTool diamondPickaxe = new TurtleTool( new ResourceLocation( "minecraft", "diamond_pickaxe" ), Items.DIAMOND_PICKAXE );
|
||||
public static TurtleAxe diamondAxe = new TurtleAxe( new ResourceLocation( "minecraft", "diamond_axe" ), Items.DIAMOND_AXE );
|
||||
public static TurtleHoe diamondHoe = new TurtleHoe( new ResourceLocation( "minecraft", "diamond_hoe" ), Items.DIAMOND_HOE );
|
||||
|
||||
public static TurtleTool netheritePickaxe = new TurtleTool( new Identifier( "minecraft", "netherite_pickaxe" ), Items.NETHERITE_PICKAXE );
|
||||
public static TurtleTool netheritePickaxe = new TurtleTool( new ResourceLocation( "minecraft", "netherite_pickaxe" ), Items.NETHERITE_PICKAXE );
|
||||
|
||||
public static void registerTurtleUpgrades()
|
||||
{
|
||||
|
@@ -9,9 +9,8 @@ package dan200.computercraft.shared;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.media.IMedia;
|
||||
import dan200.computercraft.api.media.IMediaProvider;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@@ -10,12 +10,11 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||
import dan200.computercraft.shared.peripheral.generic.GenericPeripheralProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
@@ -33,13 +32,13 @@ public final class Peripherals
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IPeripheral getPeripheral( World world, BlockPos pos, Direction side )
|
||||
public static IPeripheral getPeripheral( Level world, BlockPos pos, Direction side )
|
||||
{
|
||||
return world.isInBuildLimit( pos ) && !world.isClient ? getPeripheralAt( world, pos, side ) : null;
|
||||
return world.isInWorldBounds( pos ) && !world.isClientSide ? getPeripheralAt( world, pos, side ) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IPeripheral getPeripheralAt( World world, BlockPos pos, Direction side )
|
||||
private static IPeripheral getPeripheralAt( Level world, BlockPos pos, Direction side )
|
||||
{
|
||||
// Try the handlers in order:
|
||||
for( IPeripheralProvider peripheralProvider : providers )
|
||||
|
@@ -9,9 +9,8 @@ import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenCustomHashMap;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
@@ -19,7 +18,7 @@ import java.util.*;
|
||||
public final class PocketUpgrades
|
||||
{
|
||||
private static final Map<String, IPocketUpgrade> upgrades = new HashMap<>();
|
||||
private static final Map<IPocketUpgrade, String> upgradeOwners = new Object2ObjectLinkedOpenCustomHashMap<>( Util.identityHashStrategy() );
|
||||
private static final Map<IPocketUpgrade, String> upgradeOwners = new Object2ObjectLinkedOpenCustomHashMap<>( Util.identityStrategy() );
|
||||
|
||||
private PocketUpgrades() {}
|
||||
|
||||
|
@@ -5,21 +5,21 @@
|
||||
*/
|
||||
package dan200.computercraft.shared;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public final class TurtlePermissions
|
||||
{
|
||||
public static boolean isBlockEnterable( World world, BlockPos pos, PlayerEntity player )
|
||||
public static boolean isBlockEnterable( Level world, BlockPos pos, Player player )
|
||||
{
|
||||
MinecraftServer server = world.getServer();
|
||||
return server == null || world.isClient || world instanceof ServerWorld && !server.isSpawnProtected( (ServerWorld) world, pos, player );
|
||||
return server == null || world.isClientSide || world instanceof ServerLevel && !server.isUnderSpawnProtection( (ServerLevel) world, pos, player );
|
||||
}
|
||||
|
||||
public static boolean isBlockEditable( World world, BlockPos pos, PlayerEntity player )
|
||||
public static boolean isBlockEditable( Level world, BlockPos pos, Player player )
|
||||
{
|
||||
return isBlockEnterable( world, pos, player );
|
||||
}
|
||||
|
@@ -8,10 +8,9 @@ package dan200.computercraft.shared;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@@ -6,9 +6,8 @@
|
||||
package dan200.computercraft.shared.command;
|
||||
|
||||
import dan200.computercraft.shared.util.IDAssigner;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import net.minecraft.Util;
|
||||
|
||||
/**
|
||||
* Basic client-side commands.
|
||||
@@ -42,7 +41,7 @@ public final class ClientCommands
|
||||
File file = new File( IDAssigner.getDir(), "computer/" + id );
|
||||
if( !file.isDirectory() ) return true;
|
||||
|
||||
Util.getOperatingSystem().open( file );
|
||||
Util.getPlatform().openFile( file );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@@ -23,21 +23,20 @@ import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.network.container.ViewComputerContainerData;
|
||||
import dan200.computercraft.shared.util.IDAssigner;
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.level.Level;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -52,7 +51,7 @@ import static dan200.computercraft.shared.command.builder.CommandBuilder.args;
|
||||
import static dan200.computercraft.shared.command.builder.CommandBuilder.command;
|
||||
import static dan200.computercraft.shared.command.builder.HelpingArgumentBuilder.choice;
|
||||
import static dan200.computercraft.shared.command.text.ChatHelpers.*;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public final class CommandComputerCraft
|
||||
{
|
||||
@@ -66,7 +65,7 @@ public final class CommandComputerCraft
|
||||
{
|
||||
}
|
||||
|
||||
public static void register( CommandDispatcher<ServerCommandSource> dispatcher, Boolean dedicated )
|
||||
public static void register( CommandDispatcher<CommandSourceStack> dispatcher, Boolean dedicated )
|
||||
{
|
||||
dispatcher.register( choice( "computercraft" )
|
||||
.then( literal( "dump" )
|
||||
@@ -74,17 +73,17 @@ public final class CommandComputerCraft
|
||||
.executes( context -> {
|
||||
TableBuilder table = new TableBuilder( DUMP_LIST_ID, "Computer", "On", "Position" );
|
||||
|
||||
ServerCommandSource source = context.getSource();
|
||||
CommandSourceStack source = context.getSource();
|
||||
List<ServerComputer> computers = new ArrayList<>( ComputerCraft.serverComputerRegistry.getComputers() );
|
||||
|
||||
// Unless we're on a server, limit the number of rows we can send.
|
||||
World world = source.getWorld();
|
||||
Level world = source.getLevel();
|
||||
BlockPos pos = new BlockPos( source.getPosition() );
|
||||
|
||||
computers.sort( ( a, b ) -> {
|
||||
if( a.getWorld() == b.getWorld() && a.getWorld() == world )
|
||||
{
|
||||
return Double.compare( a.getPosition().getSquaredDistance( pos ), b.getPosition().getSquaredDistance( pos ) );
|
||||
return Double.compare( a.getPosition().distSqr( pos ), b.getPosition().distSqr( pos ) );
|
||||
}
|
||||
else if( a.getWorld() == world )
|
||||
{
|
||||
@@ -148,7 +147,7 @@ public final class CommandComputerCraft
|
||||
if( computer.isOn() ) shutdown++;
|
||||
computer.shutdown();
|
||||
}
|
||||
context.getSource().sendFeedback( translate( "commands.computercraft.shutdown.done", shutdown, computers.size() ), false );
|
||||
context.getSource().sendSuccess( translate( "commands.computercraft.shutdown.done", shutdown, computers.size() ), false );
|
||||
return shutdown;
|
||||
} ) )
|
||||
|
||||
@@ -162,7 +161,7 @@ public final class CommandComputerCraft
|
||||
if( !computer.isOn() ) on++;
|
||||
computer.turnOn();
|
||||
}
|
||||
context.getSource().sendFeedback( translate( "commands.computercraft.turn_on.done", on, computers.size() ), false );
|
||||
context.getSource().sendSuccess( translate( "commands.computercraft.turn_on.done", on, computers.size() ), false );
|
||||
return on;
|
||||
} ) )
|
||||
|
||||
@@ -171,25 +170,25 @@ public final class CommandComputerCraft
|
||||
.arg( "computer", oneComputer() )
|
||||
.executes( context -> {
|
||||
ServerComputer computer = getComputerArgument( context, "computer" );
|
||||
World world = computer.getWorld();
|
||||
Level world = computer.getWorld();
|
||||
BlockPos pos = computer.getPosition();
|
||||
|
||||
if( world == null || pos == null ) throw TP_NOT_THERE.create();
|
||||
|
||||
Entity entity = context.getSource().getEntityOrThrow();
|
||||
if( !(entity instanceof ServerPlayerEntity) ) throw TP_NOT_PLAYER.create();
|
||||
Entity entity = context.getSource().getEntityOrException();
|
||||
if( !(entity instanceof ServerPlayer) ) throw TP_NOT_PLAYER.create();
|
||||
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) entity;
|
||||
if( player.getEntityWorld() == world )
|
||||
ServerPlayer player = (ServerPlayer) entity;
|
||||
if( player.getCommandSenderWorld() == world )
|
||||
{
|
||||
player.networkHandler.requestTeleport(
|
||||
player.connection.teleport(
|
||||
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0,
|
||||
EnumSet.noneOf( PlayerPositionLookS2CPacket.Flag.class )
|
||||
EnumSet.noneOf( ClientboundPlayerPositionPacket.RelativeArgument.class )
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.teleport( (ServerWorld) world,
|
||||
player.teleportTo( (ServerLevel) world,
|
||||
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0
|
||||
);
|
||||
}
|
||||
@@ -222,28 +221,28 @@ public final class CommandComputerCraft
|
||||
.requires( UserLevel.OP )
|
||||
.arg( "computer", oneComputer() )
|
||||
.executes( context -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayer();
|
||||
ServerPlayer player = context.getSource().getPlayerOrException();
|
||||
ServerComputer computer = getComputerArgument( context, "computer" );
|
||||
computer.sendTerminalState( player );
|
||||
ViewComputerContainerData container = new ViewComputerContainerData( computer );
|
||||
container.open( player, new ExtendedScreenHandlerFactory()
|
||||
{
|
||||
@Override
|
||||
public void writeScreenOpeningData( ServerPlayerEntity player, PacketByteBuf buf )
|
||||
public void writeScreenOpeningData( ServerPlayer player, FriendlyByteBuf buf )
|
||||
{
|
||||
container.toBytes( buf );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MutableText getDisplayName()
|
||||
public MutableComponent getDisplayName()
|
||||
{
|
||||
return new TranslatableText( "gui.computercraft.view_computer" );
|
||||
return new TranslatableComponent( "gui.computercraft.view_computer" );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ScreenHandler createMenu( int id, @Nonnull PlayerInventory player, @Nonnull PlayerEntity entity )
|
||||
public AbstractContainerMenu createMenu( int id, @Nonnull Inventory player, @Nonnull Player entity )
|
||||
{
|
||||
return new ContainerViewComputer( id, player, computer );
|
||||
}
|
||||
@@ -258,7 +257,7 @@ public final class CommandComputerCraft
|
||||
getTimingContext( context.getSource() ).start();
|
||||
|
||||
String stopCommand = "/computercraft track stop";
|
||||
context.getSource().sendFeedback( translate( "commands.computercraft.track.start.stop",
|
||||
context.getSource().sendSuccess( translate( "commands.computercraft.track.start.stop",
|
||||
link( text( stopCommand ), stopCommand, translate( "commands.computercraft.track.stop.action" ) ) ), false );
|
||||
return 1;
|
||||
} ) )
|
||||
@@ -292,9 +291,9 @@ public final class CommandComputerCraft
|
||||
);
|
||||
}
|
||||
|
||||
private static MutableText linkComputer( ServerCommandSource source, ServerComputer serverComputer, int computerId )
|
||||
private static MutableComponent linkComputer( CommandSourceStack source, ServerComputer serverComputer, int computerId )
|
||||
{
|
||||
MutableText out = new LiteralText( "" );
|
||||
MutableComponent out = new TextComponent( "" );
|
||||
|
||||
// Append the computer instance
|
||||
if( serverComputer == null )
|
||||
@@ -333,14 +332,14 @@ public final class CommandComputerCraft
|
||||
|
||||
if( UserLevel.OWNER.test( source ) && isPlayer( source ) )
|
||||
{
|
||||
MutableText linkPath = linkStorage( computerId );
|
||||
MutableComponent linkPath = linkStorage( computerId );
|
||||
if( linkPath != null ) out.append( " " ).append( linkPath );
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
private static MutableText linkPosition( ServerCommandSource context, ServerComputer computer )
|
||||
private static MutableComponent linkPosition( CommandSourceStack context, ServerComputer computer )
|
||||
{
|
||||
if( UserLevel.OP.test( context ) )
|
||||
{
|
||||
@@ -356,7 +355,7 @@ public final class CommandComputerCraft
|
||||
}
|
||||
}
|
||||
|
||||
private static MutableText linkStorage( int id )
|
||||
private static MutableComponent linkStorage( int id )
|
||||
{
|
||||
File file = new File( IDAssigner.getDir(), "computer/" + id );
|
||||
if( !file.isDirectory() ) return null;
|
||||
@@ -369,20 +368,20 @@ public final class CommandComputerCraft
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static TrackingContext getTimingContext( ServerCommandSource source )
|
||||
private static TrackingContext getTimingContext( CommandSourceStack source )
|
||||
{
|
||||
Entity entity = source.getEntity();
|
||||
return entity instanceof PlayerEntity ? Tracking.getContext( entity.getUuid() ) : Tracking.getContext( SYSTEM_UUID );
|
||||
return entity instanceof Player ? Tracking.getContext( entity.getUUID() ) : 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 int displayTimings( ServerCommandSource source, TrackingField sortField, List<TrackingField> fields ) throws CommandSyntaxException
|
||||
private static int displayTimings( CommandSourceStack source, TrackingField sortField, List<TrackingField> fields ) throws CommandSyntaxException
|
||||
{
|
||||
return displayTimings( source, getTimingContext( source ).getTimings(), sortField, fields );
|
||||
}
|
||||
|
||||
private static int displayTimings( ServerCommandSource source, @Nonnull List<ComputerTracker> timings, @Nonnull TrackingField sortField, @Nonnull List<TrackingField> fields ) throws CommandSyntaxException
|
||||
private static int displayTimings( CommandSourceStack source, @Nonnull List<ComputerTracker> timings, @Nonnull TrackingField sortField, @Nonnull List<TrackingField> fields ) throws CommandSyntaxException
|
||||
{
|
||||
if( timings.isEmpty() ) throw NO_TIMINGS_EXCEPTION.create();
|
||||
|
||||
@@ -398,7 +397,7 @@ public final class CommandComputerCraft
|
||||
|
||||
timings.sort( Comparator.<ComputerTracker, Long>comparing( x -> x.get( sortField ) ).reversed() );
|
||||
|
||||
MutableText[] headers = new MutableText[1 + fields.size()];
|
||||
MutableComponent[] headers = new MutableComponent[1 + fields.size()];
|
||||
headers[0] = translate( "commands.computercraft.track.dump.computer" );
|
||||
for( int i = 0; i < fields.size(); i++ ) headers[i + 1] = translate( fields.get( i ).translationKey() );
|
||||
TableBuilder table = new TableBuilder( TRACK_ID, headers );
|
||||
@@ -408,9 +407,9 @@ public final class CommandComputerCraft
|
||||
Computer computer = entry.getComputer();
|
||||
ServerComputer serverComputer = computer == null ? null : lookup.get( computer );
|
||||
|
||||
MutableText computerComponent = linkComputer( source, serverComputer, entry.getComputerId() );
|
||||
MutableComponent computerComponent = linkComputer( source, serverComputer, entry.getComputerId() );
|
||||
|
||||
MutableText[] row = new MutableText[1 + fields.size()];
|
||||
MutableComponent[] row = new MutableComponent[1 + fields.size()];
|
||||
row[0] = computerComponent;
|
||||
for( int i = 0; i < fields.size(); i++ ) row[i + 1] = text( entry.getFormatted( fields.get( i ) ) );
|
||||
table.row( row );
|
||||
|
@@ -10,42 +10,41 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import dan200.computercraft.api.turtle.FakePlayer;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
public final class CommandUtils
|
||||
{
|
||||
private CommandUtils() {}
|
||||
|
||||
public static boolean isPlayer( ServerCommandSource output )
|
||||
public static boolean isPlayer( CommandSourceStack output )
|
||||
{
|
||||
Entity sender = output.getEntity();
|
||||
return sender instanceof ServerPlayerEntity && !(sender instanceof FakePlayer) && ((ServerPlayerEntity) sender).networkHandler != null;
|
||||
return sender instanceof ServerPlayer && !(sender instanceof FakePlayer) && ((ServerPlayer) sender).connection != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
public static CompletableFuture<Suggestions> suggestOnServer( CommandContext<?> context, SuggestionsBuilder builder,
|
||||
Function<CommandContext<ServerCommandSource>, CompletableFuture<Suggestions>> supplier )
|
||||
Function<CommandContext<CommandSourceStack>, CompletableFuture<Suggestions>> supplier )
|
||||
{
|
||||
Object source = context.getSource();
|
||||
if( !(source instanceof CommandSource) )
|
||||
if( !(source instanceof SharedSuggestionProvider) )
|
||||
{
|
||||
return Suggestions.empty();
|
||||
}
|
||||
else if( source instanceof ServerCommandSource )
|
||||
else if( source instanceof CommandSourceStack )
|
||||
{
|
||||
return supplier.apply( (CommandContext<ServerCommandSource>) context );
|
||||
return supplier.apply( (CommandContext<CommandSourceStack>) context );
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((CommandSource) source).getCompletions( (CommandContext<CommandSource>) context, builder );
|
||||
return ((SharedSuggestionProvider) source).customSuggestion( (CommandContext<SharedSuggestionProvider>) context, builder );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ package dan200.computercraft.shared.command;
|
||||
import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType;
|
||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
public final class Exceptions
|
||||
{
|
||||
@@ -25,16 +25,16 @@ public final class Exceptions
|
||||
|
||||
private static SimpleCommandExceptionType translated( String key )
|
||||
{
|
||||
return new SimpleCommandExceptionType( new TranslatableText( key ) );
|
||||
return new SimpleCommandExceptionType( new TranslatableComponent( key ) );
|
||||
}
|
||||
|
||||
private static DynamicCommandExceptionType translated1( String key )
|
||||
{
|
||||
return new DynamicCommandExceptionType( x -> new TranslatableText( key, x ) );
|
||||
return new DynamicCommandExceptionType( x -> new TranslatableComponent( key, x ) );
|
||||
}
|
||||
|
||||
private static Dynamic2CommandExceptionType translated2( String key )
|
||||
{
|
||||
return new Dynamic2CommandExceptionType( ( x, y ) -> new TranslatableText( key, x, y ) );
|
||||
return new Dynamic2CommandExceptionType( ( x, y ) -> new TranslatableComponent( key, x, y ) );
|
||||
}
|
||||
}
|
||||
|
@@ -5,17 +5,16 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.command;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* The level a user must be at in order to execute a command.
|
||||
*/
|
||||
public enum UserLevel implements Predicate<ServerCommandSource>
|
||||
public enum UserLevel implements Predicate<CommandSourceStack>
|
||||
{
|
||||
/**
|
||||
* Only can be used by the owner of the server: namely the server console or the player in SSP.
|
||||
@@ -53,20 +52,20 @@ public enum UserLevel implements Predicate<ServerCommandSource>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test( ServerCommandSource source )
|
||||
public boolean test( CommandSourceStack source )
|
||||
{
|
||||
if( this == ANYONE ) return true;
|
||||
if( this == OWNER ) return isOwner( source );
|
||||
if( this == OWNER_OP && isOwner( source ) ) return true;
|
||||
return source.hasPermissionLevel( toLevel() );
|
||||
return source.hasPermission( toLevel() );
|
||||
}
|
||||
|
||||
private static boolean isOwner( ServerCommandSource source )
|
||||
private static boolean isOwner( CommandSourceStack source )
|
||||
{
|
||||
MinecraftServer server = source.getServer();
|
||||
Entity sender = source.getEntity();
|
||||
return server.isDedicated()
|
||||
? source.getEntity() == null && source.hasPermissionLevel( 4 ) && source.getName().equals( "Server" )
|
||||
: sender instanceof PlayerEntity && ((PlayerEntity) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() );
|
||||
return server.isDedicatedServer()
|
||||
? source.getEntity() == null && source.hasPermission( 4 ) && source.getTextName().equals( "Server" )
|
||||
: sender instanceof Player && ((Player) sender).getGameProfile().getName().equalsIgnoreCase( server.getServerModName() );
|
||||
}
|
||||
}
|
||||
|
@@ -8,33 +8,33 @@ package dan200.computercraft.shared.command.arguments;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import net.minecraft.command.argument.ArgumentTypes;
|
||||
import net.minecraft.command.argument.serialize.ArgumentSerializer;
|
||||
import net.minecraft.command.argument.serialize.ConstantArgumentSerializer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.commands.synchronization.ArgumentSerializer;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypes;
|
||||
import net.minecraft.commands.synchronization.EmptyArgumentSerializer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public final class ArgumentSerializers
|
||||
{
|
||||
public static void register()
|
||||
{
|
||||
register( new Identifier( ComputerCraft.MOD_ID, "tracking_field" ), TrackingFieldArgumentType.trackingField() );
|
||||
register( new Identifier( ComputerCraft.MOD_ID, "computer" ), ComputerArgumentType.oneComputer() );
|
||||
register( new Identifier( ComputerCraft.MOD_ID, "computers" ), ComputersArgumentType.class, new ComputersArgumentType.Serializer() );
|
||||
registerUnsafe( new Identifier( ComputerCraft.MOD_ID, "repeat" ), RepeatArgumentType.class, new RepeatArgumentType.Serializer() );
|
||||
register( new ResourceLocation( ComputerCraft.MOD_ID, "tracking_field" ), TrackingFieldArgumentType.trackingField() );
|
||||
register( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ), ComputerArgumentType.oneComputer() );
|
||||
register( new ResourceLocation( ComputerCraft.MOD_ID, "computers" ), ComputersArgumentType.class, new ComputersArgumentType.Serializer() );
|
||||
registerUnsafe( new ResourceLocation( ComputerCraft.MOD_ID, "repeat" ), RepeatArgumentType.class, new RepeatArgumentType.Serializer() );
|
||||
}
|
||||
|
||||
private static <T extends ArgumentType<?>> void register( Identifier id, T instance )
|
||||
private static <T extends ArgumentType<?>> void register( ResourceLocation id, T instance )
|
||||
{
|
||||
registerUnsafe( id, instance.getClass(), new ConstantArgumentSerializer<>( () -> instance ) );
|
||||
registerUnsafe( id, instance.getClass(), new EmptyArgumentSerializer<>( () -> instance ) );
|
||||
}
|
||||
|
||||
private static <T extends ArgumentType<?>> void register( Identifier id, Class<T> type, ArgumentSerializer<T> serializer )
|
||||
private static <T extends ArgumentType<?>> void register( ResourceLocation id, Class<T> type, ArgumentSerializer<T> serializer )
|
||||
{
|
||||
ArgumentTypes.register( id.toString(), type, serializer );
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
private static <T extends ArgumentType<?>> void registerUnsafe( Identifier id, Class<T> type, ArgumentSerializer<?> serializer )
|
||||
private static <T extends ArgumentType<?>> void registerUnsafe( ResourceLocation id, Class<T> type, ArgumentSerializer<?> serializer )
|
||||
{
|
||||
ArgumentTypes.register( id.toString(), type, (ArgumentSerializer<T>) serializer );
|
||||
}
|
||||
|
@@ -14,10 +14,9 @@ import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import dan200.computercraft.shared.command.arguments.ComputersArgumentType.ComputersSupplier;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import static dan200.computercraft.shared.command.Exceptions.COMPUTER_ARG_MANY;
|
||||
|
||||
@@ -34,7 +33,7 @@ public final class ComputerArgumentType implements ArgumentType<ComputerArgument
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static ServerComputer getComputerArgument( CommandContext<ServerCommandSource> context, String name ) throws CommandSyntaxException
|
||||
public static ServerComputer getComputerArgument( CommandContext<CommandSourceStack> context, String name ) throws CommandSyntaxException
|
||||
{
|
||||
return context.getArgument( name, ComputerSupplier.class )
|
||||
.unwrap( context.getSource() );
|
||||
@@ -98,6 +97,6 @@ public final class ComputerArgumentType implements ArgumentType<ComputerArgument
|
||||
@FunctionalInterface
|
||||
public interface ComputerSupplier
|
||||
{
|
||||
ServerComputer unwrap( ServerCommandSource source ) throws CommandSyntaxException;
|
||||
ServerComputer unwrap( CommandSourceStack source ) throws CommandSyntaxException;
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,10 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import net.minecraft.command.argument.serialize.ArgumentSerializer;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.synchronization.ArgumentSerializer;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
@@ -54,13 +53,13 @@ public final class ComputersArgumentType implements ArgumentType<ComputersArgume
|
||||
return SOME;
|
||||
}
|
||||
|
||||
public static Collection<ServerComputer> getComputersArgument( CommandContext<ServerCommandSource> context, String name ) throws CommandSyntaxException
|
||||
public static Collection<ServerComputer> getComputersArgument( CommandContext<CommandSourceStack> context, String name ) throws CommandSyntaxException
|
||||
{
|
||||
return context.getArgument( name, ComputersSupplier.class )
|
||||
.unwrap( context.getSource() );
|
||||
}
|
||||
|
||||
public static Set<ServerComputer> unwrap( ServerCommandSource source, Collection<ComputersSupplier> suppliers ) throws CommandSyntaxException
|
||||
public static Set<ServerComputer> unwrap( CommandSourceStack source, Collection<ComputersSupplier> suppliers ) throws CommandSyntaxException
|
||||
{
|
||||
Set<ServerComputer> computers = new HashSet<>();
|
||||
for( ComputersSupplier supplier : suppliers )
|
||||
@@ -188,21 +187,21 @@ public final class ComputersArgumentType implements ArgumentType<ComputersArgume
|
||||
@FunctionalInterface
|
||||
public interface ComputersSupplier
|
||||
{
|
||||
Collection<ServerComputer> unwrap( ServerCommandSource source ) throws CommandSyntaxException;
|
||||
Collection<ServerComputer> unwrap( CommandSourceStack source ) throws CommandSyntaxException;
|
||||
}
|
||||
|
||||
public static class Serializer implements ArgumentSerializer<ComputersArgumentType>
|
||||
{
|
||||
|
||||
@Override
|
||||
public void toPacket( @Nonnull ComputersArgumentType arg, @Nonnull PacketByteBuf buf )
|
||||
public void toPacket( @Nonnull ComputersArgumentType arg, @Nonnull FriendlyByteBuf buf )
|
||||
{
|
||||
buf.writeBoolean( arg.requireSome );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ComputersArgumentType fromPacket( @Nonnull PacketByteBuf buf )
|
||||
public ComputersArgumentType deserializeFromNetwork( @Nonnull FriendlyByteBuf buf )
|
||||
{
|
||||
return buf.readBoolean() ? SOME : MANY;
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user