mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-02 14:43:00 +00:00
Compare commits
60 Commits
v1.15.2-1.
...
v1.16.5-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efa2be2821 | ||
|
|
670db97fc7 | ||
|
|
a5bca3f0df | ||
|
|
5ef8d52c13 | ||
|
|
3ab3213290 | ||
|
|
9bd662d8dc | ||
|
|
df7a40354e | ||
|
|
2d3e88ef59 | ||
|
|
0bfe960cbd | ||
|
|
db2cde4a4c | ||
|
|
5eec7d9172 | ||
|
|
8b9735d72e | ||
|
|
1866916cb8 | ||
|
|
f38a6a9d43 | ||
|
|
7f9b86a78e | ||
|
|
f0ba1108d5 | ||
|
|
8b8692ba53 | ||
|
|
f387730b88 | ||
|
|
8c56b6a7be | ||
|
|
7514cf7320 | ||
|
|
417fda3019 | ||
|
|
23bf33c454 | ||
|
|
0be030c497 | ||
|
|
a3a9684505 | ||
|
|
c5694ea966 | ||
|
|
7b476cb24b | ||
|
|
7ca261d763 | ||
|
|
1edb7288b9 | ||
|
|
4af5bcc0b0 | ||
|
|
96c577482d | ||
|
|
61f8e97f6b | ||
|
|
c92f06cfd9 | ||
|
|
c9f3d315c0 | ||
|
|
83df64e520 | ||
|
|
ab232bd689 | ||
|
|
5bf367af9f | ||
|
|
4766833cf2 | ||
|
|
71563a52ff | ||
|
|
0c6e7b5db5 | ||
|
|
72c1d451fe | ||
|
|
8b4a01df27 | ||
|
|
d0a973fa46 | ||
|
|
26c12ac1a9 | ||
|
|
2c67849b35 | ||
|
|
7809a2eddd | ||
|
|
e8e9294fdf | ||
|
|
99581e1f40 | ||
|
|
29646a7f61 | ||
|
|
50d2712581 | ||
|
|
3093f882d8 | ||
|
|
e5cf0d1c61 | ||
|
|
6b102a8142 | ||
|
|
c8a6888a2f | ||
|
|
9ce33f8a3f | ||
|
|
a1dcd59d95 | ||
|
|
2a17585702 | ||
|
|
087c305b0d | ||
|
|
31764f6d65 | ||
|
|
4efde2b294 | ||
|
|
46595e73df |
2
.github/workflows/make-doc.yml
vendored
2
.github/workflows/make-doc.yml
vendored
@@ -3,7 +3,7 @@ name: Build documentation
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- mc-1.16.x
|
||||
- mc-1.15.x
|
||||
|
||||
jobs:
|
||||
make_doc:
|
||||
|
||||
57
build.gradle
57
build.gradle
@@ -8,7 +8,7 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.google.code.gson:gson:2.8.1'
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:5.0.6'
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:5.0.12'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ minecraft {
|
||||
testServer {
|
||||
workingDirectory project.file('test-files/server')
|
||||
parent runs.server
|
||||
arg "--nogui"
|
||||
|
||||
mods {
|
||||
cctest {
|
||||
@@ -106,9 +107,10 @@ minecraft {
|
||||
}
|
||||
}
|
||||
|
||||
mappings channel: 'official', version: project.mc_version
|
||||
mappings channel: 'official', version: mc_version
|
||||
|
||||
accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
accessTransformer file('src/test/resources/META-INF/accesstransformer.cfg')
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -136,10 +138,11 @@ dependencies {
|
||||
|
||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
||||
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.3:api")
|
||||
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.15.2:6.0.0.9")
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.7.0.104:api")
|
||||
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.16.5:7.1.0.313")
|
||||
compileOnly fg.deobf("commoble.morered:morered-1.16.5:2.1.1.0")
|
||||
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.3")
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.7.0.104")
|
||||
|
||||
shade 'org.squiddev:Cobalt:0.5.2-SNAPSHOT'
|
||||
|
||||
@@ -179,12 +182,12 @@ task luaJavadoc(type: Javadoc) {
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(["Specification-Title": "computercraft",
|
||||
"Specification-Vendor": "SquidDev",
|
||||
"Specification-Version": "1",
|
||||
"Implementation-Title": "CC: Tweaked",
|
||||
"Implementation-Version": "${mod_version}",
|
||||
"Implementation-Vendor" :"SquidDev",
|
||||
attributes(["Specification-Title" : "computercraft",
|
||||
"Specification-Vendor" : "SquidDev",
|
||||
"Specification-Version" : "1",
|
||||
"Implementation-Title" : "CC: Tweaked",
|
||||
"Implementation-Version" : "${mod_version}",
|
||||
"Implementation-Vendor" : "SquidDev",
|
||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")])
|
||||
}
|
||||
|
||||
@@ -210,7 +213,7 @@ processResources {
|
||||
["git", "-C", projectDir, "log", "--format=tformat:%an%n%cn"].execute().text.split('\n').each {
|
||||
if (!blacklist.contains(it)) contributors.add(it)
|
||||
}
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
inputs.property "commithash", hash
|
||||
@@ -221,8 +224,8 @@ processResources {
|
||||
include 'data/computercraft/lua/rom/help/credits.txt'
|
||||
|
||||
expand 'version': mod_version,
|
||||
'mcversion': mc_version,
|
||||
'gitcontributors': contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
|
||||
'mcversion': mc_version,
|
||||
'gitcontributors': contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
@@ -237,6 +240,9 @@ sourcesJar {
|
||||
|
||||
// Web tasks
|
||||
|
||||
|
||||
import com.hierynomus.gradle.license.tasks.LicenseCheck
|
||||
import com.hierynomus.gradle.license.tasks.LicenseFormat
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
List<String> mkCommand(String command) {
|
||||
@@ -306,10 +312,6 @@ jacocoTestReport {
|
||||
|
||||
check.dependsOn jacocoTestReport
|
||||
|
||||
|
||||
import com.hierynomus.gradle.license.tasks.LicenseCheck
|
||||
import com.hierynomus.gradle.license.tasks.LicenseFormat
|
||||
|
||||
license {
|
||||
mapping("java", "SLASHSTAR_STYLE")
|
||||
strictCheck true
|
||||
@@ -339,8 +341,8 @@ gradle.projectsEvaluated {
|
||||
}
|
||||
|
||||
|
||||
task licenseAPI(type: LicenseCheck);
|
||||
task licenseFormatAPI(type: LicenseFormat);
|
||||
task licenseAPI(type: LicenseCheck)
|
||||
task licenseFormatAPI(type: LicenseFormat)
|
||||
[licenseAPI, licenseFormatAPI].forEach {
|
||||
it.configure {
|
||||
source = sourceSets.main.java
|
||||
@@ -436,7 +438,7 @@ task checkRelease {
|
||||
ok = false
|
||||
project.logger.error("Must mention the changelog in whatsnew.md")
|
||||
} else {
|
||||
whatsnew = whatsnew.getAt(0 ..< idx)
|
||||
whatsnew = whatsnew.getAt(0..<idx)
|
||||
}
|
||||
|
||||
// Check whatsnew and changelog match.
|
||||
@@ -472,12 +474,11 @@ tasks.register('publishModrinth', TaskModrinthUpload.class).configure {
|
||||
project.hasProperty('modrinthApiKey')
|
||||
}
|
||||
|
||||
token = project.hasProperty('modrinthApiKey') ? project.getProperty('modrinthApiKey') : ''
|
||||
token = project.hasProperty('curseForgeApiKey')
|
||||
projectId = 'gu7yAYhd'
|
||||
versionNumber = "${project.mc_version}-${project.mod_version}"
|
||||
versionNumber = project.mod_version
|
||||
uploadFile = jar
|
||||
addGameVersion(project.mc_version)
|
||||
changelog = "Release notes can be found on the [GitHub repository](https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
|
||||
addLoader('forge')
|
||||
}
|
||||
|
||||
@@ -547,10 +548,10 @@ githubRelease {
|
||||
tagName "v${mc_version}-${mod_version}"
|
||||
releaseName "[${mc_version}] ${mod_version}"
|
||||
body.set(project.provider({
|
||||
"## " + new File(projectDir, "src/main/resources/data/computercraft/lua/rom/help/whatsnew.md")
|
||||
.readLines()
|
||||
.takeWhile { it != 'Type "help changelog" to see the full version history.' }
|
||||
.join("\n").trim()
|
||||
"## " + new File(projectDir, "src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
|
||||
.readLines()
|
||||
.takeWhile { it != 'Type "help changelog" to see the full version history.' }
|
||||
.join("\n").trim()
|
||||
}))
|
||||
prerelease false
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Mod properties
|
||||
mod_version=1.97.1
|
||||
mod_version=1.97.0
|
||||
|
||||
# Minecraft properties (update mods.toml when changing)
|
||||
mc_version=1.15.2
|
||||
forge_version=31.1.41
|
||||
mc_version=1.16.5
|
||||
forge_version=36.1.0
|
||||
# NO SERIOUSLY, UPDATE mods.toml WHEN CHANGING
|
||||
|
||||
10
src/generated/resources/data/minecraft/tags/items/piglin_loved.json
generated
Normal file
10
src/generated/resources/data/minecraft/tags/items/piglin_loved.json
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"computercraft:computer_advanced",
|
||||
"computercraft:turtle_advanced",
|
||||
"computercraft:wireless_modem_advanced",
|
||||
"computercraft:pocket_computer_advanced",
|
||||
"computercraft:monitor_advanced"
|
||||
]
|
||||
}
|
||||
@@ -52,8 +52,6 @@ public final class ComputerCraft
|
||||
|
||||
public static int httpMaxRequests = 16;
|
||||
public static int httpMaxWebsockets = 4;
|
||||
public static int httpDownloadBandwidth = 32 * 1024 * 1024;
|
||||
public static int httpUploadBandwidth = 32 * 1024 * 1024;
|
||||
|
||||
public static boolean enableCommandBlock = false;
|
||||
public static int modemRange = 64;
|
||||
|
||||
@@ -58,7 +58,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
|
||||
public static InputStream getResourceFile( String domain, String subPath )
|
||||
{
|
||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResources();
|
||||
IReloadableResourceManager manager = (IReloadableResourceManager) ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().getResourceManager();
|
||||
try
|
||||
{
|
||||
return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
|
||||
@@ -101,7 +101,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
@Override
|
||||
public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
|
||||
{
|
||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResources();
|
||||
IReloadableResourceManager manager = (IReloadableResourceManager) ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().getResourceManager();
|
||||
ResourceMount mount = ResourceMount.get( domain, subPath, manager );
|
||||
return mount.exists( "" ) ? mount : null;
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
package dan200.computercraft.api.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ModelManager;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -29,7 +29,7 @@ public interface IPacketReceiver
|
||||
* @return The receiver's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vector3d getPosition();
|
||||
|
||||
/**
|
||||
* Get the maximum distance this receiver can send and receive messages.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -29,7 +29,7 @@ public interface IPacketSender
|
||||
* @return The sender's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vector3d getPosition();
|
||||
|
||||
/**
|
||||
* Get some sort of identification string for this sender. This does not strictly need to be unique, but you
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
@@ -67,7 +67,7 @@ public interface ITurtleAccess
|
||||
* @see #getVisualYaw(float)
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getVisualPosition( float f );
|
||||
Vector3d getVisualPosition( float f );
|
||||
|
||||
/**
|
||||
* Returns the yaw the turtle is facing when it is rendered.
|
||||
|
||||
@@ -24,6 +24,9 @@ import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.item.IItemPropertyGetter;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemModelsProperties;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ColorHandlerEvent;
|
||||
@@ -35,6 +38,8 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Registers textures and models for items.
|
||||
*/
|
||||
@@ -137,8 +142,28 @@ public final class ClientRegistry
|
||||
net.minecraftforge.fml.client.registry.ClientRegistry.bindTileEntityRenderer( Registry.ModTiles.TURTLE_ADVANCED.get(), TileEntityTurtleRenderer::new );
|
||||
|
||||
RenderingRegistry.registerEntityRenderingHandler( Registry.ModEntities.TURTLE_PLAYER.get(), TurtlePlayerRenderer::new );
|
||||
|
||||
registerItemProperty( "state",
|
||||
( stack, world, player ) -> ItemPocketComputer.getState( stack ).ordinal(),
|
||||
Registry.ModItems.POCKET_COMPUTER_NORMAL, Registry.ModItems.POCKET_COMPUTER_ADVANCED
|
||||
);
|
||||
registerItemProperty( "coloured",
|
||||
( stack, world, player ) -> IColouredItem.getColourBasic( stack ) != -1 ? 1 : 0,
|
||||
Registry.ModItems.POCKET_COMPUTER_NORMAL, Registry.ModItems.POCKET_COMPUTER_ADVANCED
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static void registerItemProperty( String name, IItemPropertyGetter getter, Supplier<? extends Item>... items )
|
||||
{
|
||||
ResourceLocation id = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
||||
for( Supplier<? extends Item> item : items )
|
||||
{
|
||||
ItemModelsProperties.register( item.get(), id, getter );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void registerContainers()
|
||||
{
|
||||
// My IDE doesn't think so, but we do actually need these generics.
|
||||
|
||||
@@ -12,14 +12,12 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.NewChatGui;
|
||||
import net.minecraft.client.gui.RenderComponentsUtil;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientTableFormatter implements TableFormatter
|
||||
{
|
||||
@@ -57,7 +55,7 @@ public class ClientTableFormatter implements TableFormatter
|
||||
@Override
|
||||
public int getWidth( ITextComponent component )
|
||||
{
|
||||
return renderer().width( component.getColoredString() );
|
||||
return renderer().width( component );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,10 +64,11 @@ public class ClientTableFormatter implements TableFormatter
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
NewChatGui chat = mc.gui.getChat();
|
||||
|
||||
// Trim the text if it goes over the allowed length
|
||||
int maxWidth = MathHelper.floor( chat.getWidth() / chat.getScale() );
|
||||
List<ITextComponent> list = RenderComponentsUtil.wrapComponents( component, maxWidth, mc.font, false, false );
|
||||
if( !list.isEmpty() ) chat.addMessage( list.get( 0 ), id );
|
||||
// TODO: Trim the text if it goes over the allowed length
|
||||
// int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() );
|
||||
// List<ITextProperties> list = RenderComponentsUtil.wrapComponents( component, maxWidth, mc.fontRenderer );
|
||||
// if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
|
||||
chat.addMessage( component, id );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.minecraft.client.audio.LocatableSound;
|
||||
import net.minecraft.client.audio.SoundHandler;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -22,7 +22,7 @@ public class SoundManager
|
||||
{
|
||||
private static final Map<UUID, MoveableSound> sounds = new HashMap<>();
|
||||
|
||||
public static void playSound( UUID source, Vec3d position, SoundEvent event, float volume, float pitch )
|
||||
public static void playSound( UUID source, Vector3d position, SoundEvent event, float volume, float pitch )
|
||||
{
|
||||
SoundHandler soundManager = Minecraft.getInstance().getSoundManager();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SoundManager
|
||||
Minecraft.getInstance().getSoundManager().stop( sound );
|
||||
}
|
||||
|
||||
public static void moveSound( UUID source, Vec3d position )
|
||||
public static void moveSound( UUID source, Vector3d position )
|
||||
{
|
||||
MoveableSound sound = sounds.get( source );
|
||||
if( sound != null ) sound.setPosition( position );
|
||||
@@ -55,7 +55,7 @@ public class SoundManager
|
||||
|
||||
private static class MoveableSound extends LocatableSound implements ITickableSound
|
||||
{
|
||||
protected MoveableSound( SoundEvent sound, Vec3d position, float volume, float pitch )
|
||||
protected MoveableSound( SoundEvent sound, Vector3d position, float volume, float pitch )
|
||||
{
|
||||
super( sound, SoundCategory.RECORDS );
|
||||
setPosition( position );
|
||||
@@ -63,7 +63,7 @@ public class SoundManager
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
void setPosition( Vec3d position )
|
||||
void setPosition( Vector3d position )
|
||||
{
|
||||
x = (float) position.x();
|
||||
y = (float) position.y();
|
||||
|
||||
@@ -5,19 +5,41 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
||||
import dan200.computercraft.shared.computer.upload.FileUpload;
|
||||
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.inventory.ContainerScreen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ComputerScreenBase<T extends ContainerComputerBase> extends ContainerScreen<T>
|
||||
{
|
||||
private static final ITextComponent OK = new TranslationTextComponent( "gui.ok" );
|
||||
private static final ITextComponent CANCEL = new TranslationTextComponent( "gui.cancel" );
|
||||
private static final ITextComponent OVERWRITE = new TranslationTextComponent( "gui.computercraft.upload.overwrite_button" );
|
||||
|
||||
protected WidgetTerminal terminal;
|
||||
protected final ClientComputer computer;
|
||||
protected final ComputerFamily family;
|
||||
@@ -73,16 +95,11 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
|
||||
|
||||
@Override
|
||||
public final void render( int mouseX, int mouseY, float partialTicks )
|
||||
public final void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
|
||||
for( Widget widget : buttons )
|
||||
{
|
||||
if( widget.isHovered() ) widget.renderToolTip( mouseX, mouseY );
|
||||
}
|
||||
renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
renderTooltip( stack, mouseX, mouseY );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,4 +108,101 @@ public abstract class ComputerScreenBase<T extends ContainerComputerBase> extend
|
||||
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|
||||
|| super.mouseDragged( x, y, button, deltaX, deltaY );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void renderLabels( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFilesDrop( @Nonnull List<Path> files )
|
||||
{
|
||||
if( files.isEmpty() ) return;
|
||||
|
||||
if( computer == null || !computer.isOn() )
|
||||
{
|
||||
alert( UploadResult.FAILED_TITLE, UploadResult.COMPUTER_OFF_MSG );
|
||||
return;
|
||||
}
|
||||
|
||||
long size = 0;
|
||||
|
||||
List<FileUpload> toUpload = new ArrayList<>();
|
||||
for( Path file : files )
|
||||
{
|
||||
// TODO: Recurse directories? If so, we probably want to shunt this off-thread.
|
||||
if( !Files.isRegularFile( file ) ) continue;
|
||||
|
||||
try( SeekableByteChannel sbc = Files.newByteChannel( file ) )
|
||||
{
|
||||
long fileSize = sbc.size();
|
||||
if( fileSize > UploadFileMessage.MAX_SIZE || (size += fileSize) >= UploadFileMessage.MAX_SIZE )
|
||||
{
|
||||
alert( UploadResult.FAILED_TITLE, UploadResult.TOO_MUCH_MSG );
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect( (int) fileSize );
|
||||
sbc.read( buffer );
|
||||
buffer.flip();
|
||||
|
||||
toUpload.add( new FileUpload( file.getFileName().toString(), buffer ) );
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
ComputerCraft.log.error( "Failed uploading files", e );
|
||||
alert( UploadResult.FAILED_TITLE, new TranslationTextComponent( "computercraft.gui.upload.failed.generic", e.getMessage() ) );
|
||||
}
|
||||
}
|
||||
|
||||
if( toUpload.size() > 0 )
|
||||
{
|
||||
NetworkHandler.sendToServer( new UploadFileMessage( computer.getInstanceID(), toUpload ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadResult( UploadResult result, ITextComponent message )
|
||||
{
|
||||
switch( result )
|
||||
{
|
||||
case SUCCESS:
|
||||
alert( UploadResult.SUCCESS_TITLE, message );
|
||||
break;
|
||||
case ERROR:
|
||||
alert( UploadResult.FAILED_TITLE, message );
|
||||
break;
|
||||
case CONFIRM_OVERWRITE:
|
||||
OptionScreen.show(
|
||||
minecraft, UploadResult.UPLOAD_OVERWRITE, message,
|
||||
Arrays.asList(
|
||||
OptionScreen.newButton( CANCEL, b -> cancelUpload() ),
|
||||
OptionScreen.newButton( OVERWRITE, b -> continueUpload() )
|
||||
),
|
||||
this::cancelUpload
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void continueUpload()
|
||||
{
|
||||
if( minecraft.screen instanceof OptionScreen ) ((OptionScreen) minecraft.screen).disable();
|
||||
NetworkHandler.sendToServer( new ContinueUploadMessage( computer.getInstanceID(), true ) );
|
||||
}
|
||||
|
||||
private void cancelUpload()
|
||||
{
|
||||
minecraft.setScreen( this );
|
||||
NetworkHandler.sendToServer( new ContinueUploadMessage( computer.getInstanceID(), false ) );
|
||||
}
|
||||
|
||||
private void alert( ITextComponent title, ITextComponent message )
|
||||
{
|
||||
OptionScreen.show( minecraft, title, message,
|
||||
Collections.singletonList( OptionScreen.newButton( OK, b -> minecraft.setScreen( this ) ) ),
|
||||
() -> minecraft.setScreen( this )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@ import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
|
||||
@@ -17,6 +18,8 @@ import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
|
||||
|
||||
public final class GuiComputer<T extends ContainerComputerBase> extends ComputerScreenBase<T>
|
||||
@@ -69,12 +72,12 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Computer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
public void renderBg( @Nonnull MatrixStack stack, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw a border around the terminal
|
||||
RenderSystem.color4f( 1, 1, 1, 1 );
|
||||
minecraft.getTextureManager().bind( ComputerBorderRenderer.getTexture( family ) );
|
||||
ComputerBorderRenderer.render( terminal.x, terminal.y, getBlitOffset(), terminal.getWidth(), terminal.getHeight() );
|
||||
ComputerSidebar.renderBackground( leftPos, topPos + sidebarYOffset );
|
||||
ComputerSidebar.renderBackground( stack, leftPos, topPos + sidebarYOffset );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
@@ -12,6 +13,8 @@ import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
|
||||
@@ -22,26 +25,18 @@ public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels( int mouseX, int mouseY )
|
||||
{
|
||||
String title = this.title.getColoredString();
|
||||
font.draw( title, (imageWidth - font.width( title )) / 2.0f, 6, 0x404040 );
|
||||
font.draw( title, 8, imageHeight - 96 + 2, 0x404040 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void renderBg( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
minecraft.getTextureManager().bind( BACKGROUND );
|
||||
blit( leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
blit( transform, leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
renderBackground( transform );
|
||||
super.render( transform, mouseX, mouseY, partialTicks );
|
||||
renderTooltip( transform, mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiPrinter extends ContainerScreen<ContainerPrinter>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
||||
@@ -23,28 +25,20 @@ public class GuiPrinter extends ContainerScreen<ContainerPrinter>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels( int mouseX, int mouseY )
|
||||
{
|
||||
String title = getTitle().getColoredString();
|
||||
font.draw( title, (imageWidth - font.width( title )) / 2.0f, 6, 0x404040 );
|
||||
font.draw( I18n.get( "container.inventory" ), 8, imageHeight - 96 + 2, 0x404040 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void renderBg( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
minecraft.getTextureManager().bind( BACKGROUND );
|
||||
blit( leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
blit( transform, leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
|
||||
if( getMenu().isPrinting() ) blit( leftPos + 34, topPos + 21, 176, 0, 25, 45 );
|
||||
if( getMenu().isPrinting() ) blit( transform, leftPos + 34, topPos + 21, 176, 0, 25, 45 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
renderTooltip( stack, mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
@@ -12,18 +13,17 @@ import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||
|
||||
public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||
{
|
||||
private static final Matrix4f IDENTITY = TransformationMatrix.identity().getMatrix();
|
||||
|
||||
private final boolean book;
|
||||
private final int pages;
|
||||
private final TextBuffer[] text;
|
||||
@@ -91,27 +91,33 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void renderBg( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw the printout
|
||||
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
drawBorder( IDENTITY, renderer, leftPos, topPos, getBlitOffset(), page, pages, book );
|
||||
drawText( IDENTITY, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, text, colours );
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
drawBorder( matrix, renderer, leftPos, topPos, getBlitOffset(), page, pages, book );
|
||||
drawText( matrix, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, text, colours );
|
||||
renderer.endBatch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
// We must take the background further back in order to not overlap with our printed pages.
|
||||
setBlitOffset( getBlitOffset() - 1 );
|
||||
renderBackground();
|
||||
renderBackground( stack );
|
||||
setBlitOffset( getBlitOffset() + 1 );
|
||||
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.ComputerSidebar;
|
||||
@@ -16,6 +17,8 @@ import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static dan200.computercraft.shared.turtle.inventory.ContainerTurtle.*;
|
||||
|
||||
public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
|
||||
@@ -47,13 +50,14 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void renderBg( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
boolean advanced = family == ComputerFamily.ADVANCED;
|
||||
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
minecraft.getTextureManager().bind( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
blit( leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT );
|
||||
blit( transform, leftPos + ComputerSidebar.WIDTH, topPos, 0, 0, TEX_WIDTH, TEX_HEIGHT );
|
||||
|
||||
minecraft.getTextureManager().bind( advanced ? ComputerBorderRenderer.BACKGROUND_ADVANCED : ComputerBorderRenderer.BACKGROUND_NORMAL );
|
||||
ComputerSidebar.renderBackground( transform, leftPos, topPos + sidebarYOffset );
|
||||
|
||||
int slot = getMenu().getSelectedSlot();
|
||||
if( slot >= 0 )
|
||||
@@ -61,13 +65,10 @@ public class GuiTurtle extends ComputerScreenBase<ContainerTurtle>
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
int slotX = slot % 4;
|
||||
int slotY = slot / 4;
|
||||
blit(
|
||||
blit( transform,
|
||||
leftPos + TURTLE_START_X - 2 + slotX * 18, topPos + PLAYER_START_Y - 2 + slotY * 18,
|
||||
0, 217, 24, 24
|
||||
);
|
||||
}
|
||||
|
||||
minecraft.getTextureManager().bind( advanced ? ComputerBorderRenderer.BACKGROUND_ADVANCED : ComputerBorderRenderer.BACKGROUND_NORMAL );
|
||||
ComputerSidebar.renderBackground( leftPos, topPos + sidebarYOffset );
|
||||
}
|
||||
}
|
||||
|
||||
127
src/main/java/dan200/computercraft/client/gui/OptionScreen.java
Normal file
127
src/main/java/dan200/computercraft/client/gui/OptionScreen.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.IBidiRenderer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
public final class OptionScreen extends Screen
|
||||
{
|
||||
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;
|
||||
|
||||
private static final int PADDING = 16;
|
||||
private static final int FONT_HEIGHT = 9;
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int innerWidth;
|
||||
private int innerHeight;
|
||||
|
||||
private IBidiRenderer messageRenderer;
|
||||
private final ITextComponent message;
|
||||
private final List<Widget> buttons;
|
||||
private final Runnable exit;
|
||||
|
||||
private final Screen originalScreen;
|
||||
|
||||
private OptionScreen( ITextComponent title, ITextComponent message, List<Widget> buttons, Runnable exit, Screen originalScreen )
|
||||
{
|
||||
super( title );
|
||||
this.message = message;
|
||||
this.buttons = buttons;
|
||||
this.exit = exit;
|
||||
this.originalScreen = originalScreen;
|
||||
}
|
||||
|
||||
public static void show( Minecraft minecraft, ITextComponent title, ITextComponent message, List<Widget> buttons, Runnable exit )
|
||||
{
|
||||
minecraft.setScreen( new OptionScreen( title, message, buttons, exit, unwrap( minecraft.screen ) ) );
|
||||
}
|
||||
|
||||
public static Screen unwrap( Screen screen )
|
||||
{
|
||||
return screen instanceof OptionScreen ? ((OptionScreen) screen).getOriginalScreen() : screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
int buttonWidth = BUTTON_WIDTH * buttons.size() + PADDING * (buttons.size() - 1);
|
||||
int innerWidth = this.innerWidth = Math.max( 256, buttonWidth + PADDING * 2 );
|
||||
|
||||
messageRenderer = IBidiRenderer.create( font, message, innerWidth - 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( Widget button : buttons )
|
||||
{
|
||||
button.x = x;
|
||||
button.y = y + textHeight;
|
||||
addButton( button );
|
||||
|
||||
x += BUTTON_WIDTH + PADDING;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground( transform );
|
||||
|
||||
// Render the actual texture.
|
||||
minecraft.textureManager.bind( BACKGROUND );
|
||||
blit( transform, x, y, 0, 0, innerWidth, PADDING );
|
||||
blit( transform,
|
||||
x, y + PADDING, 0, PADDING, innerWidth, innerHeight - PADDING * 2,
|
||||
innerWidth, PADDING
|
||||
);
|
||||
blit( transform, x, y + innerHeight - PADDING, 0, 256 - PADDING, innerWidth, PADDING );
|
||||
|
||||
messageRenderer.renderLeftAlignedNoShadow( transform, x + PADDING, y + PADDING, FONT_HEIGHT, 0x404040 );
|
||||
super.render( transform, mouseX, mouseY, partialTicks );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose()
|
||||
{
|
||||
exit.run();
|
||||
}
|
||||
|
||||
public static Widget newButton( ITextComponent component, Button.IPressable clicked )
|
||||
{
|
||||
return new Button( 0, 0, BUTTON_WIDTH, BUTTON_HEIGHT, component, clicked );
|
||||
}
|
||||
|
||||
public void disable()
|
||||
{
|
||||
for( Widget widget : buttons ) widget.active = false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Screen getOriginalScreen()
|
||||
{
|
||||
return originalScreen;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.render.ComputerBorderRenderer;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
@@ -52,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(
|
||||
I18n.get( "gui.computercraft.tooltip.turn_off" ),
|
||||
TextFormatting.GRAY + I18n.get( "gui.computercraft.tooltip.turn_off.key" )
|
||||
new TranslationTextComponent( "gui.computercraft.tooltip.turn_off" ),
|
||||
new TranslationTextComponent( "gui.computercraft.tooltip.turn_off.key" ).withStyle( TextFormatting.GRAY )
|
||||
) : Arrays.asList(
|
||||
I18n.get( "gui.computercraft.tooltip.turn_on" ),
|
||||
TextFormatting.GRAY + I18n.get( "gui.computercraft.tooltip.turn_off.key" )
|
||||
new TranslationTextComponent( "gui.computercraft.tooltip.turn_on" ),
|
||||
new TranslationTextComponent( "gui.computercraft.tooltip.turn_off.key" ).withStyle( TextFormatting.GRAY )
|
||||
)
|
||||
) );
|
||||
|
||||
@@ -66,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(
|
||||
I18n.get( "gui.computercraft.tooltip.terminate" ),
|
||||
TextFormatting.GRAY + I18n.get( "gui.computercraft.tooltip.terminate.key" )
|
||||
new TranslationTextComponent( "gui.computercraft.tooltip.terminate" ),
|
||||
new TranslationTextComponent( "gui.computercraft.tooltip.terminate.key" ).withStyle( TextFormatting.GRAY )
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
public static void renderBackground( int x, int y )
|
||||
public static void renderBackground( MatrixStack transform, int x, int y )
|
||||
{
|
||||
Screen.blit(
|
||||
Screen.blit( transform,
|
||||
x, y, 0, 102, WIDTH, FULL_BORDER,
|
||||
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
|
||||
);
|
||||
|
||||
Screen.blit(
|
||||
Screen.blit( transform,
|
||||
x, y + FULL_BORDER, WIDTH, HEIGHT - FULL_BORDER * 2,
|
||||
0, 107, WIDTH, 4,
|
||||
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
|
||||
);
|
||||
|
||||
Screen.blit(
|
||||
Screen.blit( transform,
|
||||
x, y + HEIGHT - FULL_BORDER, 0, 111, WIDTH, FULL_BORDER,
|
||||
ComputerBorderRenderer.TEX_SIZE, ComputerBorderRenderer.TEX_SIZE
|
||||
);
|
||||
|
||||
@@ -5,11 +5,14 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.button.Button;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.common.util.NonNullSupplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -29,12 +32,12 @@ public class DynamicImageButton extends Button
|
||||
private final int yDiffTex;
|
||||
private final int textureWidth;
|
||||
private final int textureHeight;
|
||||
private final NonNullSupplier<List<String>> tooltip;
|
||||
private final NonNullSupplier<List<ITextComponent>> tooltip;
|
||||
|
||||
public DynamicImageButton(
|
||||
Screen screen, int x, int y, int width, int height, int xTexStart, int yTexStart, int yDiffTex,
|
||||
ResourceLocation texture, int textureWidth, int textureHeight,
|
||||
IPressable onPress, List<String> tooltip
|
||||
IPressable onPress, List<ITextComponent> tooltip
|
||||
)
|
||||
{
|
||||
this(
|
||||
@@ -48,10 +51,10 @@ public class DynamicImageButton extends Button
|
||||
public DynamicImageButton(
|
||||
Screen screen, int x, int y, int width, int height, IntSupplier xTexStart, int yTexStart, int yDiffTex,
|
||||
ResourceLocation texture, int textureWidth, int textureHeight,
|
||||
IPressable onPress, NonNullSupplier<List<String>> tooltip
|
||||
IPressable onPress, NonNullSupplier<List<ITextComponent>> tooltip
|
||||
)
|
||||
{
|
||||
super( x, y, width, height, "", onPress );
|
||||
super( x, y, width, height, StringTextComponent.EMPTY, onPress );
|
||||
this.screen = screen;
|
||||
this.textureWidth = textureWidth;
|
||||
this.textureHeight = textureHeight;
|
||||
@@ -63,7 +66,7 @@ public class DynamicImageButton extends Button
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderButton( int mouseX, int mouseY, float partialTicks )
|
||||
public void renderButton( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
minecraft.getTextureManager().bind( texture );
|
||||
@@ -72,22 +75,27 @@ public class DynamicImageButton extends Button
|
||||
int yTex = yTexStart;
|
||||
if( isHovered() ) yTex += yDiffTex;
|
||||
|
||||
blit( 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 );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getMessage()
|
||||
public ITextComponent getMessage()
|
||||
{
|
||||
List<String> tooltip = this.tooltip.get();
|
||||
return tooltip.isEmpty() ? "" : tooltip.get( 0 );
|
||||
List<ITextComponent> tooltip = this.tooltip.get();
|
||||
return tooltip.isEmpty() ? StringTextComponent.EMPTY : tooltip.get( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderToolTip( int mouseX, int mouseY )
|
||||
public void renderToolTip( @Nonnull MatrixStack stack, int mouseX, int mouseY )
|
||||
{
|
||||
List<String> tooltip = this.tooltip.get();
|
||||
if( !tooltip.isEmpty() ) screen.renderTooltip( tooltip, mouseX, mouseY );
|
||||
List<ITextComponent> tooltip = this.tooltip.get();
|
||||
if( !tooltip.isEmpty() )
|
||||
{
|
||||
screen.renderWrappedToolTip( stack, tooltip, mouseX, mouseY, screen.getMinecraft().font );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.widget.Widget;
|
||||
import net.minecraft.util.SharedConstants;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -44,7 +47,7 @@ public class WidgetTerminal extends Widget
|
||||
|
||||
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, "" );
|
||||
super( x, y, termWidth * FONT_WIDTH + MARGIN * 2, termHeight * FONT_HEIGHT + MARGIN * 2, StringTextComponent.EMPTY );
|
||||
|
||||
this.computer = computer;
|
||||
|
||||
@@ -306,17 +309,17 @@ public class WidgetTerminal extends Widget
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
// Draw the screen contents
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
Terminal terminal = computer.getTerminal();
|
||||
if( terminal != null )
|
||||
{
|
||||
FixedWidthFontRenderer.drawTerminal( innerX, innerY, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN );
|
||||
FixedWidthFontRenderer.drawTerminal( matrix, innerX, innerY, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN );
|
||||
}
|
||||
else
|
||||
{
|
||||
FixedWidthFontRenderer.drawEmptyTerminal( x, y, width, height );
|
||||
FixedWidthFontRenderer.drawEmptyTerminal( matrix, x, y, width, height );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@ import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.DrawHighlightEvent;
|
||||
@@ -63,7 +63,7 @@ public final class CableHighlightRenderer
|
||||
? CableShapes.getModemShape( state )
|
||||
: CableShapes.getCableShape( state );
|
||||
|
||||
Vec3d cameraPos = info.getPosition();
|
||||
Vector3d cameraPos = info.getPosition();
|
||||
double xOffset = pos.getX() - cameraPos.x();
|
||||
double yOffset = pos.getY() - cameraPos.y();
|
||||
double zOffset = pos.getZ() - cameraPos.z();
|
||||
|
||||
@@ -10,10 +10,10 @@ import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -10,12 +10,12 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.renderer.FirstPersonRenderer;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.HandSide;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
|
||||
public abstract class ItemMapLikeRenderer
|
||||
{
|
||||
|
||||
@@ -15,9 +15,13 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
@@ -9,9 +9,9 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderItemInFrameEvent;
|
||||
|
||||
@@ -9,12 +9,12 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.DrawHighlightEvent;
|
||||
@@ -61,7 +61,7 @@ public final class MonitorHighlightRenderer
|
||||
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
||||
|
||||
MatrixStack transformStack = event.getMatrix();
|
||||
Vec3d cameraPos = event.getInfo().getPosition();
|
||||
Vector3d cameraPos = event.getInfo().getPosition();
|
||||
transformStack.pushPose();
|
||||
transformStack.translate( pos.getX() - cameraPos.x(), pos.getY() - cameraPos.y(), pos.getZ() - cameraPos.z() );
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
|
||||
@@ -10,11 +10,11 @@ import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
@@ -24,6 +24,9 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexBuffer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
@@ -141,6 +144,10 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
(float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2)
|
||||
);
|
||||
|
||||
// Force a flush of the blocker. WorldRenderer.updateCameraAndRender will "finish" all the built-in
|
||||
// buffers before calling renderer.finish, which means the blocker isn't actually rendered at that point!
|
||||
renderer.getBuffer( RenderType.solid() );
|
||||
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ModelManager;
|
||||
@@ -31,7 +29,9 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -99,7 +99,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
||||
transform.pushPose();
|
||||
|
||||
// Setup the transform.
|
||||
Vec3d offset = turtle.getRenderOffset( partialTicks );
|
||||
Vector3d offset = turtle.getRenderOffset( partialTicks );
|
||||
float yaw = turtle.getRenderYaw( partialTicks );
|
||||
transform.translate( offset.x, offset.y, offset.z );
|
||||
|
||||
|
||||
@@ -57,16 +57,16 @@ public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.T
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextures( IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors )
|
||||
public Collection<RenderMaterial> getTextures( IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors )
|
||||
{
|
||||
Set<Material> materials = new HashSet<>();
|
||||
Set<RenderMaterial> materials = new HashSet<>();
|
||||
materials.addAll( modelGetter.apply( family ).getMaterials( modelGetter, missingTextureErrors ) );
|
||||
materials.addAll( modelGetter.apply( COLOUR_TURTLE_MODEL ).getMaterials( modelGetter, missingTextureErrors ) );
|
||||
return materials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake( IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform transform, ItemOverrideList overrides, ResourceLocation modelLocation )
|
||||
public IBakedModel bake( IModelConfiguration owner, ModelBakery bakery, Function<RenderMaterial, TextureAtlasSprite> spriteGetter, IModelTransform transform, ItemOverrideList overrides, ResourceLocation modelLocation )
|
||||
{
|
||||
return new TurtleSmartItemModel(
|
||||
bakery.getBakedModel( family, transform, spriteGetter ),
|
||||
|
||||
@@ -7,12 +7,12 @@ package dan200.computercraft.client.render;
|
||||
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
|
||||
@@ -15,14 +15,14 @@ import dan200.computercraft.shared.util.Holiday;
|
||||
import dan200.computercraft.shared.util.HolidayUtil;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -109,7 +109,7 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBakedModel resolve( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable LivingEntity entity )
|
||||
public IBakedModel resolve( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity )
|
||||
{
|
||||
ItemTurtle turtle = (ItemTurtle) stack.getItem();
|
||||
int colour = turtle.getColour( stack );
|
||||
|
||||
@@ -62,7 +62,6 @@ public interface IAPIEnvironment
|
||||
@Nullable
|
||||
IPeripheral getPeripheral( ComputerSide side );
|
||||
|
||||
@Nullable
|
||||
String getLabel();
|
||||
|
||||
void setLabel( @Nullable String label );
|
||||
|
||||
@@ -20,8 +20,6 @@ import io.netty.handler.codec.http.websocketx.WebSocketHandshakeException;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.timeout.ReadTimeoutException;
|
||||
import io.netty.handler.traffic.AbstractTrafficShapingHandler;
|
||||
import io.netty.handler.traffic.GlobalTrafficShapingHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.net.ssl.SSLException;
|
||||
@@ -30,7 +28,9 @@ import javax.net.ssl.TrustManagerFactory;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.security.KeyStore;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -38,8 +38,10 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public final class NetworkUtils
|
||||
{
|
||||
public static final ScheduledThreadPoolExecutor EXECUTOR = new ScheduledThreadPoolExecutor(
|
||||
4,
|
||||
public static final ExecutorService EXECUTOR = new ThreadPoolExecutor(
|
||||
4, Integer.MAX_VALUE,
|
||||
60L, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>(),
|
||||
ThreadUtils.builder( "Network" )
|
||||
.setPriority( Thread.MIN_PRIORITY + (Thread.NORM_PRIORITY - Thread.MIN_PRIORITY) / 2 )
|
||||
.build()
|
||||
@@ -50,15 +52,6 @@ public final class NetworkUtils
|
||||
.build()
|
||||
);
|
||||
|
||||
public static final AbstractTrafficShapingHandler SHAPING_HANDLER = new GlobalTrafficShapingHandler(
|
||||
EXECUTOR, ComputerCraft.httpUploadBandwidth, ComputerCraft.httpDownloadBandwidth
|
||||
);
|
||||
|
||||
static
|
||||
{
|
||||
EXECUTOR.setKeepAliveTime( 60, TimeUnit.SECONDS );
|
||||
}
|
||||
|
||||
private NetworkUtils()
|
||||
{
|
||||
}
|
||||
@@ -114,16 +107,6 @@ public final class NetworkUtils
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadConfig()
|
||||
{
|
||||
SHAPING_HANDLER.configure( ComputerCraft.httpUploadBandwidth, ComputerCraft.httpDownloadBandwidth );
|
||||
}
|
||||
|
||||
public static void reset()
|
||||
{
|
||||
SHAPING_HANDLER.trafficCounter().resetCumulativeTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link InetSocketAddress} from a {@link java.net.URI}.
|
||||
*
|
||||
|
||||
@@ -167,7 +167,6 @@ public class HttpRequest extends Resource<HttpRequest>
|
||||
}
|
||||
|
||||
ChannelPipeline p = ch.pipeline();
|
||||
p.addLast( NetworkUtils.SHAPING_HANDLER );
|
||||
if( sslContext != null )
|
||||
{
|
||||
p.addLast( sslContext.newHandler( ch.alloc(), uri.getHost(), socketAddress.getPort() ) );
|
||||
|
||||
@@ -28,6 +28,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
||||
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
@@ -145,7 +146,6 @@ public class Websocket extends Resource<Websocket>
|
||||
protected void initChannel( SocketChannel ch )
|
||||
{
|
||||
ChannelPipeline p = ch.pipeline();
|
||||
p.addLast( NetworkUtils.SHAPING_HANDLER );
|
||||
if( sslContext != null )
|
||||
{
|
||||
p.addLast( sslContext.newHandler( ch.alloc(), uri.getHost(), socketAddress.getPort() ) );
|
||||
@@ -160,7 +160,7 @@ public class Websocket extends Resource<Websocket>
|
||||
p.addLast(
|
||||
new HttpClientCodec(),
|
||||
new HttpObjectAggregator( 8192 ),
|
||||
WebsocketCompressionHandler.INSTANCE,
|
||||
WebSocketClientCompressionHandler.INSTANCE,
|
||||
new WebsocketHandler( Websocket.this, handshaker, options )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.core.apis.http.websocket;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.handler.codec.compression.ZlibCodecFactory;
|
||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler;
|
||||
import io.netty.handler.codec.http.websocketx.extensions.compression.DeflateFrameClientExtensionHandshaker;
|
||||
import io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateClientExtensionHandshaker;
|
||||
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler;
|
||||
|
||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateServerExtensionHandshaker.MAX_WINDOW_SIZE;
|
||||
|
||||
/**
|
||||
* An alternative to {@link WebSocketClientCompressionHandler} which supports the {@literal client_no_context_takeover}
|
||||
* extension. Makes CC <em>slightly</em> more flexible.
|
||||
*/
|
||||
@ChannelHandler.Sharable
|
||||
final class WebsocketCompressionHandler extends WebSocketClientExtensionHandler
|
||||
{
|
||||
public static final WebsocketCompressionHandler INSTANCE = new WebsocketCompressionHandler();
|
||||
|
||||
private WebsocketCompressionHandler()
|
||||
{
|
||||
super(
|
||||
new PerMessageDeflateClientExtensionHandshaker(
|
||||
6, ZlibCodecFactory.isSupportingWindowSizeAndMemLevel(), MAX_WINDOW_SIZE,
|
||||
true, false
|
||||
),
|
||||
new DeflateFrameClientExtensionHandshaker( false ),
|
||||
new DeflateFrameClientExtensionHandshaker( true )
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.core.tracking;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.core.computer.Computer;
|
||||
import net.minecraft.util.text.LanguageMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.management.*;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
public final class ComputerMBean implements DynamicMBean, Tracker
|
||||
{
|
||||
private static final Set<TrackingField> SKIP = new HashSet<>( Arrays.asList(
|
||||
TrackingField.TASKS, TrackingField.TOTAL_TIME, TrackingField.AVERAGE_TIME, TrackingField.MAX_TIME,
|
||||
TrackingField.SERVER_COUNT, TrackingField.SERVER_TIME
|
||||
) );
|
||||
|
||||
private static ComputerMBean instance;
|
||||
|
||||
private final Map<String, LongSupplier> attributes = new HashMap<>();
|
||||
private final Map<TrackingField, Counter> values = new HashMap<>();
|
||||
private final MBeanInfo info;
|
||||
|
||||
private ComputerMBean()
|
||||
{
|
||||
List<MBeanAttributeInfo> attributes = new ArrayList<>();
|
||||
for( Map.Entry<String, TrackingField> field : TrackingField.fields().entrySet() )
|
||||
{
|
||||
if( SKIP.contains( field.getValue() ) ) continue;
|
||||
|
||||
String name = CaseFormat.LOWER_UNDERSCORE.to( CaseFormat.LOWER_CAMEL, field.getKey() );
|
||||
add( name, field.getValue(), attributes, null );
|
||||
}
|
||||
|
||||
add( "task", TrackingField.TOTAL_TIME, attributes, TrackingField.TASKS );
|
||||
add( "serverTask", TrackingField.SERVER_TIME, attributes, TrackingField.SERVER_COUNT );
|
||||
|
||||
this.info = new MBeanInfo(
|
||||
ComputerMBean.class.getSimpleName(),
|
||||
"metrics about all computers on the server",
|
||||
attributes.toArray( new MBeanAttributeInfo[0] ), null, null, null
|
||||
);
|
||||
}
|
||||
|
||||
public static void register()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementFactory.getPlatformMBeanServer().registerMBean( instance = new ComputerMBean(), new ObjectName( "dan200.computercraft:type=Computers" ) );
|
||||
}
|
||||
catch( InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException e )
|
||||
{
|
||||
ComputerCraft.log.warn( "Failed to register JMX bean", e );
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerTracker()
|
||||
{
|
||||
if( instance != null ) Tracking.add( instance );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute( String attribute ) throws AttributeNotFoundException, MBeanException, ReflectionException
|
||||
{
|
||||
LongSupplier value = attributes.get( attribute );
|
||||
if( value == null ) throw new AttributeNotFoundException();
|
||||
return value.getAsLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute( Attribute attribute ) throws InvalidAttributeValueException
|
||||
{
|
||||
throw new InvalidAttributeValueException( "Cannot set attribute" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeList getAttributes( String[] attributes )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeList setAttributes( AttributeList attributes )
|
||||
{
|
||||
return new AttributeList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke( String actionName, Object[] params, String[] signature ) throws MBeanException, ReflectionException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public MBeanInfo getMBeanInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTaskTiming( Computer computer, long time )
|
||||
{
|
||||
addValue( computer, TrackingField.TOTAL_TIME, time );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addServerTiming( Computer computer, long time )
|
||||
{
|
||||
addValue( computer, TrackingField.SERVER_TIME, time );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addValue( Computer computer, TrackingField field, long change )
|
||||
{
|
||||
Counter counter = values.get( field );
|
||||
counter.value.addAndGet( change );
|
||||
counter.count.incrementAndGet();
|
||||
}
|
||||
|
||||
private MBeanAttributeInfo addAttribute( String name, String description, LongSupplier value )
|
||||
{
|
||||
attributes.put( name, value );
|
||||
return new MBeanAttributeInfo( name, "long", description, true, false, false );
|
||||
}
|
||||
|
||||
private void add( String name, TrackingField field, List<MBeanAttributeInfo> attributes, TrackingField count )
|
||||
{
|
||||
Counter counter = new Counter();
|
||||
values.put( field, counter );
|
||||
|
||||
String prettyName = LanguageMap.getInstance().getOrDefault( field.translationKey() );
|
||||
attributes.add( addAttribute( name, prettyName, counter.value::longValue ) );
|
||||
if( count != null )
|
||||
{
|
||||
String countName = LanguageMap.getInstance().getOrDefault( count.translationKey() );
|
||||
attributes.add( addAttribute( name + "Count", countName, counter.count::longValue ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static class Counter
|
||||
{
|
||||
AtomicLong value = new AtomicLong();
|
||||
AtomicLong count = new AtomicLong();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.generators.*;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Generators
|
||||
DataGenerator generator = event.getGenerator();
|
||||
generator.addProvider( new Recipes( generator ) );
|
||||
generator.addProvider( new LootTables( generator ) );
|
||||
generator.addProvider( new Tags( generator ) );
|
||||
generator.addProvider( new Tags( generator, event.getExistingFileHelper() ) );
|
||||
generator.addProvider( new BlockModelProvider( generator, event.getExistingFileHelper() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ import dan200.computercraft.ComputerCraft;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.loot.LootParameterSets;
|
||||
import net.minecraft.loot.LootTable;
|
||||
import net.minecraft.loot.LootTableManager;
|
||||
import net.minecraft.loot.ValidationTracker;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.LootParameterSets;
|
||||
import net.minecraft.world.storage.loot.LootTable;
|
||||
import net.minecraft.world.storage.loot.LootTableManager;
|
||||
import net.minecraft.world.storage.loot.ValidationTracker;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -13,10 +13,10 @@ import dan200.computercraft.shared.data.HasComputerIdLootCondition;
|
||||
import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.loot.*;
|
||||
import net.minecraft.loot.conditions.Alternative;
|
||||
import net.minecraft.loot.conditions.SurvivesExplosion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.*;
|
||||
import net.minecraft.world.storage.loot.conditions.Alternative;
|
||||
import net.minecraft.world.storage.loot.conditions.SurvivesExplosion;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -77,9 +77,9 @@ public class LootTables extends LootTableProvider
|
||||
.setRolls( ConstantRange.exactly( 1 ) )
|
||||
.add( DynamicLootEntry.dynamicEntry( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) )
|
||||
.when( Alternative.alternative(
|
||||
BlockNamedEntityLootCondition.builder(),
|
||||
HasComputerIdLootCondition.builder(),
|
||||
PlayerCreativeLootCondition.builder().invert()
|
||||
BlockNamedEntityLootCondition.BUILDER,
|
||||
HasComputerIdLootCondition.BUILDER,
|
||||
PlayerCreativeLootCondition.BUILDER.invert()
|
||||
) )
|
||||
).build() );
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import net.minecraft.advancements.criterion.ItemPredicate;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.data.*;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.util.IItemProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.Tags;
|
||||
@@ -62,7 +62,7 @@ public class Recipes extends RecipeProvider
|
||||
.requires( Items.PAPER )
|
||||
.requires( DyeItem.byColor( ofColour( colour ) ) )
|
||||
.group( "computercraft:disk" )
|
||||
.unlocks( "has_drive", inventoryChange( Registry.ModBlocks.DISK_DRIVE.get() ) )
|
||||
.unlockedBy( "has_drive", inventoryChange( Registry.ModBlocks.DISK_DRIVE.get() ) )
|
||||
.save( RecipeWrapper.wrap(
|
||||
ImpostorShapelessRecipe.SERIALIZER, add,
|
||||
x -> x.putInt( IColouredItem.NBT_COLOUR, colour.getHex() )
|
||||
@@ -92,7 +92,7 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "#T" )
|
||||
.define( '#', base.getItem() )
|
||||
.define( 'T', upgrade.getCraftingItem().getItem() )
|
||||
.unlocks( "has_items",
|
||||
.unlockedBy( "has_items",
|
||||
inventoryChange( base.getItem(), upgrade.getCraftingItem().getItem() ) )
|
||||
.save(
|
||||
RecipeWrapper.wrap( ImpostorRecipe.SERIALIZER, add, result.getTag() ),
|
||||
@@ -127,7 +127,7 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "P" )
|
||||
.define( '#', base.getItem() )
|
||||
.define( 'P', upgrade.getCraftingItem().getItem() )
|
||||
.unlocks( "has_items",
|
||||
.unlockedBy( "has_items",
|
||||
inventoryChange( base.getItem(), upgrade.getCraftingItem().getItem() ) )
|
||||
.save(
|
||||
RecipeWrapper.wrap( ImpostorRecipe.SERIALIZER, add, result.getTag() ),
|
||||
@@ -148,8 +148,8 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( " # " )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_modem", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_modem", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -160,7 +160,7 @@ public class Recipes extends RecipeProvider
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_redstone", inventoryChange( Tags.Items.DUSTS_REDSTONE ) )
|
||||
.unlockedBy( "has_redstone", inventoryChange( Tags.Items.DUSTS_REDSTONE ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -171,7 +171,7 @@ public class Recipes extends RecipeProvider
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_components", inventoryChange( Items.REDSTONE, Items.GOLD_INGOT ) )
|
||||
.unlockedBy( "has_components", inventoryChange( Items.REDSTONE, Items.GOLD_INGOT ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -182,7 +182,7 @@ public class Recipes extends RecipeProvider
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'R', Blocks.COMMAND_BLOCK )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_components", inventoryChange( Blocks.COMMAND_BLOCK ) )
|
||||
.unlockedBy( "has_components", inventoryChange( Blocks.COMMAND_BLOCK ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -192,7 +192,7 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "#R#" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -202,7 +202,7 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -212,7 +212,7 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -223,8 +223,8 @@ public class Recipes extends RecipeProvider
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'A', Items.GOLDEN_APPLE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -235,8 +235,8 @@ public class Recipes extends RecipeProvider
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'A', Items.GOLDEN_APPLE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -247,7 +247,7 @@ public class Recipes extends RecipeProvider
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.define( 'D', Tags.Items.DYES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -258,7 +258,7 @@ public class Recipes extends RecipeProvider
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'N', Blocks.NOTE_BLOCK )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -268,19 +268,19 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_cable", inventoryChange( Registry.ModItems.CABLE.get() ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_cable", inventoryChange( Registry.ModItems.CABLE.get() ) )
|
||||
.save( add );
|
||||
|
||||
ShapelessRecipeBuilder
|
||||
.shapeless( Registry.ModBlocks.WIRED_MODEM_FULL.get() )
|
||||
.requires( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.unlocks( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.unlockedBy( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.save( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_from" ) );
|
||||
ShapelessRecipeBuilder
|
||||
.shapeless( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.requires( Registry.ModBlocks.WIRED_MODEM_FULL.get() )
|
||||
.unlocks( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.unlockedBy( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.save( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_to" ) );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -290,7 +290,7 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'E', Tags.Items.ENDER_PEARLS )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
@@ -300,8 +300,8 @@ public class Recipes extends RecipeProvider
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'E', Items.ENDER_EYE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_wireless", inventoryChange( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) )
|
||||
.unlockedBy( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlockedBy( "has_wireless", inventoryChange( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) )
|
||||
.save( add );
|
||||
}
|
||||
|
||||
@@ -310,13 +310,13 @@ public class Recipes extends RecipeProvider
|
||||
return DyeColor.byId( 15 - colour.ordinal() );
|
||||
}
|
||||
|
||||
private static InventoryChangeTrigger.Instance inventoryChange( Tag<Item> stack )
|
||||
private static InventoryChangeTrigger.Instance inventoryChange( ITag<Item> stack )
|
||||
{
|
||||
return InventoryChangeTrigger.Instance.hasItem( ItemPredicate.Builder.item().of( stack ).build() );
|
||||
return InventoryChangeTrigger.Instance.hasItems( ItemPredicate.Builder.item().of( stack ).build() );
|
||||
}
|
||||
|
||||
private static InventoryChangeTrigger.Instance inventoryChange( IItemProvider... stack )
|
||||
{
|
||||
return InventoryChangeTrigger.Instance.hasItem( stack );
|
||||
return InventoryChangeTrigger.Instance.hasItems( stack );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,46 +7,55 @@ package dan200.computercraft.data;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import net.minecraft.data.BlockTagsProvider;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.ItemTagsProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import static dan200.computercraft.data.Tags.CCTags.*;
|
||||
|
||||
public class Tags extends ItemTagsProvider
|
||||
{
|
||||
private static final ITag.INamedTag<Item> PIGLIN_LOVED = ItemTags.PIGLIN_LOVED;
|
||||
|
||||
public static class CCTags
|
||||
{
|
||||
public static final Tag<Item> COMPUTER = item( "computer" );
|
||||
public static final Tag<Item> TURTLE = item( "turtle" );
|
||||
public static final Tag<Item> WIRED_MODEM = item( "wired_modem" );
|
||||
public static final Tag<Item> MONITOR = item( "monitor" );
|
||||
public static final ITag.INamedTag<Item> COMPUTER = item( "computer" );
|
||||
public static final ITag.INamedTag<Item> TURTLE = item( "turtle" );
|
||||
public static final ITag.INamedTag<Item> WIRED_MODEM = item( "wired_modem" );
|
||||
public static final ITag.INamedTag<Item> MONITOR = item( "monitor" );
|
||||
}
|
||||
|
||||
public Tags( DataGenerator generator )
|
||||
public Tags( DataGenerator generator, ExistingFileHelper helper )
|
||||
{
|
||||
super( generator );
|
||||
super( generator, new BlockTagsProvider( generator, ComputerCraft.MOD_ID, helper ), ComputerCraft.MOD_ID, helper );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTags()
|
||||
{
|
||||
tag( COMPUTER )
|
||||
.add( Registry.ModItems.COMPUTER_NORMAL.get() )
|
||||
.add( Registry.ModItems.COMPUTER_ADVANCED.get() )
|
||||
.add( Registry.ModItems.COMPUTER_COMMAND.get() );
|
||||
tag( COMPUTER ).add(
|
||||
Registry.ModItems.COMPUTER_NORMAL.get(),
|
||||
Registry.ModItems.COMPUTER_ADVANCED.get(),
|
||||
Registry.ModItems.COMPUTER_COMMAND.get()
|
||||
);
|
||||
tag( TURTLE ).add( Registry.ModItems.TURTLE_NORMAL.get(), Registry.ModItems.TURTLE_ADVANCED.get() );
|
||||
tag( WIRED_MODEM ).add( Registry.ModItems.WIRED_MODEM.get(), Registry.ModItems.WIRED_MODEM_FULL.get() );
|
||||
tag( MONITOR )
|
||||
.add( Registry.ModItems.MONITOR_NORMAL.get() )
|
||||
.add( Registry.ModItems.MONITOR_ADVANCED.get() );
|
||||
tag( MONITOR ).add( Registry.ModItems.MONITOR_NORMAL.get(), Registry.ModItems.MONITOR_ADVANCED.get() );
|
||||
|
||||
tag( PIGLIN_LOVED ).add(
|
||||
Registry.ModItems.COMPUTER_ADVANCED.get(), Registry.ModItems.TURTLE_ADVANCED.get(),
|
||||
Registry.ModItems.WIRELESS_MODEM_ADVANCED.get(), Registry.ModItems.POCKET_COMPUTER_ADVANCED.get(),
|
||||
Registry.ModItems.MONITOR_ADVANCED.get()
|
||||
);
|
||||
}
|
||||
|
||||
private static Tag<Item> item( String name )
|
||||
private static ITag.INamedTag<Item> item( String name )
|
||||
{
|
||||
return new ItemTags.Wrapper( new ResourceLocation( ComputerCraft.MOD_ID, name ) );
|
||||
return ItemTags.bind( new ResourceLocation( ComputerCraft.MOD_ID, name ).toString() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,19 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public final class BundledRedstone
|
||||
{
|
||||
private static final Set<IBundledRedstoneProvider> providers = new LinkedHashSet<>();
|
||||
private static final ArrayList<IBundledRedstoneProvider> providers = new ArrayList<>();
|
||||
|
||||
private BundledRedstone() {}
|
||||
|
||||
public static synchronized void register( @Nonnull IBundledRedstoneProvider provider )
|
||||
{
|
||||
Objects.requireNonNull( provider, "provider cannot be null" );
|
||||
providers.add( provider );
|
||||
if( !providers.contains( provider ) ) providers.add( provider );
|
||||
}
|
||||
|
||||
public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
package dan200.computercraft.shared;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.core.apis.http.NetworkUtils;
|
||||
import dan200.computercraft.core.computer.MainThread;
|
||||
import dan200.computercraft.core.tracking.ComputerMBean;
|
||||
import dan200.computercraft.core.tracking.Tracking;
|
||||
import dan200.computercraft.shared.command.CommandComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.IComputer;
|
||||
@@ -15,12 +15,15 @@ import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.loot.ConstantRange;
|
||||
import net.minecraft.loot.LootPool;
|
||||
import net.minecraft.loot.LootTables;
|
||||
import net.minecraft.loot.TableLootEntry;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.ConstantRange;
|
||||
import net.minecraft.world.storage.loot.LootPool;
|
||||
import net.minecraft.world.storage.loot.LootTables;
|
||||
import net.minecraft.world.storage.loot.TableLootEntry;
|
||||
import net.minecraftforge.event.LootTableLoadEvent;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -72,10 +75,20 @@ public final class CommonHooks
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRegisterCommand( RegisterCommandsEvent event )
|
||||
{
|
||||
CommandComputerCraft.register( event.getDispatcher() );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onServerStarting( FMLServerStartingEvent event )
|
||||
{
|
||||
CommandComputerCraft.register( event.getCommandDispatcher() );
|
||||
MinecraftServer server = event.getServer();
|
||||
if( server instanceof DedicatedServer && ((DedicatedServer) server).getProperties().enableJmxMonitoring )
|
||||
{
|
||||
ComputerMBean.register();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -84,7 +97,7 @@ public final class CommonHooks
|
||||
ComputerCraft.serverComputerRegistry.reset();
|
||||
WirelessNetwork.resetNetworks();
|
||||
Tracking.reset();
|
||||
NetworkUtils.reset();
|
||||
ComputerMBean.registerTracker();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -93,7 +106,6 @@ public final class CommonHooks
|
||||
ComputerCraft.serverComputerRegistry.reset();
|
||||
WirelessNetwork.resetNetworks();
|
||||
Tracking.reset();
|
||||
NetworkUtils.reset();
|
||||
}
|
||||
|
||||
public static final ResourceLocation LOOT_TREASURE_DISK = new ResourceLocation( ComputerCraft.MOD_ID, "treasure_disk" );
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Converter;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
||||
import dan200.computercraft.core.apis.http.NetworkUtils;
|
||||
import dan200.computercraft.core.apis.http.options.Action;
|
||||
import dan200.computercraft.core.apis.http.options.AddressRuleConfig;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
@@ -57,9 +56,6 @@ public final class Config
|
||||
private static final ConfigValue<Integer> httpMaxRequests;
|
||||
private static final ConfigValue<Integer> httpMaxWebsockets;
|
||||
|
||||
private static final ConfigValue<Integer> httpDownloadBandwidth;
|
||||
private static final ConfigValue<Integer> httpUploadBandwidth;
|
||||
|
||||
private static final ConfigValue<Boolean> commandBlockEnabled;
|
||||
private static final ConfigValue<Integer> modemRange;
|
||||
private static final ConfigValue<Integer> modemHighAltitudeRange;
|
||||
@@ -191,20 +187,6 @@ public final class Config
|
||||
.comment( "The number of websockets a computer can have open at one time. Set to 0 for unlimited." )
|
||||
.defineInRange( "max_websockets", ComputerCraft.httpMaxWebsockets, 1, Integer.MAX_VALUE );
|
||||
|
||||
builder
|
||||
.comment( "Limits bandwidth used by computers" )
|
||||
.push( "bandwidth" );
|
||||
|
||||
httpDownloadBandwidth = builder
|
||||
.comment( "The number of bytes which can be downloaded in a second. This is shared across all computers. (bytes/s)" )
|
||||
.defineInRange( "global_download", ComputerCraft.httpDownloadBandwidth, 1, Integer.MAX_VALUE );
|
||||
|
||||
httpUploadBandwidth = builder
|
||||
.comment( "The number of bytes which can be uploaded in a second. This is shared across all computers. (bytes/s)" )
|
||||
.defineInRange( "global_upload", ComputerCraft.httpUploadBandwidth, 1, Integer.MAX_VALUE );
|
||||
|
||||
builder.pop();
|
||||
|
||||
builder.pop();
|
||||
}
|
||||
|
||||
@@ -347,8 +329,6 @@ public final class Config
|
||||
|
||||
ComputerCraft.httpMaxRequests = httpMaxRequests.get();
|
||||
ComputerCraft.httpMaxWebsockets = httpMaxWebsockets.get();
|
||||
ComputerCraft.httpDownloadBandwidth = httpDownloadBandwidth.get();
|
||||
NetworkUtils.reloadConfig();
|
||||
|
||||
// Peripheral
|
||||
ComputerCraft.enableCommandBlock = commandBlockEnabled.get();
|
||||
|
||||
@@ -23,9 +23,9 @@ import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||
import dan200.computercraft.shared.computer.recipe.ComputerUpgradeRecipe;
|
||||
import dan200.computercraft.shared.data.BlockNamedEntityLootCondition;
|
||||
import dan200.computercraft.shared.data.ConstantLootConditionSerializer;
|
||||
import dan200.computercraft.shared.data.HasComputerIdLootCondition;
|
||||
import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
|
||||
import dan200.computercraft.shared.integration.morered.MoreRedIntegration;
|
||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||
@@ -67,6 +67,7 @@ import dan200.computercraft.shared.turtle.recipes.TurtleRecipe;
|
||||
import dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe;
|
||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||
import dan200.computercraft.shared.util.*;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
@@ -74,10 +75,10 @@ import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.item.crafting.IRecipeSerializer;
|
||||
import net.minecraft.loot.LootConditionType;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.conditions.LootConditionManager;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
@@ -85,6 +86,7 @@ import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fml.DeferredWorkQueue;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
@@ -107,21 +109,21 @@ public final class Registry
|
||||
|
||||
public static final class ModBlocks
|
||||
{
|
||||
static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>( ForgeRegistries.BLOCKS, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<Block> BLOCKS = DeferredRegister.create( ForgeRegistries.BLOCKS, ComputerCraft.MOD_ID );
|
||||
|
||||
private static Block.Properties properties()
|
||||
private static AbstractBlock.Properties properties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 2 );
|
||||
return AbstractBlock.Properties.of( Material.STONE ).strength( 2 );
|
||||
}
|
||||
|
||||
private static Block.Properties turtleProperties()
|
||||
private static AbstractBlock.Properties turtleProperties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 2.5f );
|
||||
return AbstractBlock.Properties.of( Material.STONE ).strength( 2.5f );
|
||||
}
|
||||
|
||||
private static Block.Properties modemProperties()
|
||||
private static AbstractBlock.Properties modemProperties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 1.5f );
|
||||
return AbstractBlock.Properties.of( Material.STONE ).strength( 1.5f );
|
||||
}
|
||||
|
||||
public static final RegistryObject<BlockComputer> COMPUTER_NORMAL = BLOCKS.register( "computer_normal",
|
||||
@@ -130,7 +132,7 @@ public final class Registry
|
||||
() -> new BlockComputer( properties(), ComputerFamily.ADVANCED, ModTiles.COMPUTER_ADVANCED ) );
|
||||
|
||||
public static final RegistryObject<BlockComputer> COMPUTER_COMMAND = BLOCKS.register( "computer_command", () -> new BlockComputer(
|
||||
Block.Properties.of( Material.STONE ).strength( -1, 6000000.0F ),
|
||||
AbstractBlock.Properties.of( Material.STONE ).strength( -1, 6000000.0F ),
|
||||
ComputerFamily.COMMAND, ModTiles.COMPUTER_COMMAND
|
||||
) );
|
||||
|
||||
@@ -160,7 +162,7 @@ public final class Registry
|
||||
|
||||
public static class ModTiles
|
||||
{
|
||||
static final DeferredRegister<TileEntityType<?>> TILES = new DeferredRegister<>( ForgeRegistries.TILE_ENTITIES, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<TileEntityType<?>> TILES = DeferredRegister.create( ForgeRegistries.TILE_ENTITIES, ComputerCraft.MOD_ID );
|
||||
|
||||
private static <T extends TileEntity> RegistryObject<TileEntityType<T>> ofBlock( RegistryObject<? extends Block> block, Function<TileEntityType<T>, T> factory )
|
||||
{
|
||||
@@ -198,7 +200,7 @@ public final class Registry
|
||||
|
||||
public static final class ModItems
|
||||
{
|
||||
static final DeferredRegister<Item> ITEMS = new DeferredRegister<>( ForgeRegistries.ITEMS, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<Item> ITEMS = DeferredRegister.create( ForgeRegistries.ITEMS, ComputerCraft.MOD_ID );
|
||||
|
||||
private static Item.Properties properties()
|
||||
{
|
||||
@@ -296,7 +298,7 @@ public final class Registry
|
||||
|
||||
public static class ModEntities
|
||||
{
|
||||
static final DeferredRegister<EntityType<?>> ENTITIES = new DeferredRegister<>( ForgeRegistries.ENTITIES, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create( ForgeRegistries.ENTITIES, ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<EntityType<TurtlePlayer>> TURTLE_PLAYER = ENTITIES.register( "turtle_player", () ->
|
||||
EntityType.Builder.<TurtlePlayer>createNothing( EntityClassification.MISC )
|
||||
@@ -308,7 +310,7 @@ public final class Registry
|
||||
|
||||
public static class ModContainers
|
||||
{
|
||||
static final DeferredRegister<ContainerType<?>> CONTAINERS = new DeferredRegister<>( ForgeRegistries.CONTAINERS, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create( ForgeRegistries.CONTAINERS, ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<ContainerType<ContainerComputer>> COMPUTER = CONTAINERS.register( "computer",
|
||||
() -> ContainerData.toType( ComputerContainerData::new, ContainerComputer::new ) );
|
||||
@@ -387,27 +389,24 @@ public final class Registry
|
||||
ComputerCraftAPI.registerGenericCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY );
|
||||
ComputerCraftAPI.registerGenericCapability( CapabilityEnergy.ENERGY );
|
||||
ComputerCraftAPI.registerGenericCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY );
|
||||
|
||||
// Mod integration code.
|
||||
if( ModList.get().isLoaded( MoreRedIntegration.MOD_ID ) ) MoreRedIntegration.initialise();
|
||||
}
|
||||
|
||||
public static void registerLoot()
|
||||
{
|
||||
LootConditionManager.register( ConstantLootConditionSerializer.of(
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, "block_named" ),
|
||||
BlockNamedEntityLootCondition.class,
|
||||
BlockNamedEntityLootCondition.INSTANCE
|
||||
) );
|
||||
registerCondition( "block_named", BlockNamedEntityLootCondition.TYPE );
|
||||
registerCondition( "player_creative", PlayerCreativeLootCondition.TYPE );
|
||||
registerCondition( "has_id", HasComputerIdLootCondition.TYPE );
|
||||
}
|
||||
|
||||
LootConditionManager.register( ConstantLootConditionSerializer.of(
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, "player_creative" ),
|
||||
PlayerCreativeLootCondition.class,
|
||||
PlayerCreativeLootCondition.INSTANCE
|
||||
) );
|
||||
|
||||
LootConditionManager.register( ConstantLootConditionSerializer.of(
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, "has_id" ),
|
||||
HasComputerIdLootCondition.class,
|
||||
HasComputerIdLootCondition.INSTANCE
|
||||
) );
|
||||
private static void registerCondition( String name, LootConditionType serializer )
|
||||
{
|
||||
net.minecraft.util.registry.Registry.register(
|
||||
net.minecraft.util.registry.Registry.LOOT_CONDITION_TYPE,
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, name ), serializer
|
||||
);
|
||||
}
|
||||
|
||||
public static void setup()
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@@ -20,13 +21,12 @@ public final class TurtlePermissions
|
||||
public static boolean isBlockEnterable( World world, BlockPos pos, PlayerEntity player )
|
||||
{
|
||||
MinecraftServer server = world.getServer();
|
||||
return server == null || world.isClientSide || !server.isUnderSpawnProtection( world, pos, player );
|
||||
return server == null || world.isClientSide || (world instanceof ServerWorld && !server.isUnderSpawnProtection( (ServerWorld) world, pos, player ));
|
||||
}
|
||||
|
||||
public static boolean isBlockEditable( World world, BlockPos pos, PlayerEntity player )
|
||||
{
|
||||
MinecraftServer server = world.getServer();
|
||||
return server == null || world.isClientSide || !server.isUnderSpawnProtection( world, pos, player );
|
||||
return isBlockEnterable( world, pos, player );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -7,13 +7,11 @@ package dan200.computercraft.shared.command;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.util.IDAssigner;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -37,9 +35,6 @@ public final class ClientCommands
|
||||
// Emulate the command on the client side
|
||||
if( event.getMessage().startsWith( OPEN_COMPUTER ) )
|
||||
{
|
||||
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
if( server == null || server.isDedicatedServer() ) return;
|
||||
|
||||
event.setCanceled( true );
|
||||
|
||||
String idStr = event.getMessage().substring( OPEN_COMPUTER.length() ).trim();
|
||||
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.network.play.server.SPlayerPositionLookPacket;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
@@ -285,7 +286,7 @@ public final class CommandComputerCraft
|
||||
|
||||
private static ITextComponent linkComputer( CommandSource source, ServerComputer serverComputer, int computerId )
|
||||
{
|
||||
ITextComponent out = new StringTextComponent( "" );
|
||||
IFormattableTextComponent out = new StringTextComponent( "" );
|
||||
|
||||
// Append the computer instance
|
||||
if( serverComputer == null )
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
@@ -173,7 +174,7 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
|
||||
temp.addChild( node );
|
||||
String usage = dispatcher.getSmartUsage( temp, context.getSource() ).get( node ).substring( node.getName().length() );
|
||||
|
||||
ITextComponent output = new StringTextComponent( "" )
|
||||
IFormattableTextComponent output = new StringTextComponent( "" )
|
||||
.append( coloured( "/" + command + usage, HEADER ) )
|
||||
.append( " " )
|
||||
.append( coloured( translate( "commands." + id + ".synopsis" ), SYNOPSIS ) )
|
||||
@@ -189,8 +190,8 @@ public final class HelpingArgumentBuilder extends LiteralArgumentBuilder<Command
|
||||
|
||||
output.append( "\n" );
|
||||
|
||||
ITextComponent component = coloured( child.getName(), NAME );
|
||||
component.getStyle().setClickEvent( new ClickEvent(
|
||||
IFormattableTextComponent component = coloured( child.getName(), NAME );
|
||||
component.getStyle().withClickEvent( new ClickEvent(
|
||||
ClickEvent.Action.SUGGEST_COMMAND,
|
||||
"/" + command + " " + child.getName()
|
||||
) );
|
||||
|
||||
@@ -19,37 +19,35 @@ public final class ChatHelpers
|
||||
|
||||
private ChatHelpers() {}
|
||||
|
||||
public static ITextComponent coloured( String text, TextFormatting colour )
|
||||
public static IFormattableTextComponent coloured( String text, TextFormatting colour )
|
||||
{
|
||||
ITextComponent component = new StringTextComponent( text == null ? "" : text );
|
||||
component.getStyle().setColor( colour );
|
||||
return new StringTextComponent( text == null ? "" : text ).withStyle( colour );
|
||||
}
|
||||
|
||||
public static <T extends IFormattableTextComponent> T coloured( T component, TextFormatting colour )
|
||||
{
|
||||
component.withStyle( colour );
|
||||
return component;
|
||||
}
|
||||
|
||||
public static <T extends ITextComponent> T coloured( T component, TextFormatting colour )
|
||||
{
|
||||
component.getStyle().setColor( colour );
|
||||
return component;
|
||||
}
|
||||
|
||||
public static ITextComponent text( String text )
|
||||
public static IFormattableTextComponent text( String text )
|
||||
{
|
||||
return new StringTextComponent( text == null ? "" : text );
|
||||
}
|
||||
|
||||
public static ITextComponent translate( String text )
|
||||
public static IFormattableTextComponent translate( String text )
|
||||
{
|
||||
return new TranslationTextComponent( text == null ? "" : text );
|
||||
}
|
||||
|
||||
public static ITextComponent translate( String text, Object... args )
|
||||
public static IFormattableTextComponent translate( String text, Object... args )
|
||||
{
|
||||
return new TranslationTextComponent( text == null ? "" : text, args );
|
||||
}
|
||||
|
||||
public static ITextComponent list( ITextComponent... children )
|
||||
public static IFormattableTextComponent list( ITextComponent... children )
|
||||
{
|
||||
ITextComponent component = new StringTextComponent( "" );
|
||||
IFormattableTextComponent component = new StringTextComponent( "" );
|
||||
for( ITextComponent child : children )
|
||||
{
|
||||
component.append( child );
|
||||
@@ -57,20 +55,20 @@ public final class ChatHelpers
|
||||
return component;
|
||||
}
|
||||
|
||||
public static ITextComponent position( BlockPos pos )
|
||||
public static IFormattableTextComponent position( BlockPos pos )
|
||||
{
|
||||
if( pos == null ) return translate( "commands.computercraft.generic.no_position" );
|
||||
return translate( "commands.computercraft.generic.position", pos.getX(), pos.getY(), pos.getZ() );
|
||||
}
|
||||
|
||||
public static ITextComponent bool( boolean value )
|
||||
public static IFormattableTextComponent bool( boolean value )
|
||||
{
|
||||
return value
|
||||
? coloured( translate( "commands.computercraft.generic.yes" ), TextFormatting.GREEN )
|
||||
: coloured( translate( "commands.computercraft.generic.no" ), TextFormatting.RED );
|
||||
}
|
||||
|
||||
public static ITextComponent link( ITextComponent component, String command, ITextComponent toolTip )
|
||||
public static ITextComponent link( IFormattableTextComponent component, String command, ITextComponent toolTip )
|
||||
{
|
||||
return link( component, new ClickEvent( ClickEvent.Action.RUN_COMMAND, command ), toolTip );
|
||||
}
|
||||
@@ -79,24 +77,24 @@ public final class ChatHelpers
|
||||
{
|
||||
Style style = component.getStyle();
|
||||
|
||||
if( style.getColor() == null ) style.setColor( TextFormatting.YELLOW );
|
||||
style.setClickEvent( click );
|
||||
style.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, toolTip ) );
|
||||
if( style.getColor() == null ) style = style.withColor( TextFormatting.YELLOW );
|
||||
style = style.withClickEvent( click );
|
||||
style = style.withHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, toolTip ) );
|
||||
|
||||
return component;
|
||||
return component.copy().withStyle( style );
|
||||
}
|
||||
|
||||
public static ITextComponent header( String text )
|
||||
public static IFormattableTextComponent header( String text )
|
||||
{
|
||||
return coloured( text, HEADER );
|
||||
}
|
||||
|
||||
public static ITextComponent copy( String text )
|
||||
public static IFormattableTextComponent copy( String text )
|
||||
{
|
||||
StringTextComponent name = new StringTextComponent( text );
|
||||
name.getStyle()
|
||||
.setClickEvent( new ClickEvent( ClickEvent.Action.COPY_TO_CLIPBOARD, text ) )
|
||||
.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent( "gui.computercraft.tooltip.copy" ) ) );
|
||||
return name;
|
||||
Style style = name.getStyle()
|
||||
.withClickEvent( new ClickEvent( ClickEvent.Action.COPY_TO_CLIPBOARD, text ) )
|
||||
.withHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent( "gui.computercraft.tooltip.copy" ) ) );
|
||||
return name.withStyle( style );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ public abstract class TileGeneric extends TileEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag( @Nonnull CompoundNBT tag )
|
||||
public void handleUpdateTag( @Nonnull BlockState state, @Nonnull CompoundNBT tag )
|
||||
{
|
||||
super.handleUpdateTag( tag );
|
||||
super.handleUpdateTag( state, tag );
|
||||
readDescription( tag );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.LootContext;
|
||||
import net.minecraft.loot.LootParameters;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
@@ -23,12 +25,11 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraft.world.storage.loot.LootParameters;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -139,6 +140,7 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
public void playerWillDestroy( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull PlayerEntity player )
|
||||
{
|
||||
if( !(world instanceof ServerWorld) ) return;
|
||||
ServerWorld serverWorld = (ServerWorld) world;
|
||||
|
||||
// We drop the item here instead of doing it in the harvest method, as we should
|
||||
// drop computers for creative players too.
|
||||
@@ -147,19 +149,19 @@ public abstract class BlockComputerBase<T extends TileComputerBase> extends Bloc
|
||||
if( tile instanceof TileComputerBase )
|
||||
{
|
||||
TileComputerBase computer = (TileComputerBase) tile;
|
||||
LootContext.Builder context = new LootContext.Builder( (ServerWorld) world )
|
||||
LootContext.Builder context = new LootContext.Builder( serverWorld )
|
||||
.withRandom( world.random )
|
||||
.withParameter( LootParameters.BLOCK_POS, pos )
|
||||
.withParameter( LootParameters.ORIGIN, Vector3d.atCenterOf( pos ) )
|
||||
.withParameter( LootParameters.TOOL, player.getMainHandItem() )
|
||||
.withParameter( LootParameters.THIS_ENTITY, player )
|
||||
.withOptionalParameter( LootParameters.BLOCK_ENTITY, tile )
|
||||
.withParameter( LootParameters.BLOCK_ENTITY, tile )
|
||||
.withDynamicDrop( DROP, ( ctx, out ) -> out.accept( getItem( computer ) ) );
|
||||
for( ItemStack item : state.getDrops( context ) )
|
||||
{
|
||||
popResource( world, pos, item );
|
||||
}
|
||||
|
||||
state.spawnAfterBreak( world, pos, player.getMainHandItem() );
|
||||
state.spawnAfterBreak( serverWorld, pos, player.getMainHandItem() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import net.minecraft.command.ICommandSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector2f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.world.server.ServerWorld;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TileCommandComputer extends TileComputer
|
||||
{
|
||||
@@ -48,7 +49,7 @@ public class TileCommandComputer extends TileComputer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage( @Nonnull ITextComponent textComponent )
|
||||
public void sendMessage( @Nonnull ITextComponent textComponent, @Nonnull UUID id )
|
||||
{
|
||||
output.put( output.size() + 1, textComponent.getString() );
|
||||
}
|
||||
@@ -96,7 +97,7 @@ public class TileCommandComputer extends TileComputer
|
||||
}
|
||||
|
||||
return new CommandSource( receiver,
|
||||
new Vec3d( worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5 ), Vec2f.ZERO,
|
||||
new Vector3d( worldPosition.getX() + 0.5, worldPosition.getY() + 0.5, worldPosition.getZ() + 0.5 ), Vector2f.ZERO,
|
||||
(ServerWorld) getLevel(), 2,
|
||||
name, new StringTextComponent( name ),
|
||||
getLevel().getServer(), null
|
||||
|
||||
@@ -200,9 +200,9 @@ public abstract class TileComputerBase extends TileGeneric implements IComputerT
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load( @Nonnull CompoundNBT nbt )
|
||||
public void load( @Nonnull BlockState state, @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.load( nbt );
|
||||
super.load( state, nbt );
|
||||
|
||||
// Load ID, label and power state
|
||||
computerID = nbt.contains( NBT_ID ) ? nbt.getInt( NBT_ID ) : -1;
|
||||
|
||||
@@ -5,16 +5,18 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.computer.core;
|
||||
|
||||
import dan200.computercraft.shared.computer.upload.FileUpload;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An instance of {@link Container} which provides a computer. You should implement this
|
||||
* if you provide custom computers/GUIs to interact with them.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IContainerComputer
|
||||
{
|
||||
/**
|
||||
@@ -33,8 +35,21 @@ public interface IContainerComputer
|
||||
* @return This container's input.
|
||||
*/
|
||||
@Nonnull
|
||||
default InputState getInput()
|
||||
{
|
||||
return new InputState( this );
|
||||
}
|
||||
InputState getInput();
|
||||
|
||||
/**
|
||||
* Attempt to upload a series of files to this computer.
|
||||
*
|
||||
* @param uploader The player uploading files.
|
||||
* @param files The files to upload.
|
||||
*/
|
||||
void upload( @Nonnull ServerPlayerEntity uploader, @Nonnull List<FileUpload> files );
|
||||
|
||||
/**
|
||||
* Continue an upload.
|
||||
*
|
||||
* @param uploader The player uploading files.
|
||||
* @param overwrite Whether the files should be overwritten or not.
|
||||
*/
|
||||
void continueUpload( @Nonnull ServerPlayerEntity uploader, boolean overwrite );
|
||||
}
|
||||
|
||||
@@ -6,23 +6,41 @@
|
||||
package dan200.computercraft.shared.computer.inventory;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.core.filesystem.FileSystem;
|
||||
import dan200.computercraft.core.filesystem.FileSystemException;
|
||||
import dan200.computercraft.core.filesystem.FileSystemWrapper;
|
||||
import dan200.computercraft.shared.computer.core.*;
|
||||
import dan200.computercraft.shared.computer.upload.FileUpload;
|
||||
import dan200.computercraft.shared.computer.upload.UploadResult;
|
||||
import dan200.computercraft.shared.network.NetworkHandler;
|
||||
import dan200.computercraft.shared.network.client.UploadResultMessage;
|
||||
import dan200.computercraft.shared.network.container.ComputerContainerData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ContainerComputerBase extends Container implements IContainerComputer
|
||||
{
|
||||
private static final String LIST_PREFIX = "\n \u2022 ";
|
||||
|
||||
private final Predicate<PlayerEntity> canUse;
|
||||
private final IComputer computer;
|
||||
private final ComputerFamily family;
|
||||
private final InputState input = new InputState( this );
|
||||
private List<FileUpload> toUpload;
|
||||
|
||||
protected ContainerComputerBase( ContainerType<? extends ContainerComputerBase> type, int id, Predicate<PlayerEntity> canUse, IComputer computer, ComputerFamily family )
|
||||
{
|
||||
@@ -73,6 +91,86 @@ public class ContainerComputerBase extends Container implements IContainerComput
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upload( @Nonnull ServerPlayerEntity uploader, @Nonnull List<FileUpload> files )
|
||||
{
|
||||
UploadResultMessage message = upload( files, false );
|
||||
NetworkHandler.sendToPlayer( uploader, message );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void continueUpload( @Nonnull ServerPlayerEntity uploader, boolean overwrite )
|
||||
{
|
||||
List<FileUpload> files = this.toUpload;
|
||||
toUpload = null;
|
||||
if( files == null || files.isEmpty() || !overwrite ) return;
|
||||
|
||||
UploadResultMessage message = upload( files, true );
|
||||
NetworkHandler.sendToPlayer( uploader, message );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private UploadResultMessage upload( @Nonnull List<FileUpload> files, boolean forceOverwrite )
|
||||
{
|
||||
ServerComputer computer = (ServerComputer) getComputer();
|
||||
if( computer == null ) return UploadResultMessage.COMPUTER_OFF;
|
||||
|
||||
FileSystem fs = computer.getComputer().getEnvironment().getFileSystem();
|
||||
if( fs == null ) return UploadResultMessage.COMPUTER_OFF;
|
||||
|
||||
try
|
||||
{
|
||||
List<String> overwrite = new ArrayList<>();
|
||||
for( FileUpload upload : files )
|
||||
{
|
||||
if( !fs.exists( upload.getName() ) ) continue;
|
||||
if( fs.isDir( upload.getName() ) )
|
||||
{
|
||||
return new UploadResultMessage(
|
||||
UploadResult.ERROR,
|
||||
new TranslationTextComponent( "gui.computercraft.upload.failed.overwrite_dir", upload.getName() )
|
||||
);
|
||||
}
|
||||
|
||||
overwrite.add( upload.getName() );
|
||||
}
|
||||
|
||||
if( !overwrite.isEmpty() && !forceOverwrite )
|
||||
{
|
||||
StringJoiner joiner = new StringJoiner( LIST_PREFIX, LIST_PREFIX, "" );
|
||||
for( String value : overwrite ) joiner.add( value );
|
||||
|
||||
toUpload = files;
|
||||
return new UploadResultMessage(
|
||||
UploadResult.CONFIRM_OVERWRITE,
|
||||
new TranslationTextComponent( "gui.computercraft.upload.overwrite.detail", joiner.toString() )
|
||||
);
|
||||
}
|
||||
|
||||
long availableSpace = fs.getFreeSpace( "/" );
|
||||
long neededSpace = 0;
|
||||
for( FileUpload upload : files ) neededSpace += Math.max( 512, upload.getBytes().remaining() );
|
||||
if( neededSpace > availableSpace ) return UploadResultMessage.OUT_OF_SPACE;
|
||||
|
||||
for( FileUpload file : files )
|
||||
{
|
||||
try( FileSystemWrapper<WritableByteChannel> channel = fs.openForWrite( file.getName(), false, Function.identity() ) )
|
||||
{
|
||||
channel.get().write( file.getBytes() );
|
||||
}
|
||||
}
|
||||
|
||||
return new UploadResultMessage(
|
||||
UploadResult.SUCCESS, new TranslationTextComponent( "gui.computercraft.upload.success.msg", files.size() )
|
||||
);
|
||||
}
|
||||
catch( FileSystemException | IOException e )
|
||||
{
|
||||
ComputerCraft.log.error( "Error uploading files", e );
|
||||
return new UploadResultMessage( UploadResult.ERROR, new TranslationTextComponent( "computercraft.gui.upload.failed.generic", e.getMessage() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed( @Nonnull PlayerEntity player )
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.network.container.ViewComputerContainerData;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -17,7 +16,7 @@ import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ContainerViewComputer extends ContainerComputerBase implements IContainerComputer
|
||||
public class ContainerViewComputer extends ContainerComputerBase
|
||||
{
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.computer.upload;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class FileUpload
|
||||
{
|
||||
private final String name;
|
||||
private final ByteBuffer bytes;
|
||||
|
||||
public FileUpload( String name, ByteBuffer bytes )
|
||||
{
|
||||
this.name = name;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public ByteBuffer getBytes()
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.computer.upload;
|
||||
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
public enum UploadResult
|
||||
{
|
||||
SUCCESS,
|
||||
ERROR,
|
||||
CONFIRM_OVERWRITE;
|
||||
|
||||
public static final ITextComponent SUCCESS_TITLE = new TranslationTextComponent( "gui.computercraft.upload.success" );
|
||||
|
||||
public static final ITextComponent FAILED_TITLE = new TranslationTextComponent( "gui.computercraft.upload.failed" );
|
||||
public static final ITextComponent COMPUTER_OFF_MSG = new TranslationTextComponent( "gui.computercraft.upload.failed.computer_off" );
|
||||
public static final ITextComponent OUT_OF_SPACE_MSG = new TranslationTextComponent( "gui.computercraft.upload.failed.out_of_space" );
|
||||
public static final ITextComponent TOO_MUCH_MSG = new TranslationTextComponent( "gui.computercraft.upload.failed.too_much" );
|
||||
|
||||
public static final ITextComponent UPLOAD_OVERWRITE = new TranslationTextComponent( "gui.computercraft.upload.overwrite" );
|
||||
}
|
||||
@@ -5,12 +5,13 @@
|
||||
*/
|
||||
package dan200.computercraft.shared.data;
|
||||
|
||||
import net.minecraft.loot.LootConditionType;
|
||||
import net.minecraft.loot.LootContext;
|
||||
import net.minecraft.loot.LootParameter;
|
||||
import net.minecraft.loot.LootParameters;
|
||||
import net.minecraft.loot.conditions.ILootCondition;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.INameable;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraft.world.storage.loot.LootParameter;
|
||||
import net.minecraft.world.storage.loot.LootParameters;
|
||||
import net.minecraft.world.storage.loot.conditions.ILootCondition;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
@@ -22,6 +23,8 @@ import java.util.Set;
|
||||
public final class BlockNamedEntityLootCondition implements ILootCondition
|
||||
{
|
||||
public static final BlockNamedEntityLootCondition INSTANCE = new BlockNamedEntityLootCondition();
|
||||
public static final LootConditionType TYPE = ConstantLootConditionSerializer.type( INSTANCE );
|
||||
public static final IBuilder BUILDER = () -> INSTANCE;
|
||||
|
||||
private BlockNamedEntityLootCondition()
|
||||
{
|
||||
@@ -41,8 +44,10 @@ public final class BlockNamedEntityLootCondition implements ILootCondition
|
||||
return Collections.singleton( LootParameters.BLOCK_ENTITY );
|
||||
}
|
||||
|
||||
public static IBuilder builder()
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootConditionType getType()
|
||||
{
|
||||
return () -> INSTANCE;
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,24 +8,24 @@ package dan200.computercraft.shared.data;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.conditions.ILootCondition;
|
||||
import net.minecraft.loot.ILootSerializer;
|
||||
import net.minecraft.loot.LootConditionType;
|
||||
import net.minecraft.loot.conditions.ILootCondition;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class ConstantLootConditionSerializer<T extends ILootCondition> extends ILootCondition.AbstractSerializer<T>
|
||||
public final class ConstantLootConditionSerializer<T extends ILootCondition> implements ILootSerializer<T>
|
||||
{
|
||||
private final T instance;
|
||||
|
||||
private ConstantLootConditionSerializer( ResourceLocation id, Class<T> klass, T instance )
|
||||
public ConstantLootConditionSerializer( T instance )
|
||||
{
|
||||
super( id, klass );
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static <T extends ILootCondition> ILootCondition.AbstractSerializer<T> of( ResourceLocation id, Class<T> klass, T instance )
|
||||
public static <T extends ILootCondition> LootConditionType type( T condition )
|
||||
{
|
||||
return new ConstantLootConditionSerializer<>( id, klass, instance );
|
||||
return new LootConditionType( new ConstantLootConditionSerializer<>( condition ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
package dan200.computercraft.shared.data;
|
||||
|
||||
import dan200.computercraft.shared.computer.blocks.IComputerTile;
|
||||
import net.minecraft.loot.LootConditionType;
|
||||
import net.minecraft.loot.LootContext;
|
||||
import net.minecraft.loot.LootParameter;
|
||||
import net.minecraft.loot.LootParameters;
|
||||
import net.minecraft.loot.conditions.ILootCondition;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraft.world.storage.loot.LootParameter;
|
||||
import net.minecraft.world.storage.loot.LootParameters;
|
||||
import net.minecraft.world.storage.loot.conditions.ILootCondition;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
@@ -22,6 +23,8 @@ import java.util.Set;
|
||||
public final class HasComputerIdLootCondition implements ILootCondition
|
||||
{
|
||||
public static final HasComputerIdLootCondition INSTANCE = new HasComputerIdLootCondition();
|
||||
public static final LootConditionType TYPE = ConstantLootConditionSerializer.type( INSTANCE );
|
||||
public static final IBuilder BUILDER = () -> INSTANCE;
|
||||
|
||||
private HasComputerIdLootCondition()
|
||||
{
|
||||
@@ -41,8 +44,10 @@ public final class HasComputerIdLootCondition implements ILootCondition
|
||||
return Collections.singleton( LootParameters.BLOCK_ENTITY );
|
||||
}
|
||||
|
||||
public static IBuilder builder()
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootConditionType getType()
|
||||
{
|
||||
return () -> INSTANCE;
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ package dan200.computercraft.shared.data;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.storage.loot.LootContext;
|
||||
import net.minecraft.world.storage.loot.LootParameter;
|
||||
import net.minecraft.world.storage.loot.LootParameters;
|
||||
import net.minecraft.world.storage.loot.conditions.ILootCondition;
|
||||
import net.minecraft.loot.LootConditionType;
|
||||
import net.minecraft.loot.LootContext;
|
||||
import net.minecraft.loot.LootParameter;
|
||||
import net.minecraft.loot.LootParameters;
|
||||
import net.minecraft.loot.conditions.ILootCondition;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
@@ -22,6 +23,8 @@ import java.util.Set;
|
||||
public final class PlayerCreativeLootCondition implements ILootCondition
|
||||
{
|
||||
public static final PlayerCreativeLootCondition INSTANCE = new PlayerCreativeLootCondition();
|
||||
public static final LootConditionType TYPE = ConstantLootConditionSerializer.type( INSTANCE );
|
||||
public static final IBuilder BUILDER = () -> INSTANCE;
|
||||
|
||||
private PlayerCreativeLootCondition()
|
||||
{
|
||||
@@ -41,8 +44,10 @@ public final class PlayerCreativeLootCondition implements ILootCondition
|
||||
return Collections.singleton( LootParameters.THIS_ENTITY );
|
||||
}
|
||||
|
||||
public static IBuilder builder()
|
||||
@Override
|
||||
@Nonnull
|
||||
public LootConditionType getType()
|
||||
{
|
||||
return () -> INSTANCE;
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,10 @@ public class AddTurtleTool implements IUndoableAction
|
||||
|
||||
if( craftItem.isEmpty() ) trackLog.error( "Crafting item stack is empty." );
|
||||
|
||||
if( craftItem.hasTag() && !craftItem.getTag().isEmpty() ) trackLog.warning( "Crafting item has NBT." );
|
||||
if( craftItem.isDamaged() || craftItem.isEnchanted() || craftItem.hasCustomHoverName() )
|
||||
{
|
||||
trackLog.warning( "Crafting item has NBT." );
|
||||
}
|
||||
if( toolItem.isEmpty() ) trackLog.error( "Tool item stack is empty." );
|
||||
|
||||
if( !kinds.containsKey( kind ) ) trackLog.error( String.format( "Unknown kind '%s'.", kind ) );
|
||||
@@ -122,6 +125,6 @@ public class AddTurtleTool implements IUndoableAction
|
||||
@Override
|
||||
public boolean shouldApplyOn( LogicalSide side )
|
||||
{
|
||||
return true;
|
||||
return shouldApplySingletons();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.JeiPlugin;
|
||||
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
|
||||
import mezz.jei.api.constants.VanillaTypes;
|
||||
import mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter;
|
||||
import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter;
|
||||
import mezz.jei.api.recipe.IRecipeManager;
|
||||
import mezz.jei.api.recipe.category.IRecipeCategory;
|
||||
import mezz.jei.api.registration.IAdvancedRegistration;
|
||||
@@ -90,13 +90,13 @@ public class JEIComputerCraft implements IModPlugin
|
||||
runtime.getIngredientManager().addIngredientsAtRuntime( VanillaTypes.ITEM, upgradeItems );
|
||||
|
||||
// Hide all upgrade recipes
|
||||
IRecipeCategory<?> category = (IRecipeCategory<?>) registry.getRecipeCategory( VanillaRecipeCategoryUid.CRAFTING );
|
||||
IRecipeCategory<?> category = registry.getRecipeCategory( VanillaRecipeCategoryUid.CRAFTING );
|
||||
if( category != null )
|
||||
{
|
||||
for( Object wrapper : registry.getRecipes( category ) )
|
||||
{
|
||||
if( !(wrapper instanceof IRecipe) ) continue;
|
||||
ResourceLocation id = ((IRecipe) wrapper).getId();
|
||||
ResourceLocation id = ((IRecipe<?>) wrapper).getId();
|
||||
if( !id.getNamespace().equals( ComputerCraft.MOD_ID ) ) continue;
|
||||
|
||||
String path = id.getPath();
|
||||
@@ -112,9 +112,9 @@ public class JEIComputerCraft implements IModPlugin
|
||||
/**
|
||||
* Distinguishes turtles by upgrades and family.
|
||||
*/
|
||||
private static final ISubtypeInterpreter turtleSubtype = stack -> {
|
||||
private static final IIngredientSubtypeInterpreter<ItemStack> turtleSubtype = ( stack, ctx ) -> {
|
||||
Item item = stack.getItem();
|
||||
if( !(item instanceof ITurtleItem) ) return ISubtypeInterpreter.NONE;
|
||||
if( !(item instanceof ITurtleItem) ) return IIngredientSubtypeInterpreter.NONE;
|
||||
|
||||
ITurtleItem turtle = (ITurtleItem) item;
|
||||
StringBuilder name = new StringBuilder( "turtle:" );
|
||||
@@ -132,9 +132,9 @@ public class JEIComputerCraft implements IModPlugin
|
||||
/**
|
||||
* Distinguishes pocket computers by upgrade and family.
|
||||
*/
|
||||
private static final ISubtypeInterpreter pocketSubtype = stack -> {
|
||||
private static final IIngredientSubtypeInterpreter<ItemStack> pocketSubtype = ( stack, ctx ) -> {
|
||||
Item item = stack.getItem();
|
||||
if( !(item instanceof ItemPocketComputer) ) return ISubtypeInterpreter.NONE;
|
||||
if( !(item instanceof ItemPocketComputer) ) return IIngredientSubtypeInterpreter.NONE;
|
||||
|
||||
StringBuilder name = new StringBuilder( "pocket:" );
|
||||
|
||||
@@ -148,13 +148,13 @@ public class JEIComputerCraft implements IModPlugin
|
||||
/**
|
||||
* Distinguishes disks by colour.
|
||||
*/
|
||||
private static final ISubtypeInterpreter diskSubtype = stack -> {
|
||||
private static final IIngredientSubtypeInterpreter<ItemStack> diskSubtype = ( stack, ctx ) -> {
|
||||
Item item = stack.getItem();
|
||||
if( !(item instanceof ItemDisk) ) return ISubtypeInterpreter.NONE;
|
||||
if( !(item instanceof ItemDisk) ) return IIngredientSubtypeInterpreter.NONE;
|
||||
|
||||
ItemDisk disk = (ItemDisk) item;
|
||||
|
||||
int colour = disk.getColour( stack );
|
||||
return colour == -1 ? ISubtypeInterpreter.NONE : String.format( "%06x", colour );
|
||||
return colour == -1 ? IIngredientSubtypeInterpreter.NONE : String.format( "%06x", colour );
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.integration.morered;
|
||||
|
||||
import commoble.morered.api.ChanneledPowerSupplier;
|
||||
import commoble.morered.api.MoreRedAPI;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.shared.common.IBundledRedstoneBlock;
|
||||
import dan200.computercraft.shared.util.CapabilityUtil;
|
||||
import dan200.computercraft.shared.util.FixedPointTileEntityType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MoreRedIntegration
|
||||
{
|
||||
public static final String MOD_ID = "morered";
|
||||
|
||||
private static final ResourceLocation ID = new ResourceLocation( ComputerCraft.MOD_ID, "morered" );
|
||||
|
||||
private static final class BundledPowerSupplier implements ICapabilityProvider, ChanneledPowerSupplier
|
||||
{
|
||||
private final IBundledRedstoneBlock block;
|
||||
private final TileEntity tile;
|
||||
private LazyOptional<ChanneledPowerSupplier> instance;
|
||||
|
||||
private BundledPowerSupplier( IBundledRedstoneBlock block, TileEntity tile )
|
||||
{
|
||||
this.block = block;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> cap, @Nullable Direction side )
|
||||
{
|
||||
if( cap != MoreRedAPI.CHANNELED_POWER_CAPABILITY ) return LazyOptional.empty();
|
||||
|
||||
if( tile.isRemoved() || !block.getBundledRedstoneConnectivity( tile.getLevel(), tile.getBlockPos(), side ) )
|
||||
{
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
return (instance == null ? (instance = LazyOptional.of( () -> this )) : instance).cast();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPowerOnChannel( @Nonnull World world, @Nonnull BlockPos wirePos, @Nonnull BlockState wireState, @Nullable Direction wireFace, int channel )
|
||||
{
|
||||
if( wireFace == null ) return 0;
|
||||
|
||||
BlockPos pos = wirePos.relative( wireFace );
|
||||
BlockState state = world.getBlockState( pos );
|
||||
if( !(state.getBlock() instanceof IBundledRedstoneBlock) ) return 0;
|
||||
|
||||
IBundledRedstoneBlock block = (IBundledRedstoneBlock) state.getBlock();
|
||||
return (block.getBundledRedstoneOutput( world, pos, wireFace.getOpposite() ) & (1 << channel)) != 0 ? 31 : 0;
|
||||
}
|
||||
|
||||
void invalidate()
|
||||
{
|
||||
instance = CapabilityUtil.invalidate( instance );
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void attachBlockCapabilities( AttachCapabilitiesEvent<TileEntity> event )
|
||||
{
|
||||
TileEntity tile = event.getObject();
|
||||
if( !(tile.getType() instanceof FixedPointTileEntityType) ) return;
|
||||
|
||||
Block block = ((FixedPointTileEntityType<?>) tile.getType()).getBlock();
|
||||
if( !(block instanceof IBundledRedstoneBlock) ) return;
|
||||
|
||||
BundledPowerSupplier provider = new BundledPowerSupplier( (IBundledRedstoneBlock) block, tile );
|
||||
event.addCapability( ID, provider );
|
||||
event.addListener( provider::invalidate );
|
||||
}
|
||||
|
||||
public static void initialise()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register( MoreRedIntegration.class );
|
||||
ComputerCraftAPI.registerBundledRedstoneProvider( MoreRedIntegration::getBundledPower );
|
||||
}
|
||||
|
||||
private static int getBundledPower( World world, BlockPos pos, Direction side )
|
||||
{
|
||||
TileEntity tile = world.getBlockEntity( pos );
|
||||
if( tile == null ) return -1;
|
||||
|
||||
ChanneledPowerSupplier power = CapabilityUtil.unwrapUnsafe( tile.getCapability( MoreRedAPI.CHANNELED_POWER_CAPABILITY, side ) );
|
||||
if( power == null ) return -1;
|
||||
|
||||
BlockState state = tile.getBlockState();
|
||||
|
||||
// Skip ones already handled by CC. We can do this more efficiently.
|
||||
if( state.getBlock() instanceof IBundledRedstoneBlock ) return -1;
|
||||
|
||||
int mask = 0;
|
||||
for( int i = 0; i < 16; i++ )
|
||||
{
|
||||
mask |= power.getPowerOnChannel( world, pos, state, side, i ) > 0 ? (1 << i) : 0;
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,14 @@ import net.minecraft.item.crafting.SpecialRecipe;
|
||||
import net.minecraft.item.crafting.SpecialRecipeSerializer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class DiskRecipe extends SpecialRecipe
|
||||
{
|
||||
private final Ingredient paper = Ingredient.of( Items.PAPER );
|
||||
private final Ingredient redstone = Ingredient.of( Tags.Items.DUSTS_REDSTONE );
|
||||
private final Ingredient redstone = Ingredient.of( Items.REDSTONE );
|
||||
// TODO: Ingredient.fromTag( Tags.Items.DUSTS_REDSTONE );
|
||||
|
||||
public DiskRecipe( ResourceLocation id )
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.fml.network.NetworkDirection;
|
||||
@@ -21,6 +21,7 @@ import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@@ -47,6 +48,8 @@ public final class NetworkHandler
|
||||
registerMainThread( 2, NetworkDirection.PLAY_TO_SERVER, RequestComputerMessage.class, RequestComputerMessage::new );
|
||||
registerMainThread( 3, NetworkDirection.PLAY_TO_SERVER, KeyEventServerMessage.class, KeyEventServerMessage::new );
|
||||
registerMainThread( 4, NetworkDirection.PLAY_TO_SERVER, MouseEventServerMessage.class, MouseEventServerMessage::new );
|
||||
registerMainThread( 5, NetworkDirection.PLAY_TO_SERVER, UploadFileMessage.class, UploadFileMessage::new );
|
||||
registerMainThread( 6, NetworkDirection.PLAY_TO_SERVER, ContinueUploadMessage.class, ContinueUploadMessage::new );
|
||||
|
||||
// Client messages
|
||||
registerMainThread( 10, NetworkDirection.PLAY_TO_CLIENT, ChatTableClientMessage.class, ChatTableClientMessage::new );
|
||||
@@ -58,6 +61,7 @@ public final class NetworkHandler
|
||||
registerMainThread( 16, NetworkDirection.PLAY_TO_CLIENT, SpeakerPlayClientMessage.class, SpeakerPlayClientMessage::new );
|
||||
registerMainThread( 17, NetworkDirection.PLAY_TO_CLIENT, SpeakerStopClientMessage.class, SpeakerStopClientMessage::new );
|
||||
registerMainThread( 18, NetworkDirection.PLAY_TO_CLIENT, SpeakerMoveClientMessage.class, SpeakerMoveClientMessage::new );
|
||||
registerMainThread( 19, NetworkDirection.PLAY_TO_CLIENT, UploadResultMessage.class, UploadResultMessage::new );
|
||||
}
|
||||
|
||||
public static void sendToPlayer( PlayerEntity player, NetworkMessage packet )
|
||||
@@ -67,7 +71,10 @@ public final class NetworkHandler
|
||||
|
||||
public static void sendToAllPlayers( NetworkMessage packet )
|
||||
{
|
||||
network.send( PacketDistributor.ALL.noArg(), packet );
|
||||
for( ServerPlayerEntity player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() )
|
||||
{
|
||||
sendToPlayer( player, packet );
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendToServer( NetworkMessage packet )
|
||||
@@ -75,9 +82,9 @@ public final class NetworkHandler
|
||||
network.sendToServer( packet );
|
||||
}
|
||||
|
||||
public static void sendToAllAround( NetworkMessage packet, World world, Vec3d pos, double range )
|
||||
public static void sendToAllAround( NetworkMessage packet, World world, Vector3d pos, double range )
|
||||
{
|
||||
PacketDistributor.TargetPoint target = new PacketDistributor.TargetPoint( pos.x, pos.y, pos.z, range, world.getDimension().getType() );
|
||||
PacketDistributor.TargetPoint target = new PacketDistributor.TargetPoint( pos.x, pos.y, pos.z, range, world.dimension() );
|
||||
network.send( PacketDistributor.NEAR.with( () -> target ), packet );
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
@@ -79,7 +80,7 @@ public class PlayRecordClientMessage implements NetworkMessage
|
||||
public void handle( NetworkEvent.Context context )
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
mc.levelRenderer.playStreamingMusic( soundEvent, pos );
|
||||
if( name != null ) mc.gui.setNowPlaying( name );
|
||||
mc.levelRenderer.playRecord( soundEvent, pos, null );
|
||||
if( name != null ) mc.gui.setNowPlaying( new StringTextComponent( name ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ package dan200.computercraft.shared.network.client;
|
||||
import dan200.computercraft.client.SoundManager;
|
||||
import dan200.computercraft.shared.network.NetworkMessage;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
@@ -26,9 +26,9 @@ import java.util.UUID;
|
||||
public class SpeakerMoveClientMessage implements NetworkMessage
|
||||
{
|
||||
private final UUID source;
|
||||
private final Vec3d pos;
|
||||
private final Vector3d pos;
|
||||
|
||||
public SpeakerMoveClientMessage( UUID source, Vec3d pos )
|
||||
public SpeakerMoveClientMessage( UUID source, Vector3d pos )
|
||||
{
|
||||
this.source = source;
|
||||
this.pos = pos;
|
||||
@@ -37,7 +37,7 @@ public class SpeakerMoveClientMessage implements NetworkMessage
|
||||
public SpeakerMoveClientMessage( PacketBuffer buf )
|
||||
{
|
||||
source = buf.readUUID();
|
||||
pos = new Vec3d( buf.readDouble(), buf.readDouble(), buf.readDouble() );
|
||||
pos = new Vector3d( buf.readDouble(), buf.readDouble(), buf.readDouble() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,7 @@ import dan200.computercraft.shared.network.NetworkMessage;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
@@ -29,12 +29,12 @@ import java.util.UUID;
|
||||
public class SpeakerPlayClientMessage implements NetworkMessage
|
||||
{
|
||||
private final UUID source;
|
||||
private final Vec3d pos;
|
||||
private final Vector3d pos;
|
||||
private final ResourceLocation sound;
|
||||
private final float volume;
|
||||
private final float pitch;
|
||||
|
||||
public SpeakerPlayClientMessage( UUID source, Vec3d pos, ResourceLocation event, float volume, float pitch )
|
||||
public SpeakerPlayClientMessage( UUID source, Vector3d pos, ResourceLocation event, float volume, float pitch )
|
||||
{
|
||||
this.source = source;
|
||||
this.pos = pos;
|
||||
@@ -46,7 +46,7 @@ public class SpeakerPlayClientMessage implements NetworkMessage
|
||||
public SpeakerPlayClientMessage( PacketBuffer buf )
|
||||
{
|
||||
source = buf.readUUID();
|
||||
pos = new Vec3d( buf.readDouble(), buf.readDouble(), buf.readDouble() );
|
||||
pos = new Vector3d( buf.readDouble(), buf.readDouble(), buf.readDouble() );
|
||||
sound = buf.readResourceLocation();
|
||||
volume = buf.readFloat();
|
||||
pitch = buf.readFloat();
|
||||
|
||||
@@ -126,7 +126,7 @@ public class TerminalState
|
||||
if( !compress ) return buffer;
|
||||
if( compressed != null ) return compressed;
|
||||
|
||||
ByteBuf compressed = Unpooled.buffer();
|
||||
ByteBuf compressed = Unpooled.directBuffer();
|
||||
OutputStream stream = null;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.network.client;
|
||||
|
||||
import dan200.computercraft.client.gui.ComputerScreenBase;
|
||||
import dan200.computercraft.client.gui.OptionScreen;
|
||||
import dan200.computercraft.shared.computer.upload.UploadResult;
|
||||
import dan200.computercraft.shared.network.NetworkMessage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class UploadResultMessage implements NetworkMessage
|
||||
{
|
||||
public static final UploadResultMessage COMPUTER_OFF = new UploadResultMessage( UploadResult.ERROR, UploadResult.COMPUTER_OFF_MSG );
|
||||
public static final UploadResultMessage OUT_OF_SPACE = new UploadResultMessage( UploadResult.ERROR, UploadResult.OUT_OF_SPACE_MSG );
|
||||
|
||||
private final UploadResult result;
|
||||
private final ITextComponent message;
|
||||
|
||||
public UploadResultMessage( UploadResult result, ITextComponent message )
|
||||
{
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public UploadResultMessage( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
result = buf.readEnum( UploadResult.class );
|
||||
message = buf.readComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
buf.writeEnum( result );
|
||||
buf.writeComponent( message );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle( NetworkEvent.Context context )
|
||||
{
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
|
||||
Screen screen = OptionScreen.unwrap( minecraft.screen );
|
||||
if( screen instanceof ComputerScreenBase<?> )
|
||||
{
|
||||
((ComputerScreenBase<?>) screen).uploadResult( result, message );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package dan200.computercraft.shared.network.server;
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -35,7 +36,7 @@ public class ComputerActionServerMessage extends ComputerServerMessage
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
protected void handle( NetworkEvent.Context context, @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
{
|
||||
switch( action )
|
||||
{
|
||||
|
||||
@@ -49,8 +49,8 @@ public abstract class ComputerServerMessage implements NetworkMessage
|
||||
IContainerComputer container = computer.getContainer( context.getSender() );
|
||||
if( container == null ) return;
|
||||
|
||||
handle( computer, container );
|
||||
handle( context, computer, container );
|
||||
}
|
||||
|
||||
protected abstract void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container );
|
||||
protected abstract void handle( NetworkEvent.Context context, @Nonnull ServerComputer computer, @Nonnull IContainerComputer container );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.network.server;
|
||||
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ContinueUploadMessage extends ComputerServerMessage
|
||||
{
|
||||
private final boolean overwrite;
|
||||
|
||||
public ContinueUploadMessage( int instanceId, boolean overwrite )
|
||||
{
|
||||
super( instanceId );
|
||||
this.overwrite = overwrite;
|
||||
}
|
||||
|
||||
public ContinueUploadMessage( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
super( buf );
|
||||
overwrite = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
super.toBytes( buf );
|
||||
buf.writeBoolean( overwrite );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handle( NetworkEvent.Context context, @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
{
|
||||
ServerPlayerEntity player = context.getSender();
|
||||
if( player != null ) container.continueUpload( player, overwrite );
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.InputState;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -44,7 +45,7 @@ public class KeyEventServerMessage extends ComputerServerMessage
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
protected void handle( NetworkEvent.Context context, @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
{
|
||||
InputState input = container.getInput();
|
||||
if( type == TYPE_UP )
|
||||
|
||||
@@ -9,6 +9,7 @@ import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.InputState;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class MouseEventServerMessage extends ComputerServerMessage
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
protected void handle( NetworkEvent.Context context, @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
{
|
||||
InputState input = container.getInput();
|
||||
switch( type )
|
||||
|
||||
@@ -10,6 +10,7 @@ import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.util.NBTUtil;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -50,7 +51,7 @@ public class QueueEventServerMessage extends ComputerServerMessage
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handle( @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
protected void handle( NetworkEvent.Context context, @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
{
|
||||
computer.queueEvent( event, args );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.network.server;
|
||||
|
||||
import dan200.computercraft.shared.computer.core.IContainerComputer;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputer;
|
||||
import dan200.computercraft.shared.computer.upload.FileUpload;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UploadFileMessage extends ComputerServerMessage
|
||||
{
|
||||
public static final int MAX_SIZE = 30 * 1024; // Max packet size is 32767. TODO: Bump this in the future
|
||||
private final List<FileUpload> files;
|
||||
|
||||
public UploadFileMessage( int instanceId, List<FileUpload> files )
|
||||
{
|
||||
super( instanceId );
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
public UploadFileMessage( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
super( buf );
|
||||
int nFiles = buf.readVarInt();
|
||||
List<FileUpload> files = this.files = new ArrayList<>( nFiles );
|
||||
for( int i = 0; i < nFiles; i++ )
|
||||
{
|
||||
String name = buf.readUtf( 32767 );
|
||||
int size = buf.readVarInt();
|
||||
if( size > MAX_SIZE ) break;
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect( size );
|
||||
buf.readBytes( buffer );
|
||||
buffer.flip();
|
||||
|
||||
files.add( new FileUpload( name, buffer ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes( @Nonnull PacketBuffer buf )
|
||||
{
|
||||
super.toBytes( buf );
|
||||
buf.writeVarInt( files.size() );
|
||||
for( FileUpload file : files )
|
||||
{
|
||||
buf.writeUtf( file.getName() );
|
||||
buf.writeVarInt( file.getBytes().remaining() );
|
||||
buf.writeBytes( file.getBytes() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handle( NetworkEvent.Context context, @Nonnull ServerComputer computer, @Nonnull IContainerComputer container )
|
||||
{
|
||||
ServerPlayerEntity player = context.getSender();
|
||||
if( player != null ) container.upload( player, files );
|
||||
}
|
||||
}
|
||||
@@ -122,9 +122,9 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load( @Nonnull CompoundNBT nbt )
|
||||
public void load( @Nonnull BlockState state, @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.load( nbt );
|
||||
super.load( state, nbt );
|
||||
customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null;
|
||||
if( nbt.contains( NBT_ITEM ) )
|
||||
{
|
||||
@@ -442,7 +442,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
|
||||
private void updateBlockState()
|
||||
{
|
||||
if( remove || level == null ) return;
|
||||
if( remove ) return;
|
||||
|
||||
if( !diskStack.isEmpty() )
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package dan200.computercraft.shared.peripheral.generic.data;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.state.IProperty;
|
||||
import net.minecraft.state.Property;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
@@ -20,9 +20,9 @@ public class BlockData
|
||||
data.put( "name", DataHelpers.getId( state.getBlock() ) );
|
||||
|
||||
Map<Object, Object> stateTable = new HashMap<>();
|
||||
for( Map.Entry<IProperty<?>, ? extends Comparable<?>> entry : state.getValues().entrySet() )
|
||||
for( Map.Entry<Property<?>, ? extends Comparable<?>> entry : state.getValues().entrySet() )
|
||||
{
|
||||
IProperty<?> property = entry.getKey();
|
||||
Property<?> property = entry.getKey();
|
||||
stateTable.put( property.getName(), getPropertyValue( property, entry.getValue() ) );
|
||||
}
|
||||
data.put( "state", stateTable );
|
||||
@@ -32,7 +32,7 @@ public class BlockData
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "unchecked", "rawtypes" } )
|
||||
private static Object getPropertyValue( IProperty property, Comparable value )
|
||||
private static Object getPropertyValue( Property property, Comparable value )
|
||||
{
|
||||
if( value instanceof String || value instanceof Number || value instanceof Boolean ) return value;
|
||||
return property.getName( value );
|
||||
|
||||
@@ -13,7 +13,7 @@ import dan200.computercraft.api.network.IPacketSender;
|
||||
import dan200.computercraft.api.network.Packet;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -171,7 +171,7 @@ public abstract class ModemPeripheral implements IPeripheral, IPacketSender, IPa
|
||||
parseChannel( replyChannel );
|
||||
|
||||
World world = getWorld();
|
||||
Vec3d position = getPosition();
|
||||
Vector3d position = getPosition();
|
||||
IPacketNetwork network = this.network;
|
||||
|
||||
if( world == null || position == null || network == null ) return;
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
@@ -100,7 +100,7 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, IFluidState fluid )
|
||||
public boolean removedByPlayer( BlockState state, World world, BlockPos pos, PlayerEntity player, boolean willHarvest, FluidState fluid )
|
||||
{
|
||||
if( state.getValue( CABLE ) && state.getValue( MODEM ).getFacing() != null )
|
||||
{
|
||||
@@ -180,7 +180,7 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public IFluidState getFluidState( @Nonnull BlockState state )
|
||||
public FluidState getFluidState( @Nonnull BlockState state )
|
||||
{
|
||||
return getWaterloggedFluidState( state );
|
||||
}
|
||||
@@ -207,9 +207,7 @@ public class BlockCable extends BlockGeneric implements IWaterLoggable
|
||||
Direction facing = state.getValue( MODEM ).getFacing();
|
||||
if( facing == null ) return true;
|
||||
|
||||
BlockPos offsetPos = pos.relative( facing );
|
||||
BlockState offsetState = world.getBlockState( offsetPos );
|
||||
return isFaceSturdy( offsetState, world, offsetPos, facing.getOpposite() );
|
||||
return canSupportCenter( world, pos.relative( facing ), facing.getOpposite() );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -28,7 +28,7 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -58,10 +58,10 @@ public class TileCable extends TileGeneric
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
public Vector3d getPosition()
|
||||
{
|
||||
BlockPos pos = getBlockPos();
|
||||
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,10 +103,10 @@ public class TileCable extends TileGeneric
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
public Vector3d getPosition()
|
||||
{
|
||||
BlockPos pos = getBlockPos().relative( modemDirection );
|
||||
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -281,9 +281,9 @@ public class TileCable extends TileGeneric
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load( @Nonnull CompoundNBT nbt )
|
||||
public void load( @Nonnull BlockState state, @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.load( nbt );
|
||||
super.load( state, nbt );
|
||||
peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
|
||||
peripheral.read( nbt, "" );
|
||||
}
|
||||
@@ -422,12 +422,6 @@ public class TileCable extends TileGeneric
|
||||
node.updatePeripherals( peripherals );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderBreaking()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> capability, @Nullable Direction side )
|
||||
|
||||
@@ -26,7 +26,7 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
@@ -85,10 +85,10 @@ public class TileWiredModemFull extends TileGeneric
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
public Vector3d getPosition()
|
||||
{
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,9 +225,9 @@ public class TileWiredModemFull extends TileGeneric
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load( @Nonnull CompoundNBT nbt )
|
||||
public void load( @Nonnull BlockState state, @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.load( nbt );
|
||||
super.load( state, nbt );
|
||||
peripheralAccessAllowed = nbt.getBoolean( NBT_PERIPHERAL_ENABLED );
|
||||
for( int i = 0; i < peripherals.length; i++ ) peripherals[i].read( nbt, Integer.toString( i ) );
|
||||
}
|
||||
@@ -399,10 +399,10 @@ public class TileWiredModemFull extends TileGeneric
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
public Vector3d getPosition()
|
||||
{
|
||||
BlockPos pos = getBlockPos().relative( side );
|
||||
return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
return new Vector3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -10,7 +10,7 @@ import dan200.computercraft.shared.peripheral.modem.ModemShapes;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.IWaterLoggable;
|
||||
import net.minecraft.fluid.IFluidState;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.DirectionProperty;
|
||||
@@ -62,7 +62,7 @@ public class BlockWirelessModem extends BlockGeneric implements IWaterLoggable
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public IFluidState getFluidState( @Nonnull BlockState state )
|
||||
public FluidState getFluidState( @Nonnull BlockState state )
|
||||
{
|
||||
return getWaterloggedFluidState( state );
|
||||
}
|
||||
@@ -80,12 +80,10 @@ public class BlockWirelessModem extends BlockGeneric implements IWaterLoggable
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean canSurvive( BlockState state, IWorldReader world, BlockPos pos )
|
||||
public boolean canSurvive( BlockState state, @Nonnull IWorldReader world, BlockPos pos )
|
||||
{
|
||||
Direction facing = state.getValue( FACING );
|
||||
BlockPos offsetPos = pos.relative( facing );
|
||||
BlockState offsetState = world.getBlockState( offsetPos );
|
||||
return isFaceSturdy( offsetState, world, offsetPos, facing.getOpposite() );
|
||||
return canSupportCenter( world, pos.relative( facing ), facing.getOpposite() );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
@@ -46,10 +46,10 @@ public class TileWirelessModem extends TileGeneric
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
public Vector3d getPosition()
|
||||
{
|
||||
BlockPos pos = entity.getBlockPos().relative( entity.modemDirection );
|
||||
return new Vec3d( pos.getX(), pos.getY(), pos.getZ() );
|
||||
return new Vector3d( pos.getX(), pos.getY(), pos.getZ() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.network.IPacketNetwork;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.modem.ModemState;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class WirelessModemPeripheral extends ModemPeripheral
|
||||
@@ -40,7 +40,7 @@ public abstract class WirelessModemPeripheral extends ModemPeripheral
|
||||
World world = getWorld();
|
||||
if( world != null )
|
||||
{
|
||||
Vec3d position = getPosition();
|
||||
Vector3d position = getPosition();
|
||||
double minRange = ComputerCraft.modemRange;
|
||||
double maxRange = ComputerCraft.modemHighAltitudeRange;
|
||||
if( world.isRaining() && world.isThundering() )
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.peripheral.monitor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
final class MonitorState
|
||||
{
|
||||
public static final MonitorState UNLOADED = new MonitorState( State.UNLOADED, null );
|
||||
public static final MonitorState MISSING = new MonitorState( State.MISSING, null );
|
||||
|
||||
private final State state;
|
||||
private final TileMonitor monitor;
|
||||
|
||||
private MonitorState( @Nonnull State state, @Nullable TileMonitor monitor )
|
||||
{
|
||||
this.state = state;
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
public static MonitorState present( @Nonnull TileMonitor monitor )
|
||||
{
|
||||
return new MonitorState( State.PRESENT, monitor );
|
||||
}
|
||||
|
||||
public boolean isPresent()
|
||||
{
|
||||
return state == State.PRESENT;
|
||||
}
|
||||
|
||||
public boolean isMissing()
|
||||
{
|
||||
return state == State.MISSING;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TileMonitor getMonitor()
|
||||
{
|
||||
return monitor;
|
||||
}
|
||||
|
||||
enum State
|
||||
{
|
||||
UNLOADED,
|
||||
MISSING,
|
||||
PRESENT,
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,6 @@ public class TileMonitor extends TileGeneric
|
||||
private final Set<IComputerAccess> computers = new HashSet<>();
|
||||
|
||||
private boolean needsUpdate = false;
|
||||
private boolean needsValidating = false;
|
||||
private boolean destroyed = false;
|
||||
private boolean visiting = false;
|
||||
|
||||
@@ -79,7 +78,6 @@ public class TileMonitor extends TileGeneric
|
||||
public void onLoad()
|
||||
{
|
||||
super.onLoad();
|
||||
needsValidating = true;
|
||||
TickScheduler.schedule( this );
|
||||
}
|
||||
|
||||
@@ -138,24 +136,19 @@ public class TileMonitor extends TileGeneric
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load( @Nonnull CompoundNBT tag )
|
||||
public void load( @Nonnull BlockState state, @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.load( tag );
|
||||
xIndex = tag.getInt( NBT_X );
|
||||
yIndex = tag.getInt( NBT_Y );
|
||||
width = tag.getInt( NBT_WIDTH );
|
||||
height = tag.getInt( NBT_HEIGHT );
|
||||
super.load( state, nbt );
|
||||
|
||||
xIndex = nbt.getInt( NBT_X );
|
||||
yIndex = nbt.getInt( NBT_Y );
|
||||
width = nbt.getInt( NBT_WIDTH );
|
||||
height = nbt.getInt( NBT_HEIGHT );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blockTick()
|
||||
{
|
||||
if( needsValidating )
|
||||
{
|
||||
needsValidating = false;
|
||||
validate();
|
||||
}
|
||||
|
||||
if( needsUpdate )
|
||||
{
|
||||
needsUpdate = false;
|
||||
@@ -172,7 +165,7 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
for( int y = 0; y < height; y++ )
|
||||
{
|
||||
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
||||
TileMonitor monitor = getNeighbour( x, y );
|
||||
if( monitor == null ) continue;
|
||||
|
||||
for( IComputerAccess computer : monitor.computers )
|
||||
@@ -216,7 +209,7 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
if( serverMonitor != null ) return serverMonitor;
|
||||
|
||||
TileMonitor origin = getOrigin().getMonitor();
|
||||
TileMonitor origin = getOrigin();
|
||||
if( origin == null ) return null;
|
||||
|
||||
return serverMonitor = origin.serverMonitor;
|
||||
@@ -237,7 +230,7 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
for( int y = 0; y < height; y++ )
|
||||
{
|
||||
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
||||
TileMonitor monitor = getNeighbour( x, y );
|
||||
if( monitor != null ) monitor.serverMonitor = serverMonitor;
|
||||
}
|
||||
}
|
||||
@@ -382,24 +375,24 @@ public class TileMonitor extends TileGeneric
|
||||
return yIndex;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private MonitorState getSimilarMonitorAt( BlockPos pos )
|
||||
private TileMonitor getSimilarMonitorAt( BlockPos pos )
|
||||
{
|
||||
if( pos.equals( getBlockPos() ) ) return MonitorState.present( this );
|
||||
if( pos.equals( getBlockPos() ) ) return this;
|
||||
|
||||
int y = pos.getY();
|
||||
World world = getLevel();
|
||||
if( world == null || !world.isAreaLoaded( pos, 0 ) ) return MonitorState.UNLOADED;
|
||||
if( world == null || !world.isAreaLoaded( pos, 0 ) ) return null;
|
||||
|
||||
TileEntity tile = world.getBlockEntity( pos );
|
||||
if( !(tile instanceof TileMonitor) ) return MonitorState.MISSING;
|
||||
if( !(tile instanceof TileMonitor) ) return null;
|
||||
|
||||
TileMonitor monitor = (TileMonitor) tile;
|
||||
return !monitor.visiting && !monitor.destroyed && advanced == monitor.advanced
|
||||
&& getDirection() == monitor.getDirection() && getOrientation() == monitor.getOrientation()
|
||||
? MonitorState.present( monitor ) : MonitorState.MISSING;
|
||||
? monitor : null;
|
||||
}
|
||||
|
||||
private MonitorState getNeighbour( int x, int y )
|
||||
private TileMonitor getNeighbour( int x, int y )
|
||||
{
|
||||
BlockPos pos = getBlockPos();
|
||||
Direction right = getRight();
|
||||
@@ -409,7 +402,7 @@ public class TileMonitor extends TileGeneric
|
||||
return getSimilarMonitorAt( pos.relative( right, xOffset ).relative( down, yOffset ) );
|
||||
}
|
||||
|
||||
private MonitorState getOrigin()
|
||||
private TileMonitor getOrigin()
|
||||
{
|
||||
return getNeighbour( 0, 0 );
|
||||
}
|
||||
@@ -433,7 +426,7 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
for( int y = 0; y < height; y++ )
|
||||
{
|
||||
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
||||
TileMonitor monitor = getNeighbour( x, y );
|
||||
if( monitor != null && monitor.peripheral != null )
|
||||
{
|
||||
needsTerminal = true;
|
||||
@@ -461,7 +454,7 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
for( int y = 0; y < height; y++ )
|
||||
{
|
||||
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
||||
TileMonitor monitor = getNeighbour( x, y );
|
||||
if( monitor == null ) continue;
|
||||
|
||||
monitor.xIndex = x;
|
||||
@@ -477,13 +470,13 @@ public class TileMonitor extends TileGeneric
|
||||
|
||||
private boolean mergeLeft()
|
||||
{
|
||||
TileMonitor left = getNeighbour( -1, 0 ).getMonitor();
|
||||
TileMonitor left = getNeighbour( -1, 0 );
|
||||
if( left == null || left.yIndex != 0 || left.height != height ) return false;
|
||||
|
||||
int width = left.width + this.width;
|
||||
if( width > ComputerCraft.monitorWidth ) return false;
|
||||
|
||||
TileMonitor origin = left.getOrigin().getMonitor();
|
||||
TileMonitor origin = left.getOrigin();
|
||||
if( origin != null ) origin.resize( width, height );
|
||||
left.expand();
|
||||
return true;
|
||||
@@ -491,13 +484,13 @@ public class TileMonitor extends TileGeneric
|
||||
|
||||
private boolean mergeRight()
|
||||
{
|
||||
TileMonitor right = getNeighbour( width, 0 ).getMonitor();
|
||||
TileMonitor right = getNeighbour( width, 0 );
|
||||
if( right == null || right.yIndex != 0 || right.height != height ) return false;
|
||||
|
||||
int width = this.width + right.width;
|
||||
if( width > ComputerCraft.monitorWidth ) return false;
|
||||
|
||||
TileMonitor origin = getOrigin().getMonitor();
|
||||
TileMonitor origin = getOrigin();
|
||||
if( origin != null ) origin.resize( width, height );
|
||||
expand();
|
||||
return true;
|
||||
@@ -505,13 +498,13 @@ public class TileMonitor extends TileGeneric
|
||||
|
||||
private boolean mergeUp()
|
||||
{
|
||||
TileMonitor above = getNeighbour( 0, height ).getMonitor();
|
||||
TileMonitor above = getNeighbour( 0, height );
|
||||
if( above == null || above.xIndex != 0 || above.width != width ) return false;
|
||||
|
||||
int height = above.height + this.height;
|
||||
if( height > ComputerCraft.monitorHeight ) return false;
|
||||
|
||||
TileMonitor origin = getOrigin().getMonitor();
|
||||
TileMonitor origin = getOrigin();
|
||||
if( origin != null ) origin.resize( width, height );
|
||||
expand();
|
||||
return true;
|
||||
@@ -519,13 +512,13 @@ public class TileMonitor extends TileGeneric
|
||||
|
||||
private boolean mergeDown()
|
||||
{
|
||||
TileMonitor below = getNeighbour( 0, -1 ).getMonitor();
|
||||
TileMonitor below = getNeighbour( 0, -1 );
|
||||
if( below == null || below.xIndex != 0 || below.width != width ) return false;
|
||||
|
||||
int height = this.height + below.height;
|
||||
if( height > ComputerCraft.monitorHeight ) return false;
|
||||
|
||||
TileMonitor origin = below.getOrigin().getMonitor();
|
||||
TileMonitor origin = below.getOrigin();
|
||||
if( origin != null ) origin.resize( width, height );
|
||||
below.expand();
|
||||
return true;
|
||||
@@ -554,22 +547,22 @@ public class TileMonitor extends TileGeneric
|
||||
visiting = true;
|
||||
if( xIndex > 0 )
|
||||
{
|
||||
TileMonitor left = getNeighbour( xIndex - 1, yIndex ).getMonitor();
|
||||
TileMonitor left = getNeighbour( xIndex - 1, yIndex );
|
||||
if( left != null ) left.contract();
|
||||
}
|
||||
if( xIndex + 1 < width )
|
||||
{
|
||||
TileMonitor right = getNeighbour( xIndex + 1, yIndex ).getMonitor();
|
||||
TileMonitor right = getNeighbour( xIndex + 1, yIndex );
|
||||
if( right != null ) right.contract();
|
||||
}
|
||||
if( yIndex > 0 )
|
||||
{
|
||||
TileMonitor below = getNeighbour( xIndex, yIndex - 1 ).getMonitor();
|
||||
TileMonitor below = getNeighbour( xIndex, yIndex - 1 );
|
||||
if( below != null ) below.contract();
|
||||
}
|
||||
if( yIndex + 1 < height )
|
||||
{
|
||||
TileMonitor above = getNeighbour( xIndex, yIndex + 1 ).getMonitor();
|
||||
TileMonitor above = getNeighbour( xIndex, yIndex + 1 );
|
||||
if( above != null ) above.contract();
|
||||
}
|
||||
visiting = false;
|
||||
@@ -580,11 +573,11 @@ public class TileMonitor extends TileGeneric
|
||||
int height = this.height;
|
||||
int width = this.width;
|
||||
|
||||
TileMonitor origin = getOrigin().getMonitor();
|
||||
TileMonitor origin = getOrigin();
|
||||
if( origin == null )
|
||||
{
|
||||
TileMonitor right = width > 1 ? getNeighbour( 1, 0 ).getMonitor() : null;
|
||||
TileMonitor below = height > 1 ? getNeighbour( 0, 1 ).getMonitor() : null;
|
||||
TileMonitor right = width > 1 ? getNeighbour( 1, 0 ) : null;
|
||||
TileMonitor below = height > 1 ? getNeighbour( 0, 1 ) : null;
|
||||
|
||||
if( right != null ) right.resize( width - 1, 1 );
|
||||
if( below != null ) below.resize( width, height - 1 );
|
||||
@@ -598,7 +591,7 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
for( int x = 0; x < width; x++ )
|
||||
{
|
||||
TileMonitor monitor = origin.getNeighbour( x, y ).getMonitor();
|
||||
TileMonitor monitor = origin.getNeighbour( x, y );
|
||||
if( monitor != null ) continue;
|
||||
|
||||
// Decompose
|
||||
@@ -614,17 +607,17 @@ public class TileMonitor extends TileGeneric
|
||||
}
|
||||
if( x > 0 )
|
||||
{
|
||||
left = origin.getNeighbour( 0, y ).getMonitor();
|
||||
left = origin.getNeighbour( 0, y );
|
||||
left.resize( x, 1 );
|
||||
}
|
||||
if( x + 1 < width )
|
||||
{
|
||||
right = origin.getNeighbour( x + 1, y ).getMonitor();
|
||||
right = origin.getNeighbour( x + 1, y );
|
||||
right.resize( width - (x + 1), 1 );
|
||||
}
|
||||
if( y + 1 < height )
|
||||
{
|
||||
below = origin.getNeighbour( 0, y + 1 ).getMonitor();
|
||||
below = origin.getNeighbour( 0, y + 1 );
|
||||
below.resize( width, height - (y + 1) );
|
||||
}
|
||||
|
||||
@@ -638,38 +631,6 @@ public class TileMonitor extends TileGeneric
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkMonitorAt( int xIndex, int yIndex )
|
||||
{
|
||||
BlockPos pos = getBlockPos();
|
||||
Direction right = getRight();
|
||||
Direction down = getDown();
|
||||
|
||||
MonitorState state = getSimilarMonitorAt( pos.relative( right, xIndex ).relative( down, yIndex ) );
|
||||
|
||||
if( state.isMissing() ) return false;
|
||||
|
||||
TileMonitor monitor = state.getMonitor();
|
||||
if( monitor == null ) return true;
|
||||
|
||||
return monitor.xIndex == xIndex && monitor.yIndex == yIndex && monitor.width == width && monitor.height == height;
|
||||
}
|
||||
|
||||
private void validate()
|
||||
{
|
||||
if( xIndex == 0 && yIndex == 0 && width == 1 || height == 1 ) return;
|
||||
|
||||
if( checkMonitorAt( 0, 0 ) && checkMonitorAt( 0, height - 1 ) &&
|
||||
checkMonitorAt( width - 1, 0 ) && checkMonitorAt( width - 1, height - 1 ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Something in our monitor is invalid. For now, let's just reset ourselves and then try to integrate ourselves
|
||||
// later.
|
||||
resize( 1, 1 );
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
private void monitorTouched( float xPos, float yPos, float zPos )
|
||||
{
|
||||
XYPair pair = XYPair
|
||||
@@ -697,7 +658,7 @@ public class TileMonitor extends TileGeneric
|
||||
{
|
||||
for( int x = 0; x < width; x++ )
|
||||
{
|
||||
TileMonitor monitor = getNeighbour( x, y ).getMonitor();
|
||||
TileMonitor monitor = getNeighbour( x, y );
|
||||
if( monitor == null ) continue;
|
||||
|
||||
for( IComputerAccess computer : monitor.computers )
|
||||
@@ -723,8 +684,8 @@ public class TileMonitor extends TileGeneric
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
TileMonitor start = getNeighbour( 0, 0 ).getMonitor();
|
||||
TileMonitor end = getNeighbour( width - 1, height - 1 ).getMonitor();
|
||||
TileMonitor start = getNeighbour( 0, 0 );
|
||||
TileMonitor end = getNeighbour( width - 1, height - 1 );
|
||||
if( start != null && end != null )
|
||||
{
|
||||
BlockPos startPos = start.getBlockPos();
|
||||
|
||||
@@ -25,7 +25,7 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -94,9 +94,9 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load( @Nonnull CompoundNBT nbt )
|
||||
public void load( @Nonnull BlockState state, @Nonnull CompoundNBT nbt )
|
||||
{
|
||||
super.load( nbt );
|
||||
super.load( state, nbt );
|
||||
|
||||
customName = nbt.contains( NBT_NAME ) ? ITextComponent.Serializer.fromJson( nbt.getString( NBT_NAME ) ) : null;
|
||||
|
||||
@@ -406,7 +406,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
setItem( i, ItemStack.EMPTY );
|
||||
|
||||
// Spawn the item in the world
|
||||
WorldUtil.dropItemStack( stack, getLevel(), new Vec3d( getBlockPos() ).add( 0.5, 0.75, 0.5 ) );
|
||||
WorldUtil.dropItemStack( stack, getLevel(), Vector3d.atLowerCornerOf( getBlockPos() ).add( 0.5, 0.75, 0.5 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,7 +438,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
|
||||
private void updateBlockState( boolean top, boolean bottom )
|
||||
{
|
||||
if( remove || level == null ) return;
|
||||
if( remove ) return;
|
||||
|
||||
BlockState state = getBlockState();
|
||||
if( state.getValue( BlockPrinter.TOP ) == top & state.getValue( BlockPrinter.BOTTOM ) == bottom ) return;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user