Various Java 17 usages, renamed some things to match official mappings (world -> level, tile entity -> block entity).
This commit is contained in:
@@ -10,9 +10,9 @@ For documentation on how the to get computers up and running, and how to use the
|
||||
|
||||
[OpenComputers]: https://github.com/MightyPirates/OpenComputers
|
||||
[RPC Device]: src/main/java/li/cil/oc2/api/bus/device/rpc/RPCDevice.java
|
||||
[redstone interface]: src/main/java/li/cil/oc2/common/tileentity/RedstoneInterfaceTileEntity.java
|
||||
[redstone interface]: src/main/java/li/cil/oc2/common/blockentity/RedstoneInterfaceBlockEntity.java
|
||||
[sound card]: src/main/java/li/cil/oc2/common/bus/device/item/SoundCardItemDevice.java
|
||||
[VM Device]: src/main/java/li/cil/oc2/api/bus/device/vm/VMDevice.java
|
||||
[disk drive]: src/main/java/li/cil/oc2/common/tileentity/DiskDriveTileEntity.java
|
||||
[disk drive]: src/main/java/li/cil/oc2/common/blockentity/DiskDriveBlockEntity.java
|
||||
[network card]: src/main/java/li/cil/oc2/common/bus/device/item/NetworkInterfaceCardItemDevice.java
|
||||
[documentation]: src/main/resources/assets/oc2/doc/en_us/index.md
|
||||
[documentation]: src/main/resources/assets/oc2/doc/en_us/index.md
|
||||
|
||||
@@ -3,6 +3,8 @@ package li.cil.oc2.api.bus;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Implementing this interface allows providing positional information to the {@link DeviceBusController}.
|
||||
* <p>
|
||||
@@ -12,10 +14,11 @@ import net.minecraft.world.level.LevelAccessor;
|
||||
*/
|
||||
public interface BlockDeviceBusElement extends DeviceBusElement {
|
||||
/**
|
||||
* The world the bus lives in.
|
||||
* The level the bus lives in.
|
||||
*
|
||||
* @return the world the bus lives in.
|
||||
* @return the level the bus lives in.
|
||||
*/
|
||||
@Nullable
|
||||
LevelAccessor getLevel();
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,8 +27,8 @@ public @interface Callback {
|
||||
* the caller as each call will take at least one tick (50ms).
|
||||
* <p>
|
||||
* Use this when the targeted method interacts with data that is not thread
|
||||
* safe, for example the world or any objects inside the world, such as
|
||||
* tile entities and entities.
|
||||
* safe, for example the level or any objects inside the level, such as
|
||||
* entities and block entities.
|
||||
*
|
||||
* @return {@code true} when to be executed on main thread; {@code false} otherwise.
|
||||
*/
|
||||
|
||||
@@ -91,8 +91,8 @@ public final class Callbacks {
|
||||
private static List<Method> getMethods(final Class<?> type) {
|
||||
synchronized (METHOD_BY_TYPE) {
|
||||
return METHOD_BY_TYPE.computeIfAbsent(type, c -> Arrays.stream(c.getMethods())
|
||||
.filter(m -> m.isAnnotationPresent(Callback.class))
|
||||
.collect(Collectors.toList()));
|
||||
.filter(m -> m.isAnnotationPresent(Callback.class))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,9 +195,9 @@ public final class Callbacks {
|
||||
this.returnValueDescription = documentation.returnValueDescription;
|
||||
|
||||
this.parameters = PARAMETERS_BY_METHOD.computeIfAbsent(method,
|
||||
m -> Arrays.stream(m.getParameters())
|
||||
.map(parameter -> new ReflectionParameter(parameter, documentation.parameterDescriptions))
|
||||
.toArray(RPCParameter[]::new));
|
||||
m -> Arrays.stream(m.getParameters())
|
||||
.map(parameter -> new ReflectionParameter(parameter, documentation.parameterDescriptions))
|
||||
.toArray(RPCParameter[]::new));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,17 +241,9 @@ public final class Callbacks {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CallbackDocumentation {
|
||||
@Nullable public final String description;
|
||||
@Nullable public final String returnValueDescription;
|
||||
public final HashMap<String, String> parameterDescriptions;
|
||||
|
||||
private CallbackDocumentation(@Nullable final String description, @Nullable final String returnValueDescription, final HashMap<String, String> parameterDescriptions) {
|
||||
this.description = description;
|
||||
this.returnValueDescription = returnValueDescription;
|
||||
this.parameterDescriptions = parameterDescriptions;
|
||||
}
|
||||
}
|
||||
private record CallbackDocumentation(@Nullable String description,
|
||||
@Nullable String returnValueDescription,
|
||||
HashMap<String, String> parameterDescriptions) { }
|
||||
|
||||
private static final class DeviceVisitorImpl implements DocumentedDevice.DeviceVisitor {
|
||||
public final HashMap<String, CallbackVisitorImpl> callbacks = new HashMap<>();
|
||||
|
||||
@@ -37,8 +37,7 @@ public final class ObjectDevice implements RPCDevice {
|
||||
this.methods = Callbacks.collectMethods(object);
|
||||
this.className = object.getClass().getSimpleName();
|
||||
|
||||
if (object instanceof NamedDevice) {
|
||||
final NamedDevice namedDevice = (NamedDevice) object;
|
||||
if (object instanceof final NamedDevice namedDevice) {
|
||||
this.typeNames.addAll(namedDevice.getDeviceTypeNames());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package li.cil.oc2.api.bus.device.provider;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -13,9 +14,9 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public interface BlockDeviceQuery {
|
||||
/**
|
||||
* The world containing the block this query is performed for.
|
||||
* The level containing the block this query is performed for.
|
||||
*
|
||||
* @return the world containing the block.
|
||||
* @return the level containing the block.
|
||||
*/
|
||||
Level getLevel();
|
||||
|
||||
@@ -29,7 +30,7 @@ public interface BlockDeviceQuery {
|
||||
/**
|
||||
* The side of the block this query is performed on, if any.
|
||||
* <p>
|
||||
* May be {@code null} just as when requesting a capability from a tile entity.
|
||||
* May be {@code null} just as when requesting a capability from a {@link BlockEntity}.
|
||||
*
|
||||
* @return the side of the block.
|
||||
*/
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface ItemDeviceQuery {
|
||||
*
|
||||
* @return the {@link BlockEntity} hosting the device, if any.
|
||||
*/
|
||||
Optional<BlockEntity> getContainerTileEntity();
|
||||
Optional<BlockEntity> getContainerBlockEntity();
|
||||
|
||||
/**
|
||||
* The {@link Entity} that holds the item this query is for.
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface RPCDevice extends Device {
|
||||
/**
|
||||
* Called when the device is suspended.
|
||||
* <p>
|
||||
* This can happen when the world area containing the context the device was loaded in is unloaded,
|
||||
* This can happen when the level area containing the context the device was loaded in is unloaded,
|
||||
* e.g. due to player moving too far away from the area.
|
||||
* <p>
|
||||
* Intended for soft-releasing unmanaged resource, i.e. non-persisted unmanaged resources.
|
||||
|
||||
@@ -6,5 +6,4 @@ package li.cil.oc2.api.bus.device.vm;
|
||||
* It is used exclusively to check if some firmware will be loaded early in the
|
||||
* startup process, to provide a useful error to the user if none is present.
|
||||
*/
|
||||
public interface FirmwareLoader extends VMDevice {
|
||||
}
|
||||
public interface FirmwareLoader extends VMDevice { }
|
||||
|
||||
@@ -50,7 +50,7 @@ public interface VMDevice extends Device {
|
||||
/**
|
||||
* Called when the device is suspended.
|
||||
* <p>
|
||||
* This can happen when the world area containing the context the device was loaded in is unloaded,
|
||||
* This can happen when the level area containing the context the device was loaded in is unloaded,
|
||||
* e.g. due to player moving too far away from the area.
|
||||
* <p>
|
||||
* Intended for soft-releasing resources acquired in {@link #mount(VMContext)}, i.e. non-persisted
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package li.cil.oc2.api.bus.device.vm.context;
|
||||
|
||||
/**
|
||||
* Allows registering for {@link li.cil.oc2.api.bus.device.vm.event.VMLifecycleEvent}s.
|
||||
* Allows registering for VM lifecycle events.
|
||||
* @see li.cil.oc2.api.bus.device.vm.event.VMInitializingEvent
|
||||
* @see li.cil.oc2.api.bus.device.vm.event.VMResumingRunningEvent
|
||||
* @see li.cil.oc2.api.bus.device.vm.event.VMResumedRunningEvent
|
||||
* @see li.cil.oc2.api.bus.device.vm.event.VMPausingEvent
|
||||
*/
|
||||
public interface VMLifecycleEventBus {
|
||||
/**
|
||||
|
||||
@@ -19,26 +19,4 @@ import li.cil.oc2.api.bus.device.vm.context.VMContext;
|
||||
* <p>
|
||||
* <em>This is invoked from the worker thread running the VM.</em>
|
||||
*/
|
||||
public final class VMInitializingEvent {
|
||||
private final long programStartAddress;
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
public VMInitializingEvent(final long programStartAddress) {
|
||||
this.programStartAddress = programStartAddress;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* The address where code execution will begin.
|
||||
* <p>
|
||||
* Some VM implementations may perform some early setup before jumping to this
|
||||
* memory address.
|
||||
*
|
||||
* @return the memory address where code execution begins.
|
||||
*/
|
||||
public long getProgramStartAddress() {
|
||||
return programStartAddress;
|
||||
}
|
||||
}
|
||||
public record VMInitializingEvent(long programStartAddress) { }
|
||||
|
||||
@@ -8,5 +8,4 @@ package li.cil.oc2.api.bus.device.vm.event;
|
||||
* if such interactions may modify VM state, to prevent corrupting data being
|
||||
* serialized asynchronously.
|
||||
*/
|
||||
public final class VMPausingEvent {
|
||||
}
|
||||
public final class VMPausingEvent { }
|
||||
|
||||
@@ -7,8 +7,7 @@ package li.cil.oc2.api.bus.device.vm.event;
|
||||
* <p>
|
||||
* Allows device initialization that relies on all other devices having fully loaded.
|
||||
* <p>
|
||||
* Typically this is used in combination with {@link VMPausingEvent}, to re-enable external
|
||||
* Typically, this is used in combination with {@link VMPausingEvent}, to re-enable external
|
||||
* interactions after VM state is guaranteed to be safe to modify again.
|
||||
*/
|
||||
public final class VMResumedRunningEvent {
|
||||
}
|
||||
public final class VMResumedRunningEvent { }
|
||||
|
||||
@@ -12,5 +12,4 @@ import li.cil.oc2.api.bus.device.vm.context.VMContext;
|
||||
* from a saved state as well as when continuing to run after being paused for
|
||||
* a save. It is intended for awaiting asynchronous load and store operations.
|
||||
*/
|
||||
public final class VMResumingRunningEvent {
|
||||
}
|
||||
public final class VMResumingRunningEvent { }
|
||||
|
||||
@@ -2,7 +2,7 @@ package li.cil.oc2.api.capabilities;
|
||||
|
||||
/**
|
||||
* This interface may be provided as a capability by item components to signal
|
||||
* to the containing {@link net.minecraft.tileentity.TileEntity} that they wish
|
||||
* to the containing {@link net.minecraft.world.level.block.entity.BlockEntity} that they wish
|
||||
* to emit a redstone signal. This is used by the built-in redstone interface
|
||||
* card, for example.
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,6 @@ package li.cil.oc2.api.imc;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCDevice;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@@ -15,39 +14,4 @@ import java.lang.reflect.Type;
|
||||
* used for serialization/deserialization of parameters, i.e. the specified
|
||||
* {@link #typeAdapter}s should be valid for passing to {@link GsonBuilder#registerTypeAdapter(Type, Object)}.
|
||||
*/
|
||||
public final class RPCMethodParameterTypeAdapter {
|
||||
private final Class<?> type;
|
||||
private final Object typeAdapter;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Creates a new definition of a type adapter that can be called in the
|
||||
* {@link API#IMC_ADD_RPC_METHOD_PARAMETER_TYPE_ADAPTER} IMC message.
|
||||
*
|
||||
* @param type the type the adapter is registered for.
|
||||
* @param typeAdapter the adapter to use for the specified type.
|
||||
*/
|
||||
public RPCMethodParameterTypeAdapter(final Class<?> type, final Object typeAdapter) {
|
||||
this.type = type;
|
||||
this.typeAdapter = typeAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type the adapter is to be registered for.
|
||||
*
|
||||
* @return the serialized type.
|
||||
*/
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type adapter to use for the type.
|
||||
*
|
||||
* @return the type adapter.
|
||||
*/
|
||||
public Object getTypeAdapter() {
|
||||
return typeAdapter;
|
||||
}
|
||||
}
|
||||
public record RPCMethodParameterTypeAdapter(Class<?> type, Object typeAdapter) { }
|
||||
|
||||
@@ -11,17 +11,17 @@ import li.cil.oc2.client.model.BusCableModelLoader;
|
||||
import li.cil.oc2.client.renderer.BusInterfaceNameRenderer;
|
||||
import li.cil.oc2.client.renderer.NetworkCableRenderer;
|
||||
import li.cil.oc2.client.renderer.color.BusCableBlockColor;
|
||||
import li.cil.oc2.client.renderer.entity.RobotEntityRenderer;
|
||||
import li.cil.oc2.client.renderer.entity.RobotRenderer;
|
||||
import li.cil.oc2.client.renderer.entity.model.RobotModel;
|
||||
import li.cil.oc2.client.renderer.tileentity.ChargerTileEntityRenderer;
|
||||
import li.cil.oc2.client.renderer.tileentity.ComputerTileEntityRenderer;
|
||||
import li.cil.oc2.client.renderer.tileentity.DiskDriveTileEntityRenderer;
|
||||
import li.cil.oc2.client.renderer.tileentity.NetworkConnectorTileEntityRenderer;
|
||||
import li.cil.oc2.client.renderer.blockentity.ChargerRenderer;
|
||||
import li.cil.oc2.client.renderer.blockentity.ComputerRenderer;
|
||||
import li.cil.oc2.client.renderer.blockentity.DiskDriveRenderer;
|
||||
import li.cil.oc2.client.renderer.blockentity.NetworkConnectorRenderer;
|
||||
import li.cil.oc2.common.block.Blocks;
|
||||
import li.cil.oc2.common.bus.device.DeviceTypes;
|
||||
import li.cil.oc2.common.container.Containers;
|
||||
import li.cil.oc2.common.entity.Entities;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
@@ -42,10 +42,10 @@ public final class ClientSetup {
|
||||
NetworkCableRenderer.initialize();
|
||||
BusInterfaceNameRenderer.initialize();
|
||||
|
||||
BlockEntityRenderers.register(TileEntities.COMPUTER_TILE_ENTITY.get(), ComputerTileEntityRenderer::new);
|
||||
BlockEntityRenderers.register(TileEntities.NETWORK_CONNECTOR_TILE_ENTITY.get(), NetworkConnectorTileEntityRenderer::new);
|
||||
BlockEntityRenderers.register(TileEntities.DISK_DRIVE_TILE_ENTITY.get(), DiskDriveTileEntityRenderer::new);
|
||||
BlockEntityRenderers.register(TileEntities.CHARGER_TILE_ENTITY.get(), ChargerTileEntityRenderer::new);
|
||||
BlockEntityRenderers.register(BlockEntities.COMPUTER.get(), ComputerRenderer::new);
|
||||
BlockEntityRenderers.register(BlockEntities.NETWORK_CONNECTOR.get(), NetworkConnectorRenderer::new);
|
||||
BlockEntityRenderers.register(BlockEntities.DISK_DRIVE.get(), DiskDriveRenderer::new);
|
||||
BlockEntityRenderers.register(BlockEntities.CHARGER.get(), ChargerRenderer::new);
|
||||
|
||||
event.enqueueWork(() -> {
|
||||
CustomItemModelProperties.initialize();
|
||||
@@ -76,16 +76,16 @@ public final class ClientSetup {
|
||||
event.addSprite(deviceType.getBackgroundIcon());
|
||||
}
|
||||
|
||||
event.addSprite(ComputerTileEntityRenderer.OVERLAY_POWER_LOCATION);
|
||||
event.addSprite(ComputerTileEntityRenderer.OVERLAY_STATUS_LOCATION);
|
||||
event.addSprite(ComputerTileEntityRenderer.OVERLAY_TERMINAL_LOCATION);
|
||||
event.addSprite(ComputerRenderer.OVERLAY_POWER_LOCATION);
|
||||
event.addSprite(ComputerRenderer.OVERLAY_STATUS_LOCATION);
|
||||
event.addSprite(ComputerRenderer.OVERLAY_TERMINAL_LOCATION);
|
||||
|
||||
event.addSprite(ChargerTileEntityRenderer.EFFECT_LOCATION);
|
||||
event.addSprite(ChargerRenderer.EFFECT_LOCATION);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleEntityRendererRegisterEvent(final EntityRenderersEvent.RegisterRenderers event) {
|
||||
event.registerEntityRenderer(Entities.ROBOT.get(), RobotEntityRenderer::new);
|
||||
event.registerEntityRenderer(Entities.ROBOT.get(), RobotRenderer::new);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -9,23 +9,23 @@ import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public final class LoopingTileEntitySound extends AbstractTickableSoundInstance {
|
||||
public final class LoopingBlockEntitySound extends AbstractTickableSoundInstance {
|
||||
private static final float FADE_IN_DURATION_IN_SECONDS = 2.0f;
|
||||
private static final float FADE_IN_DURATION_IN_TICKS = FADE_IN_DURATION_IN_SECONDS * Constants.SECONDS_TO_TICKS;
|
||||
private static final float FADE_IN_PER_TICK = 1f / FADE_IN_DURATION_IN_TICKS;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private final BlockEntity tileEntity;
|
||||
private final BlockEntity blockEntity;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public LoopingTileEntitySound(final BlockEntity tileEntity, final SoundEvent sound) {
|
||||
public LoopingBlockEntitySound(final BlockEntity blockEntity, final SoundEvent sound) {
|
||||
super(sound, SoundSource.BLOCKS);
|
||||
this.tileEntity = tileEntity;
|
||||
this.blockEntity = blockEntity;
|
||||
this.volume = 0;
|
||||
|
||||
final Vec3 position = Vec3.atCenterOf(tileEntity.getBlockPos());
|
||||
final Vec3 position = Vec3.atCenterOf(blockEntity.getBlockPos());
|
||||
x = position.x;
|
||||
y = position.y;
|
||||
z = position.z;
|
||||
@@ -38,8 +38,8 @@ public final class LoopingTileEntitySound extends AbstractTickableSoundInstance
|
||||
@Override
|
||||
public void tick() {
|
||||
volume = Mth.clamp(volume + FADE_IN_PER_TICK, 0, 1);
|
||||
final ChunkPos chunkPos = new ChunkPos(tileEntity.getBlockPos());
|
||||
if (tileEntity.isRemoved() || !tileEntity.getLevel().hasChunk(chunkPos.x, chunkPos.z)) {
|
||||
final ChunkPos chunkPos = new ChunkPos(blockEntity.getBlockPos());
|
||||
if (blockEntity.isRemoved() || blockEntity.getLevel() == null || !blockEntity.getLevel().hasChunk(chunkPos.x, chunkPos.z)) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
@@ -8,27 +8,27 @@ import net.minecraft.sounds.SoundEvent;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public final class LoopingSoundManager {
|
||||
private static final WeakHashMap<BlockEntity, TickableSoundInstance> TILE_ENTITY_SOUNDS = new WeakHashMap<>();
|
||||
private static final WeakHashMap<BlockEntity, TickableSoundInstance> BLOCK_ENTITY_SOUNDS = new WeakHashMap<>();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void play(final BlockEntity tileEntity, final SoundEvent sound, final int delay) {
|
||||
stop(tileEntity);
|
||||
public static void play(final BlockEntity blockEntity, final SoundEvent sound, final int delay) {
|
||||
stop(blockEntity);
|
||||
|
||||
final LoopingTileEntitySound instance = new LoopingTileEntitySound(tileEntity, sound);
|
||||
TILE_ENTITY_SOUNDS.put(tileEntity, instance);
|
||||
final LoopingBlockEntitySound instance = new LoopingBlockEntitySound(blockEntity, sound);
|
||||
BLOCK_ENTITY_SOUNDS.put(blockEntity, instance);
|
||||
Minecraft.getInstance().getSoundManager().playDelayed(instance, delay);
|
||||
}
|
||||
|
||||
public static void stop(final BlockEntity tileEntity) {
|
||||
final TickableSoundInstance instance = TILE_ENTITY_SOUNDS.remove(tileEntity);
|
||||
public static void stop(final BlockEntity blockEntity) {
|
||||
final TickableSoundInstance instance = BLOCK_ENTITY_SOUNDS.remove(blockEntity);
|
||||
if (instance != null) {
|
||||
Minecraft.getInstance().getSoundManager().stop(instance);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPlaying(final BlockEntity tileEntity) {
|
||||
final TickableSoundInstance instance = TILE_ENTITY_SOUNDS.get(tileEntity);
|
||||
public static boolean isPlaying(final BlockEntity blockEntity) {
|
||||
final TickableSoundInstance instance = BLOCK_ENTITY_SOUNDS.get(blockEntity);
|
||||
return instance != null && !instance.isStopped();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,23 +72,23 @@ public abstract class AbstractMachineInventoryScreen<T extends AbstractMachineTe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
renderBackground(matrixStack);
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
renderBackground(stack);
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
|
||||
final int energyCapacity = menu.getEnergyCapacity();
|
||||
if (energyCapacity > 0) {
|
||||
final int energyStored = menu.getEnergy();
|
||||
final int energyConsumption = menu.getEnergyConsumption();
|
||||
|
||||
Sprites.ENERGY_BAR.drawFillY(matrixStack, leftPos - Sprites.SIDEBAR_2.width + 4, topPos + ENERGY_TOP + 4, energyStored / (float) energyCapacity);
|
||||
Sprites.ENERGY_BAR.drawFillY(stack, leftPos - Sprites.SIDEBAR_2.width + 4, topPos + ENERGY_TOP + 4, energyStored / (float) energyCapacity);
|
||||
|
||||
if (isMouseOver(mouseX, mouseY, -Sprites.SIDEBAR_2.width + 4, ENERGY_TOP + 4, Sprites.ENERGY_BAR.width, Sprites.ENERGY_BAR.height)) {
|
||||
final List<? extends FormattedText> tooltip = asList(
|
||||
new TranslatableComponent(Constants.TOOLTIP_ENERGY, withColor(energyStored + "/" + energyCapacity, ChatFormatting.GREEN)),
|
||||
new TranslatableComponent(Constants.TOOLTIP_ENERGY_CONSUMPTION, withColor(String.valueOf(energyConsumption), ChatFormatting.GREEN))
|
||||
);
|
||||
TooltipUtils.drawTooltip(matrixStack, tooltip, mouseX, mouseY, 200);
|
||||
TooltipUtils.drawTooltip(stack, tooltip, mouseX, mouseY, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,24 +96,24 @@ public abstract class AbstractMachineInventoryScreen<T extends AbstractMachineTe
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void renderBg(final PoseStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
Sprites.SIDEBAR_2.draw(matrixStack, leftPos - Sprites.SIDEBAR_2.width, topPos + CONTROLS_TOP);
|
||||
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
Sprites.SIDEBAR_2.draw(stack, leftPos - Sprites.SIDEBAR_2.width, topPos + CONTROLS_TOP);
|
||||
|
||||
if (menu.getEnergyCapacity() > 0) {
|
||||
final int x = leftPos - Sprites.SIDEBAR_2.width;
|
||||
final int y = topPos + ENERGY_TOP;
|
||||
Sprites.SIDEBAR_2.draw(matrixStack, x, y);
|
||||
Sprites.ENERGY_BASE.draw(matrixStack, x + 4, y + 4);
|
||||
Sprites.SIDEBAR_2.draw(stack, x, y);
|
||||
Sprites.ENERGY_BASE.draw(stack, x + 4, y + 4);
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderMissingDeviceInfo(final PoseStack matrixStack, final int mouseX, final int mouseY) {
|
||||
GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.FLASH_MEMORY, Sprites.WARN_ICON);
|
||||
GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.MEMORY, Sprites.WARN_ICON);
|
||||
GuiUtils.renderMissingDeviceInfoIcon(matrixStack, this, DeviceTypes.HARD_DRIVE, Sprites.INFO_ICON);
|
||||
protected void renderMissingDeviceInfo(final PoseStack stack, final int mouseX, final int mouseY) {
|
||||
GuiUtils.renderMissingDeviceInfoIcon(stack, this, DeviceTypes.FLASH_MEMORY, Sprites.WARN_ICON);
|
||||
GuiUtils.renderMissingDeviceInfoIcon(stack, this, DeviceTypes.MEMORY, Sprites.WARN_ICON);
|
||||
GuiUtils.renderMissingDeviceInfoIcon(stack, this, DeviceTypes.HARD_DRIVE, Sprites.INFO_ICON);
|
||||
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.FLASH_MEMORY);
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.MEMORY);
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(matrixStack, this, mouseX, mouseY, DeviceTypes.HARD_DRIVE);
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(stack, this, mouseX, mouseY, DeviceTypes.FLASH_MEMORY);
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(stack, this, mouseX, mouseY, DeviceTypes.MEMORY);
|
||||
GuiUtils.renderMissingDeviceInfoTooltip(stack, this, mouseX, mouseY, DeviceTypes.HARD_DRIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,24 +44,24 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
renderBackground(matrixStack);
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
terminalWidget.render(matrixStack, mouseX, mouseY, menu.getVirtualMachine().getBootError());
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
renderBackground(stack);
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
terminalWidget.render(stack, mouseX, mouseY, menu.getVirtualMachine().getBootError());
|
||||
|
||||
final int energyCapacity = menu.getEnergyCapacity();
|
||||
if (energyCapacity > 0) {
|
||||
final int energyStored = menu.getEnergy();
|
||||
final int energyConsumption = menu.getEnergyConsumption();
|
||||
|
||||
Sprites.ENERGY_BAR.drawFillY(matrixStack, leftPos - Sprites.SIDEBAR_2.width + 4, topPos + ENERGY_TOP + 4, energyStored / (float) energyCapacity);
|
||||
Sprites.ENERGY_BAR.drawFillY(stack, leftPos - Sprites.SIDEBAR_2.width + 4, topPos + ENERGY_TOP + 4, energyStored / (float) energyCapacity);
|
||||
|
||||
if (isMouseOver(mouseX, mouseY, -Sprites.SIDEBAR_2.width + 4, ENERGY_TOP + 4, Sprites.ENERGY_BAR.width, Sprites.ENERGY_BAR.height)) {
|
||||
final List<? extends FormattedText> tooltip = asList(
|
||||
new TranslatableComponent(Constants.TOOLTIP_ENERGY, withColor(energyStored + "/" + energyCapacity, ChatFormatting.GREEN)),
|
||||
new TranslatableComponent(Constants.TOOLTIP_ENERGY_CONSUMPTION, withColor(String.valueOf(energyConsumption), ChatFormatting.GREEN))
|
||||
);
|
||||
TooltipUtils.drawTooltip(matrixStack, tooltip, mouseX, mouseY, 200);
|
||||
TooltipUtils.drawTooltip(stack, tooltip, mouseX, mouseY, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
// Don't close with inventory binding since we usually want to use that as terminal input
|
||||
// even without input capture enabled.
|
||||
final InputConstants.Key input = InputConstants.getKey(keyCode, scanCode);
|
||||
if (minecraft.options.keyInventory.isActiveAndMatches(input)) {
|
||||
if (getMinecraft().options.keyInventory.isActiveAndMatches(input)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -166,24 +166,24 @@ public abstract class AbstractMachineTerminalScreen<T extends AbstractMachineTer
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void renderBg(final PoseStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
|
||||
Sprites.SIDEBAR_3.draw(matrixStack, leftPos - Sprites.SIDEBAR_2.width, topPos + CONTROLS_TOP);
|
||||
Sprites.SIDEBAR_3.draw(stack, leftPos - Sprites.SIDEBAR_2.width, topPos + CONTROLS_TOP);
|
||||
|
||||
if (menu.getEnergyCapacity() > 0) {
|
||||
final int x = leftPos - Sprites.SIDEBAR_2.width;
|
||||
final int y = topPos + ENERGY_TOP;
|
||||
Sprites.SIDEBAR_2.draw(matrixStack, x, y);
|
||||
Sprites.ENERGY_BASE.draw(matrixStack, x + 4, y + 4);
|
||||
Sprites.SIDEBAR_2.draw(stack, x, y);
|
||||
Sprites.ENERGY_BASE.draw(stack, x + 4, y + 4);
|
||||
}
|
||||
|
||||
terminalWidget.renderBackground(matrixStack, mouseX, mouseY);
|
||||
terminalWidget.renderBackground(stack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(final PoseStack matrixStack, final int mouseX, final int mouseY) {
|
||||
protected void renderLabels(final PoseStack stack, final int mouseX, final int mouseY) {
|
||||
// This is required to prevent the labels from being rendered
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.item.Items;
|
||||
import li.cil.oc2.common.network.Network;
|
||||
import li.cil.oc2.common.network.message.BusInterfaceNameMessage;
|
||||
import li.cil.oc2.common.tileentity.BusCableTileEntity;
|
||||
import li.cil.oc2.common.blockentity.BusCableBlockEntity;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.core.Direction;
|
||||
@@ -25,7 +25,7 @@ public final class BusInterfaceScreen extends Screen {
|
||||
private static final int CANCEL_LEFT = 219;
|
||||
private static final int CANCEL_TOP = 9;
|
||||
|
||||
private final BusCableTileEntity tileEntity;
|
||||
private final BusCableBlockEntity busCable;
|
||||
private final Direction side;
|
||||
|
||||
private EditBox nameField;
|
||||
@@ -34,9 +34,9 @@ public final class BusInterfaceScreen extends Screen {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public BusInterfaceScreen(final BusCableTileEntity tileEntity, final Direction side) {
|
||||
public BusInterfaceScreen(final BusCableBlockEntity busCable, final Direction side) {
|
||||
super(Items.BUS_INTERFACE.get().getDescription());
|
||||
this.tileEntity = tileEntity;
|
||||
this.busCable = busCable;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@@ -56,18 +56,18 @@ public final class BusInterfaceScreen extends Screen {
|
||||
nameField.setTextColor(0xFFFFFFFF);
|
||||
nameField.setBordered(false);
|
||||
nameField.setMaxLength(32);
|
||||
nameField.setValue(tileEntity.getInterfaceName(side));
|
||||
nameField.setValue(busCable.getInterfaceName(side));
|
||||
addWidget(nameField);
|
||||
setInitialFocus(nameField);
|
||||
|
||||
addRenderableWidget(new ImageButton(
|
||||
this,
|
||||
left + CONFIRM_LEFT, top + CONFIRM_TOP,
|
||||
Sprites.CONFIRM_BASE.width, Sprites.CONFIRM_BASE.height,
|
||||
new TranslatableComponent(Constants.TOOLTIP_CONFIRM),
|
||||
null,
|
||||
Sprites.CONFIRM_BASE,
|
||||
Sprites.CONFIRM_PRESSED
|
||||
this,
|
||||
left + CONFIRM_LEFT, top + CONFIRM_TOP,
|
||||
Sprites.CONFIRM_BASE.width, Sprites.CONFIRM_BASE.height,
|
||||
new TranslatableComponent(Constants.TOOLTIP_CONFIRM),
|
||||
null,
|
||||
Sprites.CONFIRM_BASE,
|
||||
Sprites.CONFIRM_PRESSED
|
||||
) {
|
||||
@Override
|
||||
public void onPress() {
|
||||
@@ -77,13 +77,13 @@ public final class BusInterfaceScreen extends Screen {
|
||||
}
|
||||
});
|
||||
addRenderableWidget(new ImageButton(
|
||||
this,
|
||||
left + CANCEL_LEFT, top + CANCEL_TOP,
|
||||
Sprites.CANCEL_BASE.width, Sprites.CANCEL_BASE.height,
|
||||
new TranslatableComponent(Constants.TOOLTIP_CANCEL),
|
||||
null,
|
||||
Sprites.CANCEL_BASE,
|
||||
Sprites.CANCEL_PRESSED
|
||||
this,
|
||||
left + CANCEL_LEFT, top + CANCEL_TOP,
|
||||
Sprites.CANCEL_BASE.width, Sprites.CANCEL_BASE.height,
|
||||
new TranslatableComponent(Constants.TOOLTIP_CANCEL),
|
||||
null,
|
||||
Sprites.CANCEL_BASE,
|
||||
Sprites.CANCEL_PRESSED
|
||||
) {
|
||||
@Override
|
||||
public void onPress() {
|
||||
@@ -105,8 +105,8 @@ public final class BusInterfaceScreen extends Screen {
|
||||
super.tick();
|
||||
nameField.tick();
|
||||
|
||||
final Vec3 busCableCenter = Vec3.atCenterOf(tileEntity.getBlockPos());
|
||||
if (getMinecraft().player.distanceToSqr(busCableCenter) > 8 * 8) {
|
||||
final Vec3 busCableCenter = Vec3.atCenterOf(busCable.getBlockPos());
|
||||
if (getMinecraft().player == null || getMinecraft().player.distanceToSqr(busCableCenter) > 8 * 8) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
@@ -124,14 +124,14 @@ public final class BusInterfaceScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
renderBackground(matrixStack);
|
||||
Sprites.BUS_INTERFACE_SCREEN.draw(matrixStack, left, top);
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
renderBackground(stack);
|
||||
Sprites.BUS_INTERFACE_SCREEN.draw(stack, left, top);
|
||||
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
|
||||
RenderSystem.disableBlend();
|
||||
nameField.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
nameField.render(stack, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,6 +142,6 @@ public final class BusInterfaceScreen extends Screen {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private void setInterfaceName(final String name) {
|
||||
Network.INSTANCE.sendToServer(new BusInterfaceNameMessage.ToServer(tileEntity, side, name));
|
||||
Network.INSTANCE.sendToServer(new BusInterfaceNameMessage.ToServer(busCable, side, name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,22 +18,22 @@ public final class ComputerContainerScreen extends AbstractMachineInventoryScree
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
|
||||
renderMissingDeviceInfo(matrixStack, mouseX, mouseY);
|
||||
renderMissingDeviceInfo(stack, mouseX, mouseY);
|
||||
|
||||
renderTooltip(matrixStack, mouseX, mouseY);
|
||||
renderTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void renderBg(final PoseStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
|
||||
Sprites.COMPUTER_CONTAINER.draw(matrixStack, leftPos, topPos);
|
||||
super.renderBg(matrixStack, partialTicks, mouseX, mouseY);
|
||||
Sprites.COMPUTER_CONTAINER.draw(stack, leftPos, topPos);
|
||||
super.renderBg(stack, partialTicks, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,23 +2,22 @@ package li.cil.oc2.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static li.cil.oc2.common.util.TranslationUtils.text;
|
||||
|
||||
@@ -113,16 +112,16 @@ public final class FileChooserScreen extends Screen {
|
||||
}
|
||||
|
||||
if (previousScreen != null) {
|
||||
minecraft.tell(() -> minecraft.setScreen(previousScreen));
|
||||
getMinecraft().tell(() -> getMinecraft().setScreen(previousScreen));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.renderBackground(matrixStack);
|
||||
fileList.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
fileNameTextField.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.renderBackground(stack);
|
||||
fileList.render(stack, mouseX, mouseY, partialTicks);
|
||||
fileNameTextField.render(stack, mouseX, mouseY, partialTicks);
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,7 +134,7 @@ public final class FileChooserScreen extends Screen {
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui(true);
|
||||
getMinecraft().keyboardHandler.setSendRepeatsToGui(true);
|
||||
|
||||
final int widgetsWidth = width - MARGIN * 2;
|
||||
final int listHeight = height - MARGIN - WIDGET_SPACING - TEXT_FIELD_HEIGHT - WIDGET_SPACING - BUTTON_HEIGHT - MARGIN;
|
||||
@@ -182,18 +181,17 @@ public final class FileChooserScreen extends Screen {
|
||||
|
||||
final FileList.FileEntry selected = fileList.getSelected();
|
||||
if (selected != null) {
|
||||
return selected.file == null || selected.file.equals(directory.getParent());
|
||||
return selected.file.equals(directory.getParent());
|
||||
}
|
||||
|
||||
final String selectedFileEntry = fileNameTextField.getValue();
|
||||
return "..".equals(selectedFileEntry);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Optional<Path> getPath() {
|
||||
final FileList.FileEntry selected = fileList.getSelected();
|
||||
if (selected != null) {
|
||||
return Optional.ofNullable(selected.file);
|
||||
return Optional.of(selected.file);
|
||||
}
|
||||
|
||||
if (directory == null) {
|
||||
@@ -201,7 +199,7 @@ public final class FileChooserScreen extends Screen {
|
||||
}
|
||||
|
||||
final String selectedFileEntry = fileNameTextField.getValue();
|
||||
if (selectedFileEntry == null || "".equals(selectedFileEntry) || ".".equals(selectedFileEntry)) {
|
||||
if ("".equals(selectedFileEntry) || ".".equals(selectedFileEntry)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -219,7 +217,7 @@ public final class FileChooserScreen extends Screen {
|
||||
}
|
||||
|
||||
getPath().ifPresent(path -> {
|
||||
if (path == null || Files.isDirectory(path)) {
|
||||
if (Files.isDirectory(path)) {
|
||||
fileList.refreshFiles(path);
|
||||
return;
|
||||
}
|
||||
@@ -276,10 +274,10 @@ public final class FileChooserScreen extends Screen {
|
||||
|
||||
private final class FileList extends ObjectSelectionList<FileList.FileEntry> {
|
||||
public FileList(final int y, final int height, final int slotHeight) {
|
||||
super(FileChooserScreen.this.minecraft, FileChooserScreen.this.width, FileChooserScreen.this.height, y, y + height, slotHeight);
|
||||
super(FileChooserScreen.this.getMinecraft(), FileChooserScreen.this.width, FileChooserScreen.this.height, y, y + height, slotHeight);
|
||||
}
|
||||
|
||||
public void refreshFiles(final Path directory) {
|
||||
public void refreshFiles(@Nullable Path directory) {
|
||||
FileChooserScreen.directory = directory;
|
||||
|
||||
setScrollAmount(0);
|
||||
@@ -290,16 +288,15 @@ public final class FileChooserScreen extends Screen {
|
||||
|
||||
try {
|
||||
final List<Path> files = Files.list(directory)
|
||||
.sorted((p1, p2) -> {
|
||||
if (Files.isDirectory(p1) && !Files.isDirectory(p2)) {
|
||||
return -1;
|
||||
}
|
||||
if (!Files.isDirectory(p1) && Files.isDirectory(p2)) {
|
||||
return 1;
|
||||
}
|
||||
return p1.getFileName().compareTo(p2.getFileName());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
.sorted((p1, p2) -> {
|
||||
if (Files.isDirectory(p1) && !Files.isDirectory(p2)) {
|
||||
return -1;
|
||||
}
|
||||
if (!Files.isDirectory(p1) && Files.isDirectory(p2)) {
|
||||
return 1;
|
||||
}
|
||||
return p1.getFileName().compareTo(p2.getFileName());
|
||||
}).toList();
|
||||
for (final Path path : files) {
|
||||
try {
|
||||
if (Files.isHidden(path)) {
|
||||
@@ -332,10 +329,10 @@ public final class FileChooserScreen extends Screen {
|
||||
} else {
|
||||
refreshFiles(path.getParent());
|
||||
children().stream().filter(entry -> entry.file.equals(path))
|
||||
.findFirst().ifPresent(entry -> {
|
||||
entry.select();
|
||||
centerScrollOn(entry);
|
||||
});
|
||||
.findFirst().ifPresent(entry -> {
|
||||
entry.select();
|
||||
centerScrollOn(entry);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +352,7 @@ public final class FileChooserScreen extends Screen {
|
||||
|
||||
private FileList.FileEntry createDirectoryEntry(final Path path, final String displayName) {
|
||||
return new FileList.FileEntry(path, new TextComponent(displayName)
|
||||
.withStyle(s -> s.withColor(TextColor.fromRgb(0xA0A0FF))));
|
||||
.withStyle(s -> s.withColor(TextColor.fromRgb(0xA0A0FF))));
|
||||
}
|
||||
|
||||
private final class FileEntry extends ObjectSelectionList.Entry<FileEntry> {
|
||||
@@ -393,7 +390,7 @@ public final class FileChooserScreen extends Screen {
|
||||
}
|
||||
|
||||
public void select() {
|
||||
if (file == null || (directory != null && file.equals(directory.getParent()))) {
|
||||
if (directory != null && file.equals(directory.getParent())) {
|
||||
fileNameTextField.setValue("..");
|
||||
} else {
|
||||
final Path fileName = file.getFileName();
|
||||
|
||||
@@ -40,29 +40,29 @@ public final class MachineTerminalWidget extends GuiComponent {
|
||||
this.terminal = this.container.getTerminal();
|
||||
}
|
||||
|
||||
public void renderBackground(final PoseStack matrixStack, final int mouseX, final int mouseY) {
|
||||
public void renderBackground(final PoseStack stack, final int mouseX, final int mouseY) {
|
||||
isMouseOverTerminal = isMouseOverTerminal(mouseX, mouseY);
|
||||
|
||||
Sprites.TERMINAL_SCREEN.draw(matrixStack, leftPos, topPos);
|
||||
Sprites.TERMINAL_SCREEN.draw(stack, leftPos, topPos);
|
||||
|
||||
if (shouldCaptureInput()) {
|
||||
Sprites.TERMINAL_FOCUSED.draw(matrixStack, leftPos, topPos);
|
||||
Sprites.TERMINAL_FOCUSED.draw(stack, leftPos, topPos);
|
||||
}
|
||||
}
|
||||
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, @Nullable final Component error) {
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, @Nullable final Component error) {
|
||||
if (container.getVirtualMachine().isRunning()) {
|
||||
final PoseStack stack = new PoseStack();
|
||||
stack.translate(leftPos + TERMINAL_X, topPos + TERMINAL_Y, getClient().getItemRenderer().blitOffset);
|
||||
stack.scale(TERMINAL_WIDTH / (float) terminal.getWidth(), TERMINAL_HEIGHT / (float) terminal.getHeight(), 1f);
|
||||
terminal.render(stack);
|
||||
final PoseStack terminalStack = new PoseStack();
|
||||
terminalStack.translate(leftPos + TERMINAL_X, topPos + TERMINAL_Y, getClient().getItemRenderer().blitOffset);
|
||||
terminalStack.scale(TERMINAL_WIDTH / (float) terminal.getWidth(), TERMINAL_HEIGHT / (float) terminal.getHeight(), 1f);
|
||||
terminal.render(terminalStack);
|
||||
} else {
|
||||
final Font font = getClient().font;
|
||||
if (error != null) {
|
||||
final int textWidth = font.width(error);
|
||||
final int textOffsetX = (TERMINAL_WIDTH - textWidth) / 2;
|
||||
final int textOffsetY = (TERMINAL_HEIGHT - font.lineHeight) / 2;
|
||||
font.drawShadow(matrixStack,
|
||||
font.drawShadow(stack,
|
||||
error,
|
||||
leftPos + TERMINAL_X + textOffsetX,
|
||||
topPos + TERMINAL_Y + textOffsetY,
|
||||
@@ -96,8 +96,8 @@ public final class MachineTerminalWidget extends GuiComponent {
|
||||
} else {
|
||||
final byte[] sequence = TerminalInput.getSequence(keyCode, modifiers);
|
||||
if (sequence != null) {
|
||||
for (int i = 0; i < sequence.length; i++) {
|
||||
terminal.putInput(sequence[i]);
|
||||
for (byte b : sequence) {
|
||||
terminal.putInput(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ public final class RobotContainerScreen extends AbstractMachineInventoryScreen<R
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void renderSelection(final PoseStack matrixStack, final int selectedSlot, final int x, final int y, final int columns) {
|
||||
public static void renderSelection(final PoseStack stack, final int selectedSlot, final int x, final int y, final int columns) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
|
||||
final int slotX = (selectedSlot % columns) * SLOT_SIZE;
|
||||
final int slotY = (selectedSlot / columns) * SLOT_SIZE;
|
||||
final int offset = SLOT_SIZE * (int) (15 * (System.currentTimeMillis() % 1000) / 1000);
|
||||
Sprites.SLOT_SELECTION.draw(matrixStack, x + slotX, y + slotY, 0, offset);
|
||||
Sprites.SLOT_SELECTION.draw(stack, x + slotX, y + slotY, 0, offset);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -32,30 +32,30 @@ public final class RobotContainerScreen extends AbstractMachineInventoryScreen<R
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
|
||||
renderSelection(matrixStack);
|
||||
renderSelection(stack);
|
||||
|
||||
renderMissingDeviceInfo(matrixStack, mouseX, mouseY);
|
||||
renderMissingDeviceInfo(stack, mouseX, mouseY);
|
||||
|
||||
renderTooltip(matrixStack, mouseX, mouseY);
|
||||
renderTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected void renderBg(final PoseStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
|
||||
Sprites.ROBOT_CONTAINER.draw(matrixStack, leftPos, topPos);
|
||||
super.renderBg(matrixStack, partialTicks, mouseX, mouseY);
|
||||
Sprites.ROBOT_CONTAINER.draw(stack, leftPos, topPos);
|
||||
super.renderBg(stack, partialTicks, mouseX, mouseY);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private void renderSelection(final PoseStack matrixStack) {
|
||||
renderSelection(matrixStack, menu.getRobot().getSelectedSlot(), leftPos + 115, topPos + 23, 2);
|
||||
private void renderSelection(final PoseStack stack) {
|
||||
renderSelection(stack, menu.getRobot().getSelectedSlot(), leftPos + 115, topPos + 23, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,19 +18,19 @@ public final class RobotTerminalScreen extends AbstractMachineTerminalScreen<Rob
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(final PoseStack matrixStack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
protected void renderBg(final PoseStack stack, final float partialTicks, final int mouseX, final int mouseY) {
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
||||
|
||||
Sprites.HOTBAR.draw(matrixStack, leftPos + SLOTS_X, topPos + SLOTS_Y);
|
||||
Sprites.HOTBAR.draw(stack, leftPos + SLOTS_X, topPos + SLOTS_Y);
|
||||
|
||||
super.renderBg(matrixStack, partialTicks, mouseX, mouseY);
|
||||
super.renderBg(stack, partialTicks, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrixStack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.render(matrixStack, mouseX, mouseY, partialTicks);
|
||||
RobotContainerScreen.renderSelection(matrixStack, menu.getRobot().getSelectedSlot(), leftPos + SLOTS_X + 4, topPos + SLOTS_Y + 4, 12);
|
||||
renderTooltip(matrixStack, mouseX, mouseY);
|
||||
public void render(final PoseStack stack, final int mouseX, final int mouseY, final float partialTicks) {
|
||||
super.render(stack, mouseX, mouseY, partialTicks);
|
||||
RobotContainerScreen.renderSelection(stack, menu.getRobot().getSelectedSlot(), leftPos + SLOTS_X + 4, topPos + SLOTS_Y + 4, 12);
|
||||
renderTooltip(stack, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ import li.cil.oc2.api.bus.device.DeviceType;
|
||||
import li.cil.oc2.api.bus.device.DeviceTypes;
|
||||
import li.cil.oc2.client.gui.widget.Sprite;
|
||||
import li.cil.oc2.common.container.TypedSlotItemHandler;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -35,18 +36,23 @@ public final class GuiUtils {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static <TContainer extends AbstractContainerMenu> void renderMissingDeviceInfoIcon(final PoseStack matrixStack, final AbstractContainerScreen<TContainer> screen, final DeviceType type, final Sprite icon) {
|
||||
findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> icon.draw(matrixStack,
|
||||
screen.getGuiLeft() + slot.x - 1 + RELATIVE_ICON_POSITION,
|
||||
screen.getGuiTop() + slot.y - 1 + RELATIVE_ICON_POSITION));
|
||||
public static <TContainer extends AbstractContainerMenu> void renderMissingDeviceInfoIcon(final PoseStack stack, final AbstractContainerScreen<TContainer> screen, final DeviceType type, final Sprite icon) {
|
||||
findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> icon.draw(stack,
|
||||
screen.getGuiLeft() + slot.x - 1 + RELATIVE_ICON_POSITION,
|
||||
screen.getGuiTop() + slot.y - 1 + RELATIVE_ICON_POSITION));
|
||||
}
|
||||
|
||||
public static <TContainer extends AbstractContainerMenu> void renderMissingDeviceInfoTooltip(final PoseStack matrixStack, final AbstractContainerScreen<TContainer> screen, final int mouseX, final int mouseY, final DeviceType type) {
|
||||
renderMissingDeviceInfoTooltip(matrixStack, screen, mouseX, mouseY, type, Objects.requireNonNull(WARNING_BY_DEVICE_TYPE.get(type)));
|
||||
public static <TContainer extends AbstractContainerMenu> void renderMissingDeviceInfoTooltip(final PoseStack stack, final AbstractContainerScreen<TContainer> screen, final int mouseX, final int mouseY, final DeviceType type) {
|
||||
renderMissingDeviceInfoTooltip(stack, screen, mouseX, mouseY, type, Objects.requireNonNull(WARNING_BY_DEVICE_TYPE.get(type)));
|
||||
}
|
||||
|
||||
public static <TContainer extends AbstractContainerMenu> void renderMissingDeviceInfoTooltip(final PoseStack matrixStack, final AbstractContainerScreen<TContainer> screen, final int mouseX, final int mouseY, final DeviceType type, final Component tooltip) {
|
||||
final boolean isCursorHoldingStack = !screen.getMinecraft().player.inventoryMenu.getCarried().isEmpty();
|
||||
public static <TContainer extends AbstractContainerMenu> void renderMissingDeviceInfoTooltip(final PoseStack stack, final AbstractContainerScreen<TContainer> screen, final int mouseX, final int mouseY, final DeviceType type, final Component tooltip) {
|
||||
Minecraft minecraft = screen.getMinecraft();
|
||||
if (minecraft.player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean isCursorHoldingStack = !minecraft.player.inventoryMenu.getCarried().isEmpty();
|
||||
if (isCursorHoldingStack) {
|
||||
return;
|
||||
}
|
||||
@@ -58,7 +64,7 @@ public final class GuiUtils {
|
||||
|
||||
findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(screen.getMenu(), type).ifPresent(slot -> {
|
||||
if (slot == hoveredSlot) {
|
||||
screen.renderTooltip(matrixStack, tooltip, mouseX, mouseY);
|
||||
screen.renderTooltip(stack, tooltip, mouseX, mouseY);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -68,8 +74,7 @@ public final class GuiUtils {
|
||||
private static Optional<TypedSlotItemHandler> findFirstSlotOfTypeIfAllSlotsOfTypeEmpty(final AbstractContainerMenu container, final DeviceType type) {
|
||||
TypedSlotItemHandler firstSlot = null;
|
||||
for (final Slot slot : container.slots) {
|
||||
if (slot instanceof TypedSlotItemHandler) {
|
||||
final TypedSlotItemHandler typedSlot = (TypedSlotItemHandler) slot;
|
||||
if (slot instanceof final TypedSlotItemHandler typedSlot) {
|
||||
final DeviceType slotType = typedSlot.getDeviceType();
|
||||
if (slotType == type) {
|
||||
if (slot.hasItem()) {
|
||||
|
||||
@@ -44,48 +44,29 @@ public final class CustomItemColors {
|
||||
}
|
||||
|
||||
public static int getColorByDye(final DyeColor dye) {
|
||||
switch (dye) {
|
||||
case WHITE:
|
||||
return WHITE;
|
||||
case ORANGE:
|
||||
return ORANGE;
|
||||
case MAGENTA:
|
||||
return MAGENTA;
|
||||
case LIGHT_BLUE:
|
||||
return LIGHT_BLUE;
|
||||
case YELLOW:
|
||||
return YELLOW;
|
||||
case LIME:
|
||||
return LIME;
|
||||
case PINK:
|
||||
return PINK;
|
||||
case GRAY:
|
||||
return GREY;
|
||||
case LIGHT_GRAY:
|
||||
return LIGHT_GREY;
|
||||
case CYAN:
|
||||
return CYAN;
|
||||
case PURPLE:
|
||||
return PURPLE;
|
||||
case BLUE:
|
||||
return BLUE;
|
||||
case BROWN:
|
||||
return BROWN;
|
||||
case GREEN:
|
||||
return GREEN;
|
||||
case RED:
|
||||
return RED;
|
||||
case BLACK:
|
||||
return BLACK;
|
||||
}
|
||||
|
||||
return GREY;
|
||||
return switch (dye) {
|
||||
case WHITE -> WHITE;
|
||||
case ORANGE -> ORANGE;
|
||||
case MAGENTA -> MAGENTA;
|
||||
case LIGHT_BLUE -> LIGHT_BLUE;
|
||||
case YELLOW -> YELLOW;
|
||||
case LIME -> LIME;
|
||||
case PINK -> PINK;
|
||||
case GRAY -> GREY;
|
||||
case LIGHT_GRAY -> LIGHT_GREY;
|
||||
case CYAN -> CYAN;
|
||||
case PURPLE -> PURPLE;
|
||||
case BLUE -> BLUE;
|
||||
case BROWN -> BROWN;
|
||||
case GREEN -> GREEN;
|
||||
case RED -> RED;
|
||||
case BLACK -> BLACK;
|
||||
};
|
||||
}
|
||||
|
||||
public static int getColor(final ItemStack stack) {
|
||||
final Item item = stack.getItem();
|
||||
if (item instanceof DyeableLeatherItem) {
|
||||
final DyeableLeatherItem coloredItem = (DyeableLeatherItem) item;
|
||||
if (item instanceof final DyeableLeatherItem coloredItem) {
|
||||
return coloredItem.getColor(stack);
|
||||
}
|
||||
return GREY;
|
||||
@@ -97,8 +78,7 @@ public final class CustomItemColors {
|
||||
|
||||
public static ItemStack withColor(final ItemStack stack, final int color) {
|
||||
final Item item = stack.getItem();
|
||||
if (item instanceof DyeableLeatherItem) {
|
||||
final DyeableLeatherItem coloredItem = (DyeableLeatherItem) item;
|
||||
if (item instanceof final DyeableLeatherItem coloredItem) {
|
||||
coloredItem.setColor(stack, color);
|
||||
}
|
||||
return stack;
|
||||
|
||||
@@ -12,14 +12,14 @@ public final class CustomItemModelProperties {
|
||||
|
||||
public static void initialize() {
|
||||
ItemProperties.register(Items.HARD_DRIVE_SMALL.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, world, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
(stack, level, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.HARD_DRIVE_MEDIUM.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, world, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
(stack, level, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.HARD_DRIVE_LARGE.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, world, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
(stack, leve, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.HARD_DRIVE_CUSTOM.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, world, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
(stack, level, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
ItemProperties.register(Items.FLOPPY.get(), CustomItemModelProperties.COLOR_PROPERTY,
|
||||
(stack, world, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
(stack, level, entity, seed) -> CustomItemColors.getColor(stack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package li.cil.oc2.client.model;
|
||||
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.block.BusCableBlock;
|
||||
import li.cil.oc2.common.tileentity.BusCableTileEntity;
|
||||
import li.cil.oc2.common.blockentity.BusCableBlockEntity;
|
||||
import li.cil.oc2.common.util.ItemStackUtils;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
@@ -58,7 +58,7 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
|
||||
if (extraData.hasProperty(BUS_CABLE_FACADE_PROPERTY)) {
|
||||
final BusCableFacade facade = extraData.getData(BUS_CABLE_FACADE_PROPERTY);
|
||||
if (layer == null || ItemBlockRenderTypes.canRenderInLayer(facade.blockState, layer)) {
|
||||
if (facade != null && (layer == null || ItemBlockRenderTypes.canRenderInLayer(facade.blockState, layer))) {
|
||||
return facade.model.getQuads(facade.blockState, side, rand, facade.data);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
@@ -119,13 +119,13 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public IModelData getModelData(final BlockAndTintGetter world, final BlockPos pos, final BlockState state, final IModelData tileData) {
|
||||
public IModelData getModelData(final BlockAndTintGetter level, final BlockPos pos, final BlockState state, final IModelData blockEntityData) {
|
||||
if (state.hasProperty(BusCableBlock.HAS_FACADE) && state.getValue(BusCableBlock.HAS_FACADE)) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
|
||||
BlockState facadeState = null;
|
||||
if (tileEntity instanceof BusCableTileEntity) {
|
||||
final ItemStack facadeItem = ((BusCableTileEntity) tileEntity).getFacade();
|
||||
if (blockEntity instanceof BusCableBlockEntity) {
|
||||
final ItemStack facadeItem = ((BusCableBlockEntity) blockEntity).getFacade();
|
||||
facadeState = ItemStackUtils.getBlockState(facadeItem);
|
||||
}
|
||||
if (facadeState == null) {
|
||||
@@ -134,19 +134,19 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
|
||||
final BlockModelShaper shapes = Minecraft.getInstance().getBlockRenderer().getBlockModelShaper();
|
||||
final BakedModel model = shapes.getBlockModel(facadeState);
|
||||
final IModelData data = model.getModelData(world, pos, facadeState, tileData);
|
||||
final IModelData data = model.getModelData(level, pos, facadeState, blockEntityData);
|
||||
|
||||
return new ModelDataMap.Builder()
|
||||
.withInitial(BUS_CABLE_FACADE_PROPERTY, new BusCableFacade(facadeState, model, data))
|
||||
.build();
|
||||
.withInitial(BUS_CABLE_FACADE_PROPERTY, new BusCableFacade(facadeState, model, data))
|
||||
.build();
|
||||
}
|
||||
|
||||
Direction supportSide = null;
|
||||
for (final Direction direction : Constants.DIRECTIONS) {
|
||||
if (isNeighborInDirectionSolid(world, pos, direction)) {
|
||||
if (isNeighborInDirectionSolid(level, pos, direction)) {
|
||||
final EnumProperty<BusCableBlock.ConnectionType> property = BusCableBlock.FACING_TO_CONNECTION_MAP.get(direction);
|
||||
if (state.hasProperty(property) && state.getValue(property) == BusCableBlock.ConnectionType.INTERFACE) {
|
||||
return tileData; // Plug is already supporting us, bail.
|
||||
return blockEntityData; // Plug is already supporting us, bail.
|
||||
}
|
||||
|
||||
if (supportSide == null) { // Prefer vertical supports.
|
||||
@@ -157,18 +157,18 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
|
||||
if (supportSide != null) {
|
||||
return new ModelDataMap.Builder()
|
||||
.withInitial(BUS_CABLE_SUPPORT_PROPERTY, new BusCableSupportSide(supportSide))
|
||||
.build();
|
||||
.withInitial(BUS_CABLE_SUPPORT_PROPERTY, new BusCableSupportSide(supportSide))
|
||||
.build();
|
||||
}
|
||||
|
||||
return tileData;
|
||||
return blockEntityData;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static boolean isNeighborInDirectionSolid(final BlockAndTintGetter world, final BlockPos pos, final Direction direction) {
|
||||
private static boolean isNeighborInDirectionSolid(final BlockAndTintGetter level, final BlockPos pos, final Direction direction) {
|
||||
final BlockPos neighborPos = pos.relative(direction);
|
||||
return world.getBlockState(neighborPos).isFaceSturdy(world, neighborPos, direction.getOpposite());
|
||||
return level.getBlockState(neighborPos).isFaceSturdy(level, neighborPos, direction.getOpposite());
|
||||
}
|
||||
|
||||
private static boolean isStraightAlongAxis(final BlockState state, final Direction.Axis axis) {
|
||||
@@ -190,23 +190,7 @@ public final class BusCableBakedModel implements IDynamicBakedModel {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static final class BusCableSupportSide {
|
||||
public final Direction value;
|
||||
private record BusCableSupportSide(Direction value) { }
|
||||
|
||||
private BusCableSupportSide(final Direction value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BusCableFacade {
|
||||
public final BlockState blockState;
|
||||
public final BakedModel model;
|
||||
public final IModelData data;
|
||||
|
||||
public BusCableFacade(final BlockState blockState, final BakedModel model, final IModelData data) {
|
||||
this.blockState = blockState;
|
||||
this.model = model;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
private record BusCableFacade(BlockState blockState, BakedModel model, IModelData data) { }
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package li.cil.oc2.client.renderer;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import li.cil.oc2.common.block.BusCableBlock;
|
||||
import li.cil.oc2.common.integration.Wrenches;
|
||||
import li.cil.oc2.common.tileentity.BusCableTileEntity;
|
||||
import li.cil.oc2.common.blockentity.BusCableBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.Camera;
|
||||
@@ -35,24 +35,26 @@ public enum BusInterfaceNameRenderer {
|
||||
public void handleRenderLastEvent(final RenderLevelLastEvent event) {
|
||||
final Minecraft mc = Minecraft.getInstance();
|
||||
final Player player = mc.player;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Level level = player.level;
|
||||
|
||||
if (!Wrenches.isHoldingWrench(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(mc.hitResult instanceof BlockHitResult)) {
|
||||
if (!(mc.hitResult instanceof final BlockHitResult hit)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockHitResult hit = (BlockHitResult) mc.hitResult;
|
||||
final BlockPos blockPos = hit.getBlockPos();
|
||||
final BlockEntity tileEntity = level.getBlockEntity(blockPos);
|
||||
if (!(tileEntity instanceof BusCableTileEntity)) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(blockPos);
|
||||
if (!(blockEntity instanceof final BusCableBlockEntity busCable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BusCableTileEntity busCable = (BusCableTileEntity) tileEntity;
|
||||
final Direction side = BusCableBlock.getHitSide(blockPos, hit);
|
||||
if (BusCableBlock.getConnectionType(level.getBlockState(blockPos), side) != BusCableBlock.ConnectionType.INTERFACE) {
|
||||
return;
|
||||
|
||||
@@ -2,24 +2,20 @@ package li.cil.oc2.client.renderer;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import li.cil.oc2.common.tileentity.NetworkConnectorTileEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import li.cil.oc2.common.blockentity.NetworkConnectorBlockEntity;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.culling.Frustum;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import net.minecraft.world.level.*;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.client.event.RenderLevelLastEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
@@ -48,12 +44,12 @@ public final class NetworkCableRenderer {
|
||||
private static final float CABLE_MAX_LENGTH = 8f;
|
||||
private static final Vector3f CABLE_COLOR = new Vector3f(0.0f, 0.33f, 0.4f);
|
||||
|
||||
private static final Set<NetworkConnectorTileEntity> connectors = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
private static final Set<NetworkConnectorBlockEntity> connectors = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
private static int lastKnownConnectorCount;
|
||||
private static boolean isDirty;
|
||||
|
||||
private static final ArrayList<Connection> connections = new ArrayList<>();
|
||||
private static final WeakHashMap<NetworkConnectorTileEntity, ArrayList<Connection>> connectionsByConnector = new WeakHashMap<>();
|
||||
private static final WeakHashMap<NetworkConnectorBlockEntity, ArrayList<Connection>> connectionsByConnector = new WeakHashMap<>();
|
||||
private static final ArrayList<CablePoint> cablePoints = new ArrayList<>();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -64,7 +60,7 @@ public final class NetworkCableRenderer {
|
||||
MinecraftForge.EVENT_BUS.addListener(NetworkCableRenderer::handleWorldUnloadEvent);
|
||||
}
|
||||
|
||||
public static void addNetworkConnector(final NetworkConnectorTileEntity connector) {
|
||||
public static void addNetworkConnector(final NetworkConnectorBlockEntity connector) {
|
||||
connectors.add(connector);
|
||||
invalidateConnections();
|
||||
}
|
||||
@@ -73,10 +69,10 @@ public final class NetworkCableRenderer {
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
public static void renderCablesFor(final BlockAndTintGetter world, final PoseStack matrixStack, final Vec3 eye, final NetworkConnectorTileEntity connector) {
|
||||
public static void renderCablesFor(final BlockAndTintGetter level, final PoseStack stack, final Vec3 eye, final NetworkConnectorBlockEntity connector) {
|
||||
final ArrayList<Connection> connections = connectionsByConnector.get(connector);
|
||||
if (connections != null) {
|
||||
renderCables(world, matrixStack, eye, connections, unused -> true);
|
||||
renderCables(level, stack, eye, connections, unused -> true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +82,8 @@ public final class NetworkCableRenderer {
|
||||
if (event.getWorld().isClientSide()) {
|
||||
final ChunkPos chunkPos = event.getChunk().getPos();
|
||||
|
||||
final ArrayList<NetworkConnectorTileEntity> list = new ArrayList<>(NetworkCableRenderer.connectors);
|
||||
for (final NetworkConnectorTileEntity connector : list) {
|
||||
final ArrayList<NetworkConnectorBlockEntity> list = new ArrayList<>(NetworkCableRenderer.connectors);
|
||||
for (final NetworkConnectorBlockEntity connector : list) {
|
||||
final ChunkPos connectorChunkPos = new ChunkPos(connector.getBlockPos());
|
||||
if (Objects.equals(connectorChunkPos, chunkPos)) {
|
||||
connectors.remove(connector);
|
||||
@@ -100,11 +96,11 @@ public final class NetworkCableRenderer {
|
||||
|
||||
private static void handleWorldUnloadEvent(final WorldEvent.Unload event) {
|
||||
if (event.getWorld().isClientSide()) {
|
||||
final LevelAccessor world = event.getWorld();
|
||||
final LevelAccessor level = event.getWorld();
|
||||
|
||||
final ArrayList<NetworkConnectorTileEntity> list = new ArrayList<>(NetworkCableRenderer.connectors);
|
||||
for (final NetworkConnectorTileEntity connector : list) {
|
||||
if (connector.getLevel() == world) {
|
||||
final ArrayList<NetworkConnectorBlockEntity> list = new ArrayList<>(NetworkCableRenderer.connectors);
|
||||
for (final NetworkConnectorBlockEntity connector : list) {
|
||||
if (connector.getLevel() == level) {
|
||||
connectors.remove(connector);
|
||||
}
|
||||
}
|
||||
@@ -126,29 +122,29 @@ public final class NetworkCableRenderer {
|
||||
}
|
||||
|
||||
final Minecraft client = Minecraft.getInstance();
|
||||
final Level world = client.level;
|
||||
if (world == null) {
|
||||
final Level level = client.level;
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PoseStack matrixStack = event.getPoseStack();
|
||||
final PoseStack stack = event.getPoseStack();
|
||||
|
||||
final Camera activeRenderInfo = client.gameRenderer.getMainCamera();
|
||||
final Vec3 eye = activeRenderInfo.getPosition();
|
||||
|
||||
final Frustum frustum = new Frustum(matrixStack.last().pose(), event.getProjectionMatrix());
|
||||
final Frustum frustum = new Frustum(stack.last().pose(), event.getProjectionMatrix());
|
||||
frustum.prepare(eye.x, eye.y, eye.z);
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(-eye.x, -eye.y, -eye.z);
|
||||
stack.pushPose();
|
||||
stack.translate(-eye.x, -eye.y, -eye.z);
|
||||
|
||||
renderCables(world, matrixStack, eye, connections, frustum::isVisible);
|
||||
renderCables(level, stack, eye, connections, frustum::isVisible);
|
||||
|
||||
matrixStack.popPose();
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
private static void renderCables(final BlockAndTintGetter world, final PoseStack matrixStack, final Vec3 eye, final ArrayList<Connection> connections, final Predicate<AABB> filter) {
|
||||
final Matrix4f viewMatrix = matrixStack.last().pose();
|
||||
private static void renderCables(final BlockAndTintGetter level, final PoseStack stack, final Vec3 eye, final ArrayList<Connection> connections, final Predicate<AABB> filter) {
|
||||
final Matrix4f viewMatrix = stack.last().pose();
|
||||
|
||||
final RenderType renderType = ModRenderType.getNetworkCable();
|
||||
final MultiBufferSource.BufferSource bufferSource = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
@@ -176,7 +172,7 @@ public final class NetworkCableRenderer {
|
||||
computeCableSwingAmount(p0, p1),
|
||||
connection.hashCode());
|
||||
|
||||
final VertexConsumer buffer = bufferSource.getBuffer(renderType);
|
||||
final VertexConsumer consumer = bufferSource.getBuffer(renderType);
|
||||
|
||||
cablePoints.clear();
|
||||
cablePoints.ensureCapacity(CABLE_VERTEX_COUNT);
|
||||
@@ -186,8 +182,8 @@ public final class NetworkCableRenderer {
|
||||
final Vec3 n = getExtrusionVector(eye, p, connection.forward);
|
||||
|
||||
final BlockPos blockPos = new BlockPos(p);
|
||||
final int blockLight = world.getBrightness(LightLayer.BLOCK, blockPos);
|
||||
final int skyLight = world.getBrightness(LightLayer.SKY, blockPos);
|
||||
final int blockLight = level.getBrightness(LightLayer.BLOCK, blockPos);
|
||||
final int skyLight = level.getBrightness(LightLayer.SKY, blockPos);
|
||||
final int packedLight = LightTexture.pack(blockLight, skyLight);
|
||||
|
||||
final Vector3f v0 = new Vector3f(p.subtract(n));
|
||||
@@ -200,19 +196,19 @@ public final class NetworkCableRenderer {
|
||||
final CablePoint pa = cablePoints.get(i);
|
||||
final CablePoint pb = cablePoints.get(i + 1);
|
||||
|
||||
buffer.vertex(viewMatrix, pa.v0.x(), pa.v0.y(), pa.v0.z())
|
||||
consumer.vertex(viewMatrix, pa.v0.x(), pa.v0.y(), pa.v0.z())
|
||||
.color(r, g, b, 1f)
|
||||
.uv2(pa.packedLight)
|
||||
.endVertex();
|
||||
buffer.vertex(viewMatrix, pa.v1.x(), pa.v1.y(), pa.v1.z())
|
||||
consumer.vertex(viewMatrix, pa.v1.x(), pa.v1.y(), pa.v1.z())
|
||||
.color(r, g, b, 1f)
|
||||
.uv2(pa.packedLight)
|
||||
.endVertex();
|
||||
buffer.vertex(viewMatrix, pb.v1.x(), pb.v1.y(), pb.v1.z())
|
||||
consumer.vertex(viewMatrix, pb.v1.x(), pb.v1.y(), pb.v1.z())
|
||||
.color(r, g, b, 1f)
|
||||
.uv2(pa.packedLight)
|
||||
.endVertex();
|
||||
buffer.vertex(viewMatrix, pb.v0.x(), pb.v0.y(), pb.v0.z())
|
||||
consumer.vertex(viewMatrix, pb.v0.x(), pb.v0.y(), pb.v0.z())
|
||||
.color(r, g, b, 1f)
|
||||
.uv2(pa.packedLight)
|
||||
.endVertex();
|
||||
@@ -262,8 +258,8 @@ public final class NetworkCableRenderer {
|
||||
}
|
||||
|
||||
private static void validateConnectors() {
|
||||
final ArrayList<NetworkConnectorTileEntity> list = new ArrayList<>(connectors);
|
||||
for (final NetworkConnectorTileEntity connector : list) {
|
||||
final ArrayList<NetworkConnectorBlockEntity> list = new ArrayList<>(connectors);
|
||||
for (final NetworkConnectorBlockEntity connector : list) {
|
||||
if (connector.isRemoved()) {
|
||||
connectors.remove(connector);
|
||||
connectionsByConnector.remove(connector);
|
||||
@@ -289,7 +285,7 @@ public final class NetworkCableRenderer {
|
||||
connectionsByConnector.clear();
|
||||
|
||||
final HashSet<Connection> seen = new HashSet<>();
|
||||
for (final NetworkConnectorTileEntity connector : connectors) {
|
||||
for (final NetworkConnectorBlockEntity connector : connectors) {
|
||||
final BlockPos position = connector.getBlockPos();
|
||||
for (final BlockPos connectedPosition : connector.getConnectedPositions()) {
|
||||
final Connection connection = new Connection(position, connectedPosition);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package li.cil.oc2.client.renderer.tileentity;
|
||||
package li.cil.oc2.client.renderer.blockentity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.client.renderer.ModRenderType;
|
||||
import li.cil.oc2.common.tileentity.ChargerTileEntity;
|
||||
import li.cil.oc2.common.blockentity.ChargerBlockEntity;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
|
||||
public final class ChargerTileEntityRenderer implements BlockEntityRenderer<ChargerTileEntity> {
|
||||
public final class ChargerRenderer implements BlockEntityRenderer<ChargerBlockEntity> {
|
||||
public static final ResourceLocation EFFECT_LOCATION = new ResourceLocation(API.MOD_ID, "block/charger/effect");
|
||||
|
||||
private static final Material TEXTURE_EFFECT = new Material(InventoryMenu.BLOCK_ATLAS, EFFECT_LOCATION);
|
||||
@@ -31,60 +31,60 @@ public final class ChargerTileEntityRenderer implements BlockEntityRenderer<Char
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public ChargerTileEntityRenderer(final BlockEntityRendererProvider.Context ignored) {
|
||||
public ChargerRenderer(final BlockEntityRendererProvider.Context ignored) {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final ChargerTileEntity tileEntity, final float partialTicks, final PoseStack matrixStack, final MultiBufferSource buffer, final int light, final int overlay) {
|
||||
public void render(final ChargerBlockEntity charger, final float partialTicks, final PoseStack stack, final MultiBufferSource bufferSource, final int light, final int overlay) {
|
||||
offset = (offset + EFFECT_SPEED * partialTicks / 20f) % (float) (Math.PI * 2);
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0.5, 1.1, 0.5);
|
||||
stack.pushPose();
|
||||
stack.translate(0.5, 1.1, 0.5);
|
||||
|
||||
final VertexConsumer builder = TEXTURE_EFFECT.buffer(buffer, ModRenderType::getUnlitBlock);
|
||||
final VertexConsumer consumer = TEXTURE_EFFECT.buffer(bufferSource, ModRenderType::getUnlitBlock);
|
||||
|
||||
for (int i = 0; i < EFFECT_LAYERS; i++) {
|
||||
final float relativeY = (1 + Mth.sin(offset + ((float) Math.PI * 2f * i / EFFECT_LAYERS))) * 0.5f;
|
||||
final float y = relativeY * EFFECT_HEIGHT;
|
||||
final float scale = EFFECT_SCALE_START + relativeY * (EFFECT_SCALE_END - EFFECT_SCALE_START);
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0, y, 0);
|
||||
renderScaledQuad(matrixStack, builder, scale);
|
||||
matrixStack.popPose();
|
||||
stack.pushPose();
|
||||
stack.translate(0, y, 0);
|
||||
renderScaledQuad(stack, consumer, scale);
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
matrixStack.popPose();
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
private static void renderScaledQuad(final PoseStack matrixStack, final VertexConsumer builder, final float scale) {
|
||||
matrixStack.pushPose();
|
||||
matrixStack.scale(scale, scale, scale);
|
||||
renderQuad(matrixStack.last().pose(), builder);
|
||||
matrixStack.popPose();
|
||||
private static void renderScaledQuad(final PoseStack stack, final VertexConsumer consumer, final float scale) {
|
||||
stack.pushPose();
|
||||
stack.scale(scale, scale, scale);
|
||||
renderQuad(stack.last().pose(), consumer);
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
private static void renderQuad(final Matrix4f matrix, final VertexConsumer builder) {
|
||||
private static void renderQuad(final Matrix4f matrix, final VertexConsumer consumer) {
|
||||
// NB: We may get a SpriteAwareVertexBuilder here. Sadly, its chaining is broken,
|
||||
// because methods may return the underlying vertex builder, so e.g. calling
|
||||
// buffer.pos(...).tex(...) will not actually call SpriteAwareVertexBuilder.tex(...)
|
||||
// but SpriteAwareVertexBuilder.vertexBuilder.tex(...), skipping the UV remapping.
|
||||
builder.vertex(matrix, -0.5f, 0, -0.5f);
|
||||
builder.uv(0, 0);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, -0.5f, 0, -0.5f);
|
||||
consumer.uv(0, 0);
|
||||
consumer.endVertex();
|
||||
|
||||
builder.vertex(matrix, -0.5f, 0, 0.5f);
|
||||
builder.uv(0, 1);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, -0.5f, 0, 0.5f);
|
||||
consumer.uv(0, 1);
|
||||
consumer.endVertex();
|
||||
|
||||
builder.vertex(matrix, 0.5f, 0, 0.5f);
|
||||
builder.uv(1, 1);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, 0.5f, 0, 0.5f);
|
||||
consumer.uv(1, 1);
|
||||
consumer.endVertex();
|
||||
|
||||
builder.vertex(matrix, 0.5f, 0, -0.5f);
|
||||
builder.uv(1, 0);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, 0.5f, 0, -0.5f);
|
||||
consumer.uv(1, 0);
|
||||
consumer.endVertex();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.client.renderer.tileentity;
|
||||
package li.cil.oc2.client.renderer.blockentity;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
@@ -9,7 +9,7 @@ import com.mojang.math.Vector3f;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.client.renderer.ModRenderType;
|
||||
import li.cil.oc2.common.block.ComputerBlock;
|
||||
import li.cil.oc2.common.tileentity.ComputerTileEntity;
|
||||
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
@@ -27,7 +27,7 @@ import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class ComputerTileEntityRenderer implements BlockEntityRenderer<ComputerTileEntity> {
|
||||
public final class ComputerRenderer implements BlockEntityRenderer<ComputerBlockEntity> {
|
||||
public static final ResourceLocation OVERLAY_POWER_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_power");
|
||||
public static final ResourceLocation OVERLAY_STATUS_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_status");
|
||||
public static final ResourceLocation OVERLAY_TERMINAL_LOCATION = new ResourceLocation(API.MOD_ID, "block/computer/computer_overlay_terminal");
|
||||
@@ -42,88 +42,88 @@ public final class ComputerTileEntityRenderer implements BlockEntityRenderer<Com
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public ComputerTileEntityRenderer(final BlockEntityRendererProvider.Context context) {
|
||||
public ComputerRenderer(final BlockEntityRendererProvider.Context context) {
|
||||
this.renderer = context.getBlockEntityRenderDispatcher();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final ComputerTileEntity tileEntity, final float partialTicks, final PoseStack matrixStack, final MultiBufferSource buffer, final int light, final int overlay) {
|
||||
final Direction blockFacing = tileEntity.getBlockState().getValue(ComputerBlock.FACING);
|
||||
public void render(final ComputerBlockEntity computer, final float partialTicks, final PoseStack stack, final MultiBufferSource bufferSource, final int light, final int overlay) {
|
||||
final Direction blockFacing = computer.getBlockState().getValue(ComputerBlock.FACING);
|
||||
final Vec3 cameraPosition = renderer.camera.getEntity().getEyePosition(partialTicks);
|
||||
|
||||
// If viewer is not in front of the block we can skip all of the rest, it cannot be visible.
|
||||
// If viewer is not in front of the block we can skip the rest, it cannot be visible.
|
||||
// We check against the center of the block instead of the actual relevant face for simplicity.
|
||||
final Vec3 relativeCameraPosition = cameraPosition.subtract(Vec3.atCenterOf(tileEntity.getBlockPos()));
|
||||
final Vec3 relativeCameraPosition = cameraPosition.subtract(Vec3.atCenterOf(computer.getBlockPos()));
|
||||
final double projectedCameraPosition = relativeCameraPosition.dot(Vec3.atLowerCornerOf(blockFacing.getNormal()));
|
||||
if (projectedCameraPosition <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
matrixStack.pushPose();
|
||||
stack.pushPose();
|
||||
|
||||
// Align with front face of block.
|
||||
final Quaternion rotation = new Quaternion(Vector3f.YN, blockFacing.toYRot() + 180, true);
|
||||
matrixStack.translate(0.5f, 0, 0.5f);
|
||||
matrixStack.mulPose(rotation);
|
||||
matrixStack.translate(-0.5f, 0, -0.5f);
|
||||
stack.translate(0.5f, 0, 0.5f);
|
||||
stack.mulPose(rotation);
|
||||
stack.translate(-0.5f, 0, -0.5f);
|
||||
|
||||
// Flip and align with top left corner.
|
||||
matrixStack.translate(1, 1, 0);
|
||||
matrixStack.scale(-1, -1, -1);
|
||||
stack.translate(1, 1, 0);
|
||||
stack.scale(-1, -1, -1);
|
||||
|
||||
// Scale to make 1/16th of the block one unit and align with top left of terminal area.
|
||||
final float pixelScale = 1 / 16f;
|
||||
matrixStack.scale(pixelScale, pixelScale, pixelScale);
|
||||
stack.scale(pixelScale, pixelScale, pixelScale);
|
||||
|
||||
if (tileEntity.getVirtualMachine().isRunning()) {
|
||||
renderTerminal(tileEntity, matrixStack, buffer, cameraPosition);
|
||||
if (computer.getVirtualMachine().isRunning()) {
|
||||
renderTerminal(computer, stack, bufferSource, cameraPosition);
|
||||
} else {
|
||||
renderStatusText(tileEntity, matrixStack, cameraPosition);
|
||||
renderStatusText(computer, stack, cameraPosition);
|
||||
}
|
||||
|
||||
matrixStack.translate(0, 0, -0.1f);
|
||||
final Matrix4f matrix = matrixStack.last().pose();
|
||||
stack.translate(0, 0, -0.1f);
|
||||
final Matrix4f matrix = stack.last().pose();
|
||||
|
||||
switch (tileEntity.getVirtualMachine().getBusState()) {
|
||||
switch (computer.getVirtualMachine().getBusState()) {
|
||||
case SCAN_PENDING:
|
||||
case INCOMPLETE:
|
||||
renderStatus(matrix, buffer);
|
||||
renderStatus(matrix, bufferSource);
|
||||
break;
|
||||
case TOO_COMPLEX:
|
||||
renderStatus(matrix, buffer, 1000);
|
||||
renderStatus(matrix, bufferSource, 1000);
|
||||
break;
|
||||
case MULTIPLE_CONTROLLERS:
|
||||
renderStatus(matrix, buffer, 250);
|
||||
renderStatus(matrix, bufferSource, 250);
|
||||
break;
|
||||
case READY:
|
||||
switch (tileEntity.getVirtualMachine().getRunState()) {
|
||||
switch (computer.getVirtualMachine().getRunState()) {
|
||||
case STOPPED:
|
||||
break;
|
||||
case LOADING_DEVICES:
|
||||
renderStatus(matrix, buffer);
|
||||
renderStatus(matrix, bufferSource);
|
||||
break;
|
||||
case RUNNING:
|
||||
renderPower(matrix, buffer);
|
||||
renderPower(matrix, bufferSource);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
matrixStack.popPose();
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private void renderTerminal(final ComputerTileEntity tileEntity, final PoseStack stack, final MultiBufferSource buffer, final Vec3 cameraPosition) {
|
||||
private void renderTerminal(final ComputerBlockEntity computer, final PoseStack stack, final MultiBufferSource bufferSource, final Vec3 cameraPosition) {
|
||||
// Render terminal content if close enough.
|
||||
if (Vec3.atCenterOf(tileEntity.getBlockPos()).closerThan(cameraPosition, 6f)) {
|
||||
if (Vec3.atCenterOf(computer.getBlockPos()).closerThan(cameraPosition, 6f)) {
|
||||
stack.pushPose();
|
||||
stack.translate(2, 2, -0.9f);
|
||||
|
||||
// Scale to make terminal fit fully.
|
||||
final Terminal terminal = tileEntity.getTerminal();
|
||||
final Terminal terminal = computer.getTerminal();
|
||||
final float textScaleX = 12f / terminal.getWidth();
|
||||
final float textScaleY = 7f / terminal.getHeight();
|
||||
final float scale = Math.min(textScaleX, textScaleY) * 0.95f;
|
||||
@@ -150,18 +150,18 @@ public final class ComputerTileEntityRenderer implements BlockEntityRenderer<Com
|
||||
stack.translate(0, 0, -0.9f);
|
||||
|
||||
final Matrix4f matrix = stack.last().pose();
|
||||
renderQuad(matrix, TEXTURE_TERMINAL.buffer(buffer, ModRenderType::getUnlitBlock));
|
||||
renderQuad(matrix, TEXTURE_TERMINAL.buffer(bufferSource, ModRenderType::getUnlitBlock));
|
||||
|
||||
stack.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
private void renderStatusText(final ComputerTileEntity tileEntity, final PoseStack stack, final Vec3 cameraPosition) {
|
||||
if (!Vec3.atCenterOf(tileEntity.getBlockPos()).closerThan(cameraPosition, 12f)) {
|
||||
private void renderStatusText(final ComputerBlockEntity computer, final PoseStack stack, final Vec3 cameraPosition) {
|
||||
if (!Vec3.atCenterOf(computer.getBlockPos()).closerThan(cameraPosition, 12f)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Component bootError = tileEntity.getVirtualMachine().getBootError();
|
||||
final Component bootError = computer.getVirtualMachine().getBootError();
|
||||
if (bootError == null) {
|
||||
return;
|
||||
}
|
||||
@@ -194,39 +194,39 @@ public final class ComputerTileEntityRenderer implements BlockEntityRenderer<Com
|
||||
stack.popPose();
|
||||
}
|
||||
|
||||
private void renderStatus(final Matrix4f matrix, final MultiBufferSource buffer) {
|
||||
renderStatus(matrix, buffer, 0);
|
||||
private void renderStatus(final Matrix4f matrix, final MultiBufferSource bufferSource) {
|
||||
renderStatus(matrix, bufferSource, 0);
|
||||
}
|
||||
|
||||
private void renderStatus(final Matrix4f matrix, final MultiBufferSource buffer, final int frequency) {
|
||||
private void renderStatus(final Matrix4f matrix, final MultiBufferSource bufferSource, final int frequency) {
|
||||
if (frequency <= 0 || (((System.currentTimeMillis() + hashCode()) / frequency) % 2) == 1) {
|
||||
renderQuad(matrix, TEXTURE_STATUS.buffer(buffer, ModRenderType::getUnlitBlock));
|
||||
renderQuad(matrix, TEXTURE_STATUS.buffer(bufferSource, ModRenderType::getUnlitBlock));
|
||||
}
|
||||
}
|
||||
|
||||
private void renderPower(final Matrix4f matrix, final MultiBufferSource buffer) {
|
||||
renderQuad(matrix, TEXTURE_POWER.buffer(buffer, ModRenderType::getUnlitBlock));
|
||||
private void renderPower(final Matrix4f matrix, final MultiBufferSource bufferSource) {
|
||||
renderQuad(matrix, TEXTURE_POWER.buffer(bufferSource, ModRenderType::getUnlitBlock));
|
||||
}
|
||||
|
||||
private static void renderQuad(final Matrix4f matrix, final VertexConsumer builder) {
|
||||
private static void renderQuad(final Matrix4f matrix, final VertexConsumer consumer) {
|
||||
// NB: We may get a SpriteAwareVertexBuilder here. Sadly, its chaining is broken,
|
||||
// because methods may return the underlying vertex builder, so e.g. calling
|
||||
// buffer.pos(...).tex(...) will not actually call SpriteAwareVertexBuilder.tex(...)
|
||||
// but SpriteAwareVertexBuilder.vertexBuilder.tex(...), skipping the UV remapping.
|
||||
builder.vertex(matrix, 0, 0, 0);
|
||||
builder.uv(0, 0);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, 0, 0, 0);
|
||||
consumer.uv(0, 0);
|
||||
consumer.endVertex();
|
||||
|
||||
builder.vertex(matrix, 0, 16, 0);
|
||||
builder.uv(0, 1);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, 0, 16, 0);
|
||||
consumer.uv(0, 1);
|
||||
consumer.endVertex();
|
||||
|
||||
builder.vertex(matrix, 16, 16, 0);
|
||||
builder.uv(1, 1);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, 16, 16, 0);
|
||||
consumer.uv(1, 1);
|
||||
consumer.endVertex();
|
||||
|
||||
builder.vertex(matrix, 16, 0, 0);
|
||||
builder.uv(1, 0);
|
||||
builder.endVertex();
|
||||
consumer.vertex(matrix, 16, 0, 0);
|
||||
consumer.uv(1, 0);
|
||||
consumer.endVertex();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package li.cil.oc2.client.renderer.blockentity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import li.cil.oc2.common.block.DiskDriveBlock;
|
||||
import li.cil.oc2.common.blockentity.DiskDriveBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class DiskDriveRenderer implements BlockEntityRenderer<DiskDriveBlockEntity> {
|
||||
private final BlockEntityRenderDispatcher renderer;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public DiskDriveRenderer(final BlockEntityRendererProvider.Context context) {
|
||||
this.renderer = context.getBlockEntityRenderDispatcher();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final DiskDriveBlockEntity diskDrive, final float partialTicks, final PoseStack stack, final MultiBufferSource bufferSource, final int light, final int overlay) {
|
||||
final ItemStack floppy = diskDrive.getFloppy();
|
||||
final Direction blockFacing = diskDrive.getBlockState().getValue(DiskDriveBlock.FACING);
|
||||
final int neighborLight = LevelRenderer.getLightColor(renderer.level, diskDrive.getBlockPos().relative(blockFacing));
|
||||
final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
|
||||
|
||||
stack.pushPose();
|
||||
|
||||
stack.translate(0.5f, 0.5f, 0.5f);
|
||||
stack.mulPose(Vector3f.YN.rotationDegrees(blockFacing.toYRot()));
|
||||
stack.translate(0.0f, 0.0f, 0.5f);
|
||||
stack.mulPose(Vector3f.XN.rotationDegrees(90));
|
||||
stack.translate(0.0f, 0.2375f, 2.5f / 16f);
|
||||
stack.scale(0.55f, 0.55f, 0.55f);
|
||||
|
||||
itemRenderer.renderStatic(floppy, ItemTransforms.TransformType.FIXED, neighborLight, overlay, stack, bufferSource, (int) diskDrive.getBlockPos().asLong());
|
||||
|
||||
stack.popPose();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package li.cil.oc2.client.renderer.tileentity;
|
||||
package li.cil.oc2.client.renderer.blockentity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import li.cil.oc2.client.renderer.NetworkCableRenderer;
|
||||
import li.cil.oc2.common.tileentity.NetworkConnectorTileEntity;
|
||||
import li.cil.oc2.common.blockentity.NetworkConnectorBlockEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
@@ -10,20 +10,20 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
public final class NetworkConnectorTileEntityRenderer implements BlockEntityRenderer<NetworkConnectorTileEntity> {
|
||||
public final class NetworkConnectorRenderer implements BlockEntityRenderer<NetworkConnectorBlockEntity> {
|
||||
private final BlockEntityRenderDispatcher renderer;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public NetworkConnectorTileEntityRenderer(final BlockEntityRendererProvider.Context context) {
|
||||
public NetworkConnectorRenderer(final BlockEntityRendererProvider.Context context) {
|
||||
this.renderer = context.getBlockEntityRenderDispatcher();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final NetworkConnectorTileEntity connector, final float partialTicks, final PoseStack matrixStack, final MultiBufferSource buffer, final int light, final int overlay) {
|
||||
// We do cable rendering as a fall-back in the TESR when Fabulous rendering is enabled.
|
||||
public void render(final NetworkConnectorBlockEntity connector, final float partialTicks, final PoseStack stack, final MultiBufferSource bufferSource, final int light, final int overlay) {
|
||||
// We do cable rendering as a fall-back in the TER when Fabulous rendering is enabled.
|
||||
// We need to do this because there's no hook to render before the Fabulous full-screen
|
||||
// effects are rendered, which, sadly, completely ruin the depth buffer for us.
|
||||
if (!Minecraft.useShaderTransparency()) {
|
||||
@@ -32,11 +32,11 @@ public final class NetworkConnectorTileEntityRenderer implements BlockEntityRend
|
||||
|
||||
final BlockPos from = connector.getBlockPos();
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(-from.getX(), -from.getY(), -from.getZ());
|
||||
stack.pushPose();
|
||||
stack.translate(-from.getX(), -from.getY(), -from.getZ());
|
||||
|
||||
NetworkCableRenderer.renderCablesFor(renderer.level, matrixStack, renderer.camera.getPosition(), connector);
|
||||
NetworkCableRenderer.renderCablesFor(renderer.level, stack, renderer.camera.getPosition(), connector);
|
||||
|
||||
matrixStack.popPose();
|
||||
stack.popPose();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package li.cil.oc2.client.renderer.tileentity;
|
||||
package li.cil.oc2.client.renderer.blockentity;
|
||||
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package li.cil.oc2.client.renderer.color;
|
||||
|
||||
import li.cil.oc2.common.tileentity.BusCableTileEntity;
|
||||
import li.cil.oc2.common.blockentity.BusCableBlockEntity;
|
||||
import li.cil.oc2.common.util.ItemStackUtils;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -22,8 +22,8 @@ public final class BusCableBlockColor implements BlockColor {
|
||||
}
|
||||
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof BusCableTileEntity) {
|
||||
final BlockState facade = ItemStackUtils.getBlockState(((BusCableTileEntity) blockEntity).getFacade());
|
||||
if (blockEntity instanceof BusCableBlockEntity) {
|
||||
final BlockState facade = ItemStackUtils.getBlockState(((BusCableBlockEntity) blockEntity).getFacade());
|
||||
if (facade != null) {
|
||||
return Minecraft.getInstance().getBlockColors().getColor(facade, level, pos, tintIndex);
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public final class RobotEntityRenderer extends EntityRenderer<RobotEntity> {
|
||||
public final class RobotRenderer extends EntityRenderer<RobotEntity> {
|
||||
private final RobotModel model;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public RobotEntityRenderer(final EntityRendererProvider.Context context) {
|
||||
public RobotRenderer(final EntityRendererProvider.Context context) {
|
||||
super(context);
|
||||
model = new RobotModel(context.bakeLayer(RobotModel.ROBOT_MODEL_LAYER));
|
||||
}
|
||||
@@ -30,24 +30,24 @@ public final class RobotEntityRenderer extends EntityRenderer<RobotEntity> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final RobotEntity entity, final float entityYaw, final float partialTicks, final PoseStack matrixStack, final MultiBufferSource buffer, final int packedLight) {
|
||||
public void render(final RobotEntity entity, final float entityYaw, final float partialTicks, final PoseStack stack, final MultiBufferSource bufferSource, final int packedLight) {
|
||||
final RobotEntity.AnimationState state = entity.getAnimationState();
|
||||
state.update(partialTicks, entity.level.random);
|
||||
|
||||
matrixStack.pushPose();
|
||||
stack.pushPose();
|
||||
// NB: we don't entityYaw given to use because that uses a plain lerp which can lead to ugly
|
||||
// jumps in case we get a wrapped rotationYaw synced from the server (leading to ~360
|
||||
// degree delta to the last known previous rotation). Haven't figured out where to
|
||||
// alternatively prevent this wrapping or patch the prev value instead.
|
||||
final float partialRotation = Mth.degreesDifferenceAbs(entity.yRotO, entity.getYRot()) * partialTicks;
|
||||
final float rotation = Mth.approachDegrees(entity.yRotO, entity.getYRot(), partialRotation);
|
||||
matrixStack.mulPose(Vector3f.YN.rotationDegrees(rotation));
|
||||
stack.mulPose(Vector3f.YN.rotationDegrees(rotation));
|
||||
|
||||
model.setupAnim(entity, 0, 0, 0, 0, 0);
|
||||
|
||||
final VertexConsumer builder = buffer.getBuffer(model.renderType(getTextureLocation(entity)));
|
||||
model.renderToBuffer(matrixStack, builder, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
|
||||
final VertexConsumer consumer = bufferSource.getBuffer(model.renderType(getTextureLocation(entity)));
|
||||
model.renderToBuffer(stack, consumer, packedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
|
||||
|
||||
matrixStack.popPose();
|
||||
stack.popPose();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.client.renderer.tileentity;
|
||||
package li.cil.oc2.client.renderer.entity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
@@ -11,12 +11,12 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class RobotItemStackRenderer extends BlockEntityWithoutLevelRenderer {
|
||||
public final class RobotWithoutLevelRenderer extends BlockEntityWithoutLevelRenderer {
|
||||
private final RobotModel model;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public RobotItemStackRenderer(final BlockEntityRenderDispatcher dispatcher, final EntityModelSet modelSet) {
|
||||
public RobotWithoutLevelRenderer(final BlockEntityRenderDispatcher dispatcher, final EntityModelSet modelSet) {
|
||||
super(dispatcher, modelSet);
|
||||
model = new RobotModel(modelSet.bakeLayer(RobotModel.ROBOT_MODEL_LAYER));
|
||||
}
|
||||
@@ -24,14 +24,14 @@ public final class RobotItemStackRenderer extends BlockEntityWithoutLevelRendere
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void renderByItem(final ItemStack stack, final ItemTransforms.TransformType transformType, final PoseStack matrixStack, final MultiBufferSource buffer, final int combinedLight, final int combinedOverlay) {
|
||||
matrixStack.pushPose();
|
||||
public void renderByItem(final ItemStack itemStack, final ItemTransforms.TransformType transformType, final PoseStack poseStack, final MultiBufferSource bufferSource, final int combinedLight, final int combinedOverlay) {
|
||||
poseStack.pushPose();
|
||||
|
||||
matrixStack.translate(0.5, 0, 0.5);
|
||||
poseStack.translate(0.5, 0, 0.5);
|
||||
|
||||
final VertexConsumer builder = buffer.getBuffer(model.renderType(RobotModel.ROBOT_ENTITY_TEXTURE));
|
||||
model.renderToBuffer(matrixStack, builder, combinedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
|
||||
final VertexConsumer consumer = bufferSource.getBuffer(model.renderType(RobotModel.ROBOT_ENTITY_TEXTURE));
|
||||
model.renderToBuffer(poseStack, consumer, combinedLight, OverlayTexture.NO_OVERLAY, 1, 1, 1, 1);
|
||||
|
||||
matrixStack.popPose();
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
@@ -65,17 +65,17 @@ public final class RobotModel extends EntityModel<RobotEntity> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderToBuffer(final PoseStack matrixStack, final VertexConsumer buffer, final int packedLight, final int packedOverlay, final float red, final float green, final float blue, final float alpha) {
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0, topY, 0);
|
||||
matrixStack.mulPose(TransformationHelper.quatFromXYZ(topRotation, true));
|
||||
topRenderer.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
matrixStack.popPose();
|
||||
public void renderToBuffer(final PoseStack stack, final VertexConsumer consumer, final int packedLight, final int packedOverlay, final float red, final float green, final float blue, final float alpha) {
|
||||
stack.pushPose();
|
||||
stack.translate(0, topY, 0);
|
||||
stack.mulPose(TransformationHelper.quatFromXYZ(topRotation, true));
|
||||
topRenderer.render(stack, consumer, packedLight, packedOverlay);
|
||||
stack.popPose();
|
||||
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(0, baseY, 0);
|
||||
baseRenderer.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
coreRenderer.render(matrixStack, buffer, LightTexture.pack(15, 15), packedOverlay);
|
||||
matrixStack.popPose();
|
||||
stack.pushPose();
|
||||
stack.translate(0, baseY, 0);
|
||||
baseRenderer.render(stack, consumer, packedLight, packedOverlay);
|
||||
coreRenderer.render(stack, consumer, LightTexture.pack(15, 15), packedOverlay);
|
||||
stack.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package li.cil.oc2.client.renderer.tileentity;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Vector3f;
|
||||
import li.cil.oc2.common.block.DiskDriveBlock;
|
||||
import li.cil.oc2.common.tileentity.DiskDriveTileEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class DiskDriveTileEntityRenderer implements BlockEntityRenderer<DiskDriveTileEntity> {
|
||||
private final BlockEntityRenderDispatcher renderer;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public DiskDriveTileEntityRenderer(final BlockEntityRendererProvider.Context context) {
|
||||
this.renderer = context.getBlockEntityRenderDispatcher();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void render(final DiskDriveTileEntity tileEntity, final float partialTicks, final PoseStack matrixStack, final MultiBufferSource buffer, final int light, final int overlay) {
|
||||
final ItemStack stack = tileEntity.getFloppy();
|
||||
final Direction blockFacing = tileEntity.getBlockState().getValue(DiskDriveBlock.FACING);
|
||||
final int neighborLight = LevelRenderer.getLightColor(renderer.level, tileEntity.getBlockPos().relative(blockFacing));
|
||||
final ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
|
||||
|
||||
matrixStack.pushPose();
|
||||
|
||||
matrixStack.translate(0.5f, 0.5f, 0.5f);
|
||||
matrixStack.mulPose(Vector3f.YN.rotationDegrees(blockFacing.toYRot()));
|
||||
matrixStack.translate(0.0f, 0.0f, 0.5f);
|
||||
matrixStack.mulPose(Vector3f.XN.rotationDegrees(90));
|
||||
matrixStack.translate(0.0f, 0.2375f, 2.5f / 16f);
|
||||
matrixStack.scale(0.55f, 0.55f, 0.55f);
|
||||
|
||||
itemRenderer.renderStatic(stack, ItemTransforms.TransformType.FIXED, neighborLight, overlay, matrixStack, buffer, (int) tileEntity.getBlockPos().asLong());
|
||||
|
||||
matrixStack.popPose();
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import li.cil.oc2.common.item.crafting.RecipeSerializers;
|
||||
import li.cil.oc2.common.serialization.serializers.Serializers;
|
||||
import li.cil.oc2.common.tags.BlockTags;
|
||||
import li.cil.oc2.common.tags.ItemTags;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.util.RegistryUtils;
|
||||
import li.cil.oc2.common.util.SoundEvents;
|
||||
import li.cil.sedna.Sedna;
|
||||
@@ -41,7 +41,7 @@ public final class Main {
|
||||
BlockTags.initialize();
|
||||
Blocks.initialize();
|
||||
Items.initialize();
|
||||
TileEntities.initialize();
|
||||
BlockEntities.initialize();
|
||||
Entities.initialize();
|
||||
Containers.initialize();
|
||||
RecipeSerializers.initialize();
|
||||
|
||||
@@ -5,40 +5,44 @@ import li.cil.oc2.client.gui.BusInterfaceScreen;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.integration.Wrenches;
|
||||
import li.cil.oc2.common.item.Items;
|
||||
import li.cil.oc2.common.tileentity.BusCableTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.BusCableBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.util.ItemStackUtils;
|
||||
import li.cil.oc2.common.util.WorldUtils;
|
||||
import li.cil.oc2.common.util.LevelUtils;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -50,11 +54,6 @@ import java.util.Map;
|
||||
|
||||
import static li.cil.oc2.common.util.TranslationUtils.text;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
||||
public final class BusCableBlock extends BaseEntityBlock {
|
||||
public enum ConnectionType implements StringRepresentable {
|
||||
NONE,
|
||||
@@ -63,16 +62,11 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
|
||||
@Override
|
||||
public String getSerializedName() {
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return "none";
|
||||
case CABLE:
|
||||
return "cable";
|
||||
case INTERFACE:
|
||||
return "interface";
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return switch (this) {
|
||||
case NONE -> "none";
|
||||
case CABLE -> "cable";
|
||||
case INTERFACE -> "interface";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +138,7 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static boolean addInterface(final Level world, final BlockPos pos, final BlockState state, final Direction side) {
|
||||
public static boolean addInterface(final Level level, final BlockPos pos, final BlockState state, final Direction side) {
|
||||
if (state.getBlock() != Blocks.BUS_CABLE.get()) {
|
||||
return false;
|
||||
}
|
||||
@@ -158,14 +152,14 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
return false;
|
||||
}
|
||||
|
||||
world.setBlock(pos, state.setValue(property, ConnectionType.INTERFACE), Block.UPDATE_ALL_IMMEDIATE);
|
||||
level.setBlock(pos, state.setValue(property, ConnectionType.INTERFACE), Block.UPDATE_ALL_IMMEDIATE);
|
||||
|
||||
onConnectionTypeChanged(world, pos, side);
|
||||
onConnectionTypeChanged(level, pos, side);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean addCable(final Level world, final BlockPos pos, final BlockState state) {
|
||||
public static boolean addCable(final Level level, final BlockPos pos, final BlockState state) {
|
||||
if (state.getBlock() != Blocks.BUS_CABLE.get()) {
|
||||
return false;
|
||||
}
|
||||
@@ -174,101 +168,99 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
return false;
|
||||
}
|
||||
|
||||
world.setBlock(pos, state.setValue(HAS_CABLE, true), Block.UPDATE_ALL_IMMEDIATE);
|
||||
level.setBlock(pos, state.setValue(HAS_CABLE, true), Block.UPDATE_ALL_IMMEDIATE);
|
||||
|
||||
onConnectionTypeChanged(world, pos, null);
|
||||
onConnectionTypeChanged(level, pos, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setHasFacade(final Level world, final BlockPos pos, final BlockState state, @Nullable final BlockState facadeState, final boolean value) {
|
||||
public static void setHasFacade(final Level level, final BlockPos pos, final BlockState state, @Nullable final BlockState facadeState, final boolean value) {
|
||||
if (state.getValue(HAS_FACADE) == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
world.setBlock(pos, state.setValue(HAS_FACADE, value), Block.UPDATE_ALL_IMMEDIATE);
|
||||
level.setBlock(pos, state.setValue(HAS_FACADE, value), Block.UPDATE_ALL_IMMEDIATE);
|
||||
|
||||
final BlockState soundsSource = facadeState != null ? facadeState : state;
|
||||
WorldUtils.playSound(world, pos, soundsSource.getSoundType(), value ? SoundType::getPlaceSound : SoundType::getBreakSound);
|
||||
LevelUtils.playSound(level, pos, soundsSource.getSoundType(), value ? SoundType::getPlaceSound : SoundType::getBreakSound);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void neighborChanged(final BlockState state, final Level world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (tileEntity instanceof BusCableTileEntity) {
|
||||
final BusCableTileEntity busCable = (BusCableTileEntity) tileEntity;
|
||||
public void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof final BusCableBlockEntity busCable) {
|
||||
busCable.handleNeighborChanged(changedBlockPos);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public InteractionResult use(final BlockState state, final Level world, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
|
||||
public InteractionResult use(final BlockState state, final Level level, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
|
||||
final ItemStack heldItem = player.getItemInHand(hand);
|
||||
if (heldItem.getItem() == Items.BUS_CABLE.get() ||
|
||||
heldItem.getItem() == Items.BUS_INTERFACE.get()) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (!(tileEntity instanceof BusCableTileEntity)) {
|
||||
return super.use(state, world, pos, player, hand, hit);
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof final BusCableBlockEntity busCableBlockEntity)) {
|
||||
return super.use(state, level, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
final BusCableTileEntity busCableTileEntity = (BusCableTileEntity) tileEntity;
|
||||
|
||||
if (Wrenches.isWrench(heldItem)) {
|
||||
if (player.isShiftKeyDown()) {
|
||||
final ItemStack facadeItem = busCableTileEntity.getFacade();
|
||||
final ItemStack facadeItem = busCableBlockEntity.getFacade();
|
||||
if (!facadeItem.isEmpty()) {
|
||||
if (!world.isClientSide()) {
|
||||
busCableTileEntity.removeFacade();
|
||||
if (!player.isCreative() && world.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) {
|
||||
ItemStackUtils.spawnAsEntity(world, pos, facadeItem, hit.getDirection()).ifPresent(entity -> {
|
||||
if (!level.isClientSide()) {
|
||||
busCableBlockEntity.removeFacade();
|
||||
if (!player.isCreative() && level.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) {
|
||||
ItemStackUtils.spawnAsEntity(level, pos, facadeItem, hit.getDirection()).ifPresent(entity -> {
|
||||
entity.setNoPickUpDelay();
|
||||
entity.playerTouch(player);
|
||||
});
|
||||
}
|
||||
}
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
} else {
|
||||
// NB: leave wrenching logic up to wrench when the to-be-removed interface is the last
|
||||
// part of this bus. This ensures we properly remove the block itself without having
|
||||
// to duplicate the logic needed for that.
|
||||
if (getPartCount(state) > 1 && (tryRemovePlug(state, world, pos, player, hit) || tryRemoveCable(state, world, pos, player))) {
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
if (getPartCount(state) > 1 && (tryRemovePlug(state, level, pos, player, hit) || tryRemoveCable(state, level, pos, player))) {
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
}
|
||||
} else if (world.isClientSide()) {
|
||||
} else if (level.isClientSide()) {
|
||||
final Direction side = getHitSide(pos, hit);
|
||||
if (getConnectionType(state, side) == ConnectionType.INTERFACE) {
|
||||
openBusInterfaceScreen(busCableTileEntity, side);
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
openBusInterfaceScreen(busCableBlockEntity, side);
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
}
|
||||
} else if (!player.isShiftKeyDown() && !state.getValue(HAS_FACADE) && getInterfaceCount(state) == 0) {
|
||||
switch (busCableTileEntity.getFacadeType(heldItem)) {
|
||||
case INVALID_BLOCK:
|
||||
if (!world.isClientSide()) {
|
||||
switch (busCableBlockEntity.getFacadeType(heldItem)) {
|
||||
case INVALID_BLOCK -> {
|
||||
if (!level.isClientSide()) {
|
||||
player.displayClientMessage(text("message.{mod}.invalid_facade_block"), true);
|
||||
}
|
||||
|
||||
// Always return success (even on failure) to avoid accidentally placing blocks.
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
case VALID_BLOCK:
|
||||
if (!world.isClientSide()) {
|
||||
busCableTileEntity.setFacade(heldItem);
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
case VALID_BLOCK -> {
|
||||
if (!level.isClientSide()) {
|
||||
busCableBlockEntity.setFacade(heldItem);
|
||||
if (!player.getAbilities().instabuild) {
|
||||
heldItem.shrink(1);
|
||||
}
|
||||
}
|
||||
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.use(state, world, pos, player, hand, hit);
|
||||
return super.use(state, level, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -277,9 +269,9 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
final List<ItemStack> drops = new ArrayList<>(super.getDrops(state, builder));
|
||||
|
||||
if (state.getValue(HAS_FACADE)) {
|
||||
final BlockEntity tileEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
|
||||
if (tileEntity instanceof BusCableTileEntity) {
|
||||
final ItemStack stack = ((BusCableTileEntity) tileEntity).getFacade();
|
||||
final BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
|
||||
if (blockEntity instanceof BusCableBlockEntity busCable) {
|
||||
final ItemStack stack = busCable.getFacade();
|
||||
if (!stack.isEmpty()) {
|
||||
drops.add(stack);
|
||||
}
|
||||
@@ -309,13 +301,13 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
||||
BlockState state = defaultBlockState();
|
||||
|
||||
final Level world = context.getLevel();
|
||||
final Level level = context.getLevel();
|
||||
final BlockPos position = context.getClickedPos();
|
||||
for (final Map.Entry<Direction, EnumProperty<ConnectionType>> entry : FACING_TO_CONNECTION_MAP.entrySet()) {
|
||||
final Direction facing = entry.getKey();
|
||||
final BlockPos facingPos = position.relative(facing);
|
||||
if (context.getItemInHand().getItem() == Items.BUS_CABLE.get() &&
|
||||
canHaveCableTo(world.getBlockState(facingPos), facing.getOpposite())) {
|
||||
canHaveCableTo(level.getBlockState(facingPos), facing.getOpposite())) {
|
||||
state = state.setValue(entry.getValue(), ConnectionType.CABLE);
|
||||
}
|
||||
}
|
||||
@@ -325,7 +317,7 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public BlockState updateShape(BlockState state, final Direction facing, final BlockState facingState, final LevelAccessor world, final BlockPos currentPos, final BlockPos facingPos) {
|
||||
public BlockState updateShape(BlockState state, final Direction facing, final BlockState facingState, final LevelAccessor level, final BlockPos currentPos, final BlockPos facingPos) {
|
||||
if (state.getValue(FACING_TO_CONNECTION_MAP.get(facing)) == ConnectionType.INTERFACE) {
|
||||
return state;
|
||||
}
|
||||
@@ -336,14 +328,14 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
state = state.setValue(FACING_TO_CONNECTION_MAP.get(facing), ConnectionType.NONE);
|
||||
}
|
||||
|
||||
onConnectionTypeChanged(world, currentPos, facing);
|
||||
onConnectionTypeChanged(level, currentPos, facing);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public VoxelShape getShape(final BlockState state, final BlockGetter world, final BlockPos pos, final CollisionContext context) {
|
||||
public VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
||||
if (state.getValue(HAS_FACADE)) {
|
||||
return Shapes.block();
|
||||
}
|
||||
@@ -353,14 +345,12 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
|
||||
@Override
|
||||
public ItemStack getCloneItemStack(final BlockState state, final HitResult hit, final BlockGetter level, final BlockPos pos, final Player player) {
|
||||
final BlockEntity tileEntity = level.getBlockEntity(pos);
|
||||
if (!(tileEntity instanceof BusCableTileEntity)) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof final BusCableBlockEntity busCable)) {
|
||||
return super.getCloneItemStack(state, hit, level, pos, player);
|
||||
}
|
||||
|
||||
final BusCableTileEntity busCableTileEntity = (BusCableTileEntity) tileEntity;
|
||||
|
||||
final ItemStack facadeItem = busCableTileEntity.getFacade();
|
||||
final ItemStack facadeItem = busCable.getFacade();
|
||||
if (!facadeItem.isEmpty()) {
|
||||
return facadeItem;
|
||||
}
|
||||
@@ -381,7 +371,7 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.BUS_CABLE_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.BUS_CABLE.get().create(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -415,7 +405,7 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
return partCount;
|
||||
}
|
||||
|
||||
private static boolean tryRemovePlug(final BlockState state, final Level world, final BlockPos pos, final Player player, final BlockHitResult hit) {
|
||||
private static boolean tryRemovePlug(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hit) {
|
||||
final Direction side = getHitSide(pos, hit);
|
||||
final EnumProperty<ConnectionType> property = FACING_TO_CONNECTION_MAP.get(side);
|
||||
|
||||
@@ -424,53 +414,52 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
}
|
||||
|
||||
final BlockPos neighborPos = pos.relative(side);
|
||||
if (state.getValue(HAS_CABLE) && canHaveCableTo(world.getBlockState(neighborPos), side.getOpposite())) {
|
||||
world.setBlockAndUpdate(pos, state.setValue(property, ConnectionType.CABLE));
|
||||
if (state.getValue(HAS_CABLE) && canHaveCableTo(level.getBlockState(neighborPos), side.getOpposite())) {
|
||||
level.setBlockAndUpdate(pos, state.setValue(property, ConnectionType.CABLE));
|
||||
} else {
|
||||
world.setBlockAndUpdate(pos, state.setValue(property, ConnectionType.NONE));
|
||||
level.setBlockAndUpdate(pos, state.setValue(property, ConnectionType.NONE));
|
||||
}
|
||||
|
||||
handlePartRemoved(state, world, pos, side, player, new ItemStack(Items.BUS_INTERFACE.get()));
|
||||
handlePartRemoved(state, level, pos, side, player, new ItemStack(Items.BUS_INTERFACE.get()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean tryRemoveCable(final BlockState state, final Level world, final BlockPos pos, final Player player) {
|
||||
private static boolean tryRemoveCable(final BlockState state, final Level level, final BlockPos pos, final Player player) {
|
||||
if (!state.getValue(HAS_CABLE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
world.setBlockAndUpdate(pos, state.setValue(HAS_CABLE, false));
|
||||
level.setBlockAndUpdate(pos, state.setValue(HAS_CABLE, false));
|
||||
|
||||
handlePartRemoved(state, world, pos, null, player, new ItemStack(Items.BUS_CABLE.get()));
|
||||
handlePartRemoved(state, level, pos, null, player, new ItemStack(Items.BUS_CABLE.get()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void handlePartRemoved(final BlockState state, final Level world, final BlockPos pos, @Nullable final Direction side, final Player player, final ItemStack drop) {
|
||||
onConnectionTypeChanged(world, pos, side);
|
||||
private static void handlePartRemoved(final BlockState state, final Level level, final BlockPos pos, @Nullable final Direction side, final Player player, final ItemStack drop) {
|
||||
onConnectionTypeChanged(level, pos, side);
|
||||
|
||||
if (!player.isCreative() && world.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) {
|
||||
ItemStackUtils.spawnAsEntity(world, pos, drop, side).ifPresent(entity -> {
|
||||
if (!player.isCreative() && level.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) {
|
||||
ItemStackUtils.spawnAsEntity(level, pos, drop, side).ifPresent(entity -> {
|
||||
entity.setNoPickUpDelay();
|
||||
entity.playerTouch(player);
|
||||
});
|
||||
}
|
||||
|
||||
WorldUtils.playSound(world, pos, state.getSoundType(), SoundType::getBreakSound);
|
||||
LevelUtils.playSound(level, pos, state.getSoundType(), SoundType::getBreakSound);
|
||||
}
|
||||
|
||||
private static void onConnectionTypeChanged(final LevelAccessor world, final BlockPos pos, @Nullable final Direction face) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (tileEntity instanceof BusCableTileEntity) {
|
||||
final BusCableTileEntity busCable = (BusCableTileEntity) tileEntity;
|
||||
private static void onConnectionTypeChanged(final LevelAccessor level, final BlockPos pos, @Nullable final Direction face) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof final BusCableBlockEntity busCable) {
|
||||
busCable.handleConnectivityChanged(face);
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private static void openBusInterfaceScreen(final BusCableTileEntity tileEntity, final Direction side) {
|
||||
final BusInterfaceScreen screen = new BusInterfaceScreen(tileEntity, side);
|
||||
private static void openBusInterfaceScreen(final BusCableBlockEntity blockEntity, final Direction side) {
|
||||
final BusInterfaceScreen screen = new BusInterfaceScreen(blockEntity, side);
|
||||
Minecraft.getInstance().setScreen(screen);
|
||||
}
|
||||
|
||||
@@ -573,12 +562,8 @@ public final class BusCableBlock extends BaseEntityBlock {
|
||||
final int cableBit = 1 << sideIndex;
|
||||
final int interfaceBit = cableBit << 6;
|
||||
switch (state.getValue(FACING_TO_CONNECTION_MAP.get(Constants.DIRECTIONS[sideIndex]))) {
|
||||
case CABLE:
|
||||
index |= cableBit;
|
||||
break;
|
||||
case INTERFACE:
|
||||
index |= interfaceBit;
|
||||
break;
|
||||
case CABLE -> index |= cableBit;
|
||||
case INTERFACE -> index |= interfaceBit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import li.cil.oc2.common.tileentity.ChargerTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.ChargerBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.util.BlockEntityUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
@@ -52,13 +52,13 @@ public final class ChargerBlock extends HalfTransparentBlock implements EntityBl
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.CHARGER_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.CHARGER.get().create(pos, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(final Level level, final BlockState state, final BlockEntityType<T> type) {
|
||||
return BlockEntityUtils.createTicker(type, TileEntities.CHARGER_TILE_ENTITY.get(), ChargerTileEntity::tick);
|
||||
return BlockEntityUtils.createTicker(type, BlockEntities.CHARGER.get(), ChargerBlockEntity::tick);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -6,41 +6,41 @@ import li.cil.oc2.common.Config;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import li.cil.oc2.common.integration.Wrenches;
|
||||
import li.cil.oc2.common.item.Items;
|
||||
import li.cil.oc2.common.tileentity.ComputerTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.util.BlockEntityUtils;
|
||||
import li.cil.oc2.common.util.NBTUtils;
|
||||
import li.cil.oc2.common.util.TooltipUtils;
|
||||
import li.cil.oc2.common.util.VoxelShapeUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
@@ -50,6 +50,7 @@ import java.util.List;
|
||||
import static li.cil.oc2.common.Constants.BLOCK_ENTITY_TAG_NAME_IN_ITEM;
|
||||
import static li.cil.oc2.common.Constants.ITEMS_TAG_NAME;
|
||||
import static li.cil.oc2.common.util.NBTUtils.makeInventoryTag;
|
||||
import static li.cil.oc2.common.util.RegistryUtils.key;
|
||||
import static li.cil.oc2.common.util.TranslationUtils.text;
|
||||
|
||||
public final class ComputerBlock extends ImmutableHorizontalBlock implements EntityBlock {
|
||||
@@ -86,10 +87,10 @@ public final class ComputerBlock extends ImmutableHorizontalBlock implements Ent
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void appendHoverText(final ItemStack stack, @Nullable final BlockGetter world, final List<Component> tooltip, final TooltipFlag advanced) {
|
||||
super.appendHoverText(stack, world, tooltip, advanced);
|
||||
public void appendHoverText(final ItemStack stack, @Nullable final BlockGetter level, final List<Component> tooltip, final TooltipFlag advanced) {
|
||||
super.appendHoverText(stack, level, tooltip, advanced);
|
||||
TooltipUtils.addEnergyConsumption(Config.computerEnergyPerTick, tooltip);
|
||||
TooltipUtils.addTileEntityInventoryInformation(stack, tooltip);
|
||||
TooltipUtils.addBlockEntityInventoryInformation(stack, tooltip);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -100,104 +101,96 @@ public final class ComputerBlock extends ImmutableHorizontalBlock implements Ent
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getSignal(final BlockState state, final BlockGetter world, final BlockPos pos, final Direction side) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (tileEntity != null) {
|
||||
public int getSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction side) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity != null) {
|
||||
// Redstone requests info for faces with external perspective. Capabilities treat
|
||||
// the Direction from internal perspective, so flip it.
|
||||
return tileEntity.getCapability(Capabilities.REDSTONE_EMITTER, side.getOpposite())
|
||||
return blockEntity.getCapability(Capabilities.REDSTONE_EMITTER, side.getOpposite())
|
||||
.map(RedstoneEmitter::getRedstoneOutput)
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
return super.getSignal(state, world, pos, side);
|
||||
return super.getSignal(state, level, pos, side);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getDirectSignal(final BlockState state, final BlockGetter world, final BlockPos pos, final Direction side) {
|
||||
return getSignal(state, world, pos, side);
|
||||
public int getDirectSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction side) {
|
||||
return getSignal(state, level, pos, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCheckWeakPower(final BlockState state, final LevelReader world, final BlockPos pos, final Direction side) {
|
||||
public boolean shouldCheckWeakPower(final BlockState state, final LevelReader level, final BlockPos pos, final Direction side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void neighborChanged(final BlockState state, final Level world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (tileEntity instanceof ComputerTileEntity) {
|
||||
final ComputerTileEntity computer = (ComputerTileEntity) tileEntity;
|
||||
public void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof final ComputerBlockEntity computer) {
|
||||
computer.handleNeighborChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public VoxelShape getShape(final BlockState state, final BlockGetter world, final BlockPos pos, final CollisionContext context) {
|
||||
switch (state.getValue(FACING)) {
|
||||
case NORTH:
|
||||
return NEG_Z_SHAPE;
|
||||
case SOUTH:
|
||||
return POS_Z_SHAPE;
|
||||
case WEST:
|
||||
return NEG_X_SHAPE;
|
||||
case EAST:
|
||||
default:
|
||||
return POS_X_SHAPE;
|
||||
}
|
||||
public VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
||||
return switch (state.getValue(FACING)) {
|
||||
case NORTH -> NEG_Z_SHAPE;
|
||||
case SOUTH -> POS_Z_SHAPE;
|
||||
case WEST -> NEG_X_SHAPE;
|
||||
default -> POS_X_SHAPE;
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public InteractionResult use(final BlockState state, final Level world, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (!(tileEntity instanceof ComputerTileEntity)) {
|
||||
return super.use(state, world, pos, player, hand, hit);
|
||||
public InteractionResult use(final BlockState state, final Level level, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof final ComputerBlockEntity computer)) {
|
||||
return super.use(state, level, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
final ComputerTileEntity computer = (ComputerTileEntity) tileEntity;
|
||||
final ItemStack heldItem = player.getItemInHand(hand);
|
||||
if (Wrenches.isWrench(heldItem)) {
|
||||
if (!player.isShiftKeyDown()) {
|
||||
if (!world.isClientSide() && player instanceof ServerPlayer) {
|
||||
if (!level.isClientSide() && player instanceof ServerPlayer) {
|
||||
computer.openInventoryScreen((ServerPlayer) player);
|
||||
}
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
} else {
|
||||
if (!world.isClientSide()) {
|
||||
if (!level.isClientSide()) {
|
||||
if (player.isShiftKeyDown()) {
|
||||
computer.start();
|
||||
} else if (player instanceof ServerPlayer) {
|
||||
computer.openTerminalScreen((ServerPlayer) player);
|
||||
}
|
||||
}
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
|
||||
return super.use(state, world, pos, player, hand, hit);
|
||||
return super.use(state, level, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerWillDestroy(final Level world, final BlockPos pos, final BlockState state, final Player player) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (!world.isClientSide() && tileEntity instanceof ComputerTileEntity) {
|
||||
final ComputerTileEntity computer = (ComputerTileEntity) tileEntity;
|
||||
public void playerWillDestroy(final Level level, final BlockPos pos, final BlockState state, final Player player) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!level.isClientSide() && blockEntity instanceof final ComputerBlockEntity computer) {
|
||||
if (!computer.getItemStackHandlers().isEmpty()) {
|
||||
computer.getItemStackHandlers().exportDeviceDataToItemStacks();
|
||||
|
||||
if (player.isCreative()) {
|
||||
final ItemStack stack = new ItemStack(Items.COMPUTER.get());
|
||||
computer.exportToItemStack(stack);
|
||||
popResource(world, pos, stack);
|
||||
popResource(level, pos, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.playerWillDestroy(world, pos, state, player);
|
||||
super.playerWillDestroy(level, pos, state, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,13 +204,13 @@ public final class ComputerBlock extends ImmutableHorizontalBlock implements Ent
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.COMPUTER_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.COMPUTER.get().create(pos, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(final Level level, final BlockState state, final BlockEntityType<T> type) {
|
||||
return level.isClientSide ? null : BlockEntityUtils.createTicker(type, TileEntities.COMPUTER_TILE_ENTITY.get(), ComputerTileEntity::serverTick);
|
||||
return level.isClientSide ? null : BlockEntityUtils.createTicker(type, BlockEntities.COMPUTER.get(), ComputerBlockEntity::serverTick);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -234,7 +227,7 @@ public final class ComputerBlock extends ImmutableHorizontalBlock implements Ent
|
||||
final ItemStack computer = new ItemStack(this);
|
||||
|
||||
final CompoundTag itemsTag = NBTUtils.getOrCreateChildTag(computer.getOrCreateTag(), BLOCK_ENTITY_TAG_NAME_IN_ITEM, ITEMS_TAG_NAME);
|
||||
itemsTag.put(DeviceTypes.FLASH_MEMORY.getRegistryName().toString(), makeInventoryTag(
|
||||
itemsTag.put(key(DeviceTypes.FLASH_MEMORY), makeInventoryTag(
|
||||
new ItemStack(Items.FLASH_MEMORY_CUSTOM.get())
|
||||
));
|
||||
|
||||
@@ -245,16 +238,16 @@ public final class ComputerBlock extends ImmutableHorizontalBlock implements Ent
|
||||
final ItemStack computer = getComputerWithFlash();
|
||||
|
||||
final CompoundTag itemsTag = NBTUtils.getOrCreateChildTag(computer.getOrCreateTag(), BLOCK_ENTITY_TAG_NAME_IN_ITEM, ITEMS_TAG_NAME);
|
||||
itemsTag.put(DeviceTypes.MEMORY.getRegistryName().toString(), makeInventoryTag(
|
||||
itemsTag.put(key(DeviceTypes.MEMORY), makeInventoryTag(
|
||||
new ItemStack(Items.MEMORY_LARGE.get()),
|
||||
new ItemStack(Items.MEMORY_LARGE.get()),
|
||||
new ItemStack(Items.MEMORY_LARGE.get()),
|
||||
new ItemStack(Items.MEMORY_LARGE.get())
|
||||
));
|
||||
itemsTag.put(DeviceTypes.HARD_DRIVE.getRegistryName().toString(), makeInventoryTag(
|
||||
itemsTag.put(key(DeviceTypes.HARD_DRIVE), makeInventoryTag(
|
||||
new ItemStack(Items.HARD_DRIVE_CUSTOM.get())
|
||||
));
|
||||
itemsTag.put(DeviceTypes.CARD.getRegistryName().toString(), makeInventoryTag(
|
||||
itemsTag.put(key(DeviceTypes.CARD), makeInventoryTag(
|
||||
new ItemStack(Items.NETWORK_INTERFACE_CARD.get())
|
||||
));
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import li.cil.oc2.common.tileentity.CreativeEnergyTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.CreativeEnergyBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.util.BlockEntityUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -31,12 +31,12 @@ public final class CreativeEnergyBlock extends Block implements EntityBlock {
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.CREATIVE_ENERGY_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.CREATIVE_ENERGY.get().create(pos, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(final Level level, final BlockState state, final BlockEntityType<T> type) {
|
||||
return level.isClientSide ? null : BlockEntityUtils.createTicker(type, TileEntities.CREATIVE_ENERGY_TILE_ENTITY.get(), CreativeEnergyTileEntity::serverTick);
|
||||
return level.isClientSide ? null : BlockEntityUtils.createTicker(type, BlockEntities.CREATIVE_ENERGY.get(), CreativeEnergyBlockEntity::serverTick);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import li.cil.oc2.common.tileentity.DiskDriveTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import li.cil.oc2.common.blockentity.DiskDriveBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class DiskDriveBlock extends ImmutableHorizontalBlock implements EntityBlock {
|
||||
public DiskDriveBlock() {
|
||||
super(Properties
|
||||
.of(Material.METAL)
|
||||
.sound(SoundType.METAL)
|
||||
.strength(1.5f, 6.0f));
|
||||
.of(Material.METAL)
|
||||
.sound(SoundType.METAL)
|
||||
.strength(1.5f, 6.0f));
|
||||
registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH));
|
||||
}
|
||||
|
||||
@@ -39,31 +39,30 @@ public final class DiskDriveBlock extends ImmutableHorizontalBlock implements En
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public InteractionResult use(final BlockState state, final Level world, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (!(tileEntity instanceof DiskDriveTileEntity)) {
|
||||
return super.use(state, world, pos, player, hand, hit);
|
||||
public InteractionResult use(final BlockState state, final Level level, final BlockPos pos, final Player player, final InteractionHand hand, final BlockHitResult hit) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof final DiskDriveBlockEntity diskDrive)) {
|
||||
return super.use(state, level, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
final DiskDriveTileEntity diskDrive = (DiskDriveTileEntity) tileEntity;
|
||||
final ItemStack heldStack = player.getItemInHand(hand);
|
||||
if (player.isShiftKeyDown()) {
|
||||
if (diskDrive.canEject()) {
|
||||
if (!world.isClientSide()) {
|
||||
if (!level.isClientSide()) {
|
||||
diskDrive.eject(player);
|
||||
}
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
} else {
|
||||
if (diskDrive.canInsert(heldStack)) {
|
||||
if (!world.isClientSide()) {
|
||||
if (!level.isClientSide()) {
|
||||
player.setItemInHand(hand, diskDrive.insert(heldStack, player));
|
||||
}
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
return InteractionResult.sidedSuccess(level.isClientSide());
|
||||
}
|
||||
}
|
||||
|
||||
return super.use(state, world, pos, player, hand, hit);
|
||||
return super.use(state, level, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -72,7 +71,7 @@ public final class DiskDriveBlock extends ImmutableHorizontalBlock implements En
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.DISK_DRIVE_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.DISK_DRIVE.get().create(pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class ImmutableHorizontalBlock extends HorizontalDirectionalBlock {
|
||||
public ImmutableHorizontalBlock(final Properties properties) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import li.cil.oc2.common.tileentity.NetworkConnectorTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.NetworkConnectorBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import li.cil.oc2.common.util.BlockEntityUtils;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
@@ -53,38 +53,28 @@ public final class NetworkConnectorBlock extends FaceAttachedHorizontalDirection
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void neighborChanged(final BlockState state, final Level world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
public void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
if (Objects.equals(changedBlockPos, pos.relative(getFacing(state).getOpposite()))) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (tileEntity instanceof NetworkConnectorTileEntity) {
|
||||
final NetworkConnectorTileEntity connector = (NetworkConnectorTileEntity) tileEntity;
|
||||
connector.setLocalInterfaceChanged();
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof final NetworkConnectorBlockEntity networkConnector) {
|
||||
networkConnector.setLocalInterfaceChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public VoxelShape getShape(final BlockState state, final BlockGetter world, final BlockPos pos, final CollisionContext context) {
|
||||
switch (state.getValue(FACE)) {
|
||||
case WALL:
|
||||
switch (state.getValue(FACING)) {
|
||||
case EAST:
|
||||
return POS_X_SHAPE;
|
||||
case WEST:
|
||||
return NEG_X_SHAPE;
|
||||
case SOUTH:
|
||||
return POS_Z_SHAPE;
|
||||
case NORTH:
|
||||
default:
|
||||
return NEG_Z_SHAPE;
|
||||
}
|
||||
case CEILING:
|
||||
return POS_Y_SHAPE;
|
||||
case FLOOR:
|
||||
default:
|
||||
return NEG_Y_SHAPE;
|
||||
}
|
||||
public VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
||||
return switch (state.getValue(FACE)) {
|
||||
case WALL -> switch (state.getValue(FACING)) {
|
||||
case EAST -> POS_X_SHAPE;
|
||||
case WEST -> NEG_X_SHAPE;
|
||||
case SOUTH -> POS_Z_SHAPE;
|
||||
default /* NORTH */ -> NEG_Z_SHAPE;
|
||||
};
|
||||
case CEILING -> POS_Y_SHAPE;
|
||||
default /* FLOOR */ -> NEG_Y_SHAPE;
|
||||
};
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -93,13 +83,13 @@ public final class NetworkConnectorBlock extends FaceAttachedHorizontalDirection
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.NETWORK_CONNECTOR_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.NETWORK_CONNECTOR.get().create(pos, state);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(final Level level, final BlockState state, final BlockEntityType<T> type) {
|
||||
return level.isClientSide ? null : BlockEntityUtils.createTicker(type, TileEntities.NETWORK_CONNECTOR_TILE_ENTITY.get(), NetworkConnectorTileEntity::serverTick);
|
||||
return level.isClientSide ? null : BlockEntityUtils.createTicker(type, BlockEntities.NETWORK_CONNECTOR.get(), NetworkConnectorBlockEntity::serverTick);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import li.cil.oc2.common.tileentity.NetworkHubTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.NetworkHubBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
@@ -35,11 +35,10 @@ public final class NetworkHubBlock extends HorizontalDirectionalBlock implements
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void neighborChanged(final BlockState state, final Level world, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (tileEntity instanceof NetworkHubTileEntity) {
|
||||
final NetworkHubTileEntity hub = (NetworkHubTileEntity) tileEntity;
|
||||
hub.handleNeighborChanged();
|
||||
public void neighborChanged(final BlockState state, final Level level, final BlockPos pos, final Block changedBlock, final BlockPos changedBlockPos, final boolean isMoving) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof final NetworkHubBlockEntity networkHub) {
|
||||
networkHub.handleNeighborChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +48,7 @@ public final class NetworkHubBlock extends HorizontalDirectionalBlock implements
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.NETWORK_HUB_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.NETWORK_HUB.get().create(pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package li.cil.oc2.common.block;
|
||||
|
||||
import li.cil.oc2.common.tileentity.RedstoneInterfaceTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.blockentity.RedstoneInterfaceBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
@@ -21,9 +21,9 @@ import javax.annotation.Nullable;
|
||||
public final class RedstoneInterfaceBlock extends HorizontalDirectionalBlock implements EntityBlock {
|
||||
public RedstoneInterfaceBlock() {
|
||||
super(Properties
|
||||
.of(Material.METAL)
|
||||
.sound(SoundType.METAL)
|
||||
.strength(1.5f, 6.0f));
|
||||
.of(Material.METAL)
|
||||
.sound(SoundType.METAL)
|
||||
.strength(1.5f, 6.0f));
|
||||
registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH));
|
||||
}
|
||||
|
||||
@@ -42,27 +42,26 @@ public final class RedstoneInterfaceBlock extends HorizontalDirectionalBlock imp
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getSignal(final BlockState state, final BlockGetter world, final BlockPos pos, final Direction side) {
|
||||
final BlockEntity tileEntity = world.getBlockEntity(pos);
|
||||
if (tileEntity instanceof RedstoneInterfaceTileEntity) {
|
||||
final RedstoneInterfaceTileEntity redstoneInterface = (RedstoneInterfaceTileEntity) tileEntity;
|
||||
public int getSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction side) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof final RedstoneInterfaceBlockEntity redstoneInterface) {
|
||||
// Redstone requests info for faces with external perspective. We treat
|
||||
// the Direction from internal perspective, so flip it.
|
||||
return redstoneInterface.getOutputForDirection(side.getOpposite());
|
||||
}
|
||||
|
||||
return super.getSignal(state, world, pos, side);
|
||||
return super.getSignal(state, level, pos, side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCheckWeakPower(final BlockState state, final LevelReader world, final BlockPos pos, final Direction side) {
|
||||
public boolean shouldCheckWeakPower(final BlockState state, final LevelReader level, final BlockPos pos, final Direction side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getDirectSignal(final BlockState state, final BlockGetter world, final BlockPos pos, final Direction side) {
|
||||
return getSignal(state, world, pos, side);
|
||||
public int getDirectSignal(final BlockState state, final BlockGetter level, final BlockPos pos, final Direction side) {
|
||||
return getSignal(state, level, pos, side);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -71,7 +70,7 @@ public final class RedstoneInterfaceBlock extends HorizontalDirectionalBlock imp
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
return TileEntities.REDSTONE_INTERFACE_TILE_ENTITY.get().create(pos, state);
|
||||
return BlockEntities.REDSTONE_INTERFACE.get().create(pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.common.block.Blocks;
|
||||
import li.cil.oc2.common.util.RegistryUtils;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public final class BlockEntities {
|
||||
private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = RegistryUtils.create(ForgeRegistries.BLOCK_ENTITIES);
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final RegistryObject<BlockEntityType<RedstoneInterfaceBlockEntity>> REDSTONE_INTERFACE = register(Blocks.REDSTONE_INTERFACE, RedstoneInterfaceBlockEntity::new);
|
||||
public static final RegistryObject<BlockEntityType<BusCableBlockEntity>> BUS_CABLE = register(Blocks.BUS_CABLE, BusCableBlockEntity::new);
|
||||
public static final RegistryObject<BlockEntityType<ComputerBlockEntity>> COMPUTER = register(Blocks.COMPUTER, ComputerBlockEntity::new);
|
||||
public static final RegistryObject<BlockEntityType<NetworkConnectorBlockEntity>> NETWORK_CONNECTOR = register(Blocks.NETWORK_CONNECTOR, NetworkConnectorBlockEntity::new);
|
||||
public static final RegistryObject<BlockEntityType<NetworkHubBlockEntity>> NETWORK_HUB = register(Blocks.NETWORK_HUB, NetworkHubBlockEntity::new);
|
||||
public static final RegistryObject<BlockEntityType<DiskDriveBlockEntity>> DISK_DRIVE = register(Blocks.DISK_DRIVE, DiskDriveBlockEntity::new);
|
||||
public static final RegistryObject<BlockEntityType<ChargerBlockEntity>> CHARGER = register(Blocks.CHARGER, ChargerBlockEntity::new);
|
||||
public static final RegistryObject<BlockEntityType<CreativeEnergyBlockEntity>> CREATIVE_ENERGY = register(Blocks.CREATIVE_ENERGY, CreativeEnergyBlockEntity::new);
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void initialize() {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@SuppressWarnings("ConstantConditions") // .build(null) is fine
|
||||
private static <B extends Block, T extends BlockEntity> RegistryObject<BlockEntityType<T>> register(final RegistryObject<B> block, final BlockEntityType.BlockEntitySupplier<T> factory) {
|
||||
return BLOCK_ENTITIES.register(block.getId().getPath(), () -> BlockEntityType.Builder.of(factory, block.get()).build(null));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.common.Config;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.block.BusCableBlock;
|
||||
import li.cil.oc2.common.bus.TileEntityDeviceBusElement;
|
||||
import li.cil.oc2.common.bus.BlockEntityDeviceBusElement;
|
||||
import li.cil.oc2.common.bus.device.rpc.TypeNameRPCDevice;
|
||||
import li.cil.oc2.common.bus.device.util.BlockDeviceInfo;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
@@ -29,7 +29,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
public final class BusCableBlockEntity extends ModBlockEntity {
|
||||
public enum FacadeType {
|
||||
NOT_A_BLOCK,
|
||||
INVALID_BLOCK,
|
||||
@@ -42,14 +42,14 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private final TileEntityDeviceBusElement busElement = new BusCableBusElement();
|
||||
private final BlockEntityDeviceBusElement busElement = new BusCableBusElement();
|
||||
private final String[] interfaceNames = new String[Constants.BLOCK_FACE_COUNT];
|
||||
private ItemStack facade = ItemStack.EMPTY;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public BusCableTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.BUS_CABLE_TILE_ENTITY.get(), pos, state);
|
||||
public BusCableBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.BUS_CABLE.get(), pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -60,6 +60,10 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
}
|
||||
|
||||
public void setInterfaceName(final Direction side, final String name) {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String validatedName = validateName(name);
|
||||
if (Objects.equals(validatedName, interfaceNames[side.get3DDataValue()])) {
|
||||
return;
|
||||
@@ -68,7 +72,7 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
interfaceNames[side.get3DDataValue()] = validatedName;
|
||||
if (!level.isClientSide()) {
|
||||
final BusInterfaceNameMessage message = new BusInterfaceNameMessage.ToClient(this, side, interfaceNames[side.get3DDataValue()]);
|
||||
Network.sendToClientsTrackingTileEntity(message, this);
|
||||
Network.sendToClientsTrackingBlockEntity(message, this);
|
||||
handleNeighborChanged(getBlockPos().relative(side));
|
||||
}
|
||||
}
|
||||
@@ -82,7 +86,8 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
return FacadeType.NOT_A_BLOCK;
|
||||
}
|
||||
|
||||
if (state.getRenderShape() != RenderShape.MODEL ||
|
||||
if (level == null ||
|
||||
state.getRenderShape() != RenderShape.MODEL ||
|
||||
!state.isSolidRender(level, getBlockPos()) ||
|
||||
state.getBlock() instanceof EntityBlock) {
|
||||
return FacadeType.INVALID_BLOCK;
|
||||
@@ -96,6 +101,10 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
}
|
||||
|
||||
public void setFacade(ItemStack stack) {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockState facadeState = ItemStackUtils.getBlockState(stack);
|
||||
if (getFacadeType(facadeState) != FacadeType.VALID_BLOCK) {
|
||||
stack = ItemStack.EMPTY;
|
||||
@@ -114,11 +123,15 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
|
||||
if (!level.isClientSide()) {
|
||||
final BusCableFacadeMessage message = new BusCableFacadeMessage(getBlockPos(), facade);
|
||||
Network.sendToClientsTrackingTileEntity(message, this);
|
||||
Network.sendToClientsTrackingBlockEntity(message, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFacade() {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockState facadeState = ItemStackUtils.getBlockState(facade);
|
||||
facade = ItemStack.EMPTY;
|
||||
BusCableBlock.setHasFacade(level, getBlockPos(), getBlockState(), facadeState, false);
|
||||
@@ -128,7 +141,7 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
|
||||
if (!level.isClientSide()) {
|
||||
final BusCableFacadeMessage message = new BusCableFacadeMessage(getBlockPos(), facade);
|
||||
Network.sendToClientsTrackingTileEntity(message, this);
|
||||
Network.sendToClientsTrackingBlockEntity(message, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,9 +246,9 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private final class BusCableBusElement extends TileEntityDeviceBusElement {
|
||||
private final class BusCableBusElement extends BlockEntityDeviceBusElement {
|
||||
public BusCableBusElement() {
|
||||
super(BusCableTileEntity.this);
|
||||
super(BusCableBlockEntity.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -252,8 +265,8 @@ public final class BusCableTileEntity extends AbstractTileEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void collectSyntheticDevices(final Level world, final BlockPos pos, @Nullable final Direction direction, final HashSet<BlockDeviceInfo> devices) {
|
||||
super.collectSyntheticDevices(world, pos, direction, devices);
|
||||
protected void collectSyntheticDevices(final Level level, final BlockPos pos, @Nullable final Direction direction, final HashSet<BlockDeviceInfo> devices) {
|
||||
super.collectSyntheticDevices(level, pos, direction, devices);
|
||||
if (direction != null) {
|
||||
final String interfaceName = interfaceNames[direction.get3DDataValue()];
|
||||
if (!StringUtil.isNullOrEmpty(interfaceName)) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.api.bus.device.object.Callback;
|
||||
import li.cil.oc2.api.bus.device.object.NamedDevice;
|
||||
@@ -7,14 +7,14 @@ import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import li.cil.oc2.common.energy.FixedEnergyStorage;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.EntitySelector;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntitySelector;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
@@ -27,7 +27,7 @@ import java.util.function.Predicate;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public final class ChargerTileEntity extends AbstractTileEntity implements NamedDevice {
|
||||
public final class ChargerBlockEntity extends ModBlockEntity implements NamedDevice {
|
||||
private static final Predicate<Entity> ENTITY_PREDICATE =
|
||||
EntitySelector.NO_SPECTATORS
|
||||
.and(EntitySelector.ENTITY_STILL_ALIVE);
|
||||
@@ -39,17 +39,21 @@ public final class ChargerTileEntity extends AbstractTileEntity implements Named
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
ChargerTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.CHARGER_TILE_ENTITY.get(), pos, state);
|
||||
ChargerBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.CHARGER.get(), pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void tick(final Level level, final BlockPos pos, final BlockState state, final ChargerTileEntity tileEntity) {
|
||||
tileEntity.tick();
|
||||
public static void tick(final Level level, final BlockPos pos, final BlockState state, final ChargerBlockEntity charger) {
|
||||
charger.tick();
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
isCharging = false;
|
||||
chargeBlock();
|
||||
chargeEntities();
|
||||
@@ -89,17 +93,21 @@ public final class ChargerTileEntity extends AbstractTileEntity implements Named
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private void chargeBlock() {
|
||||
assert level != null;
|
||||
|
||||
if (energy.getEnergyStored() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockEntity tileEntity = level.getBlockEntity(getBlockPos().above());
|
||||
if (tileEntity != null) {
|
||||
chargeCapabilityProvider(tileEntity);
|
||||
final BlockEntity blockEntity = level.getBlockEntity(getBlockPos().above());
|
||||
if (blockEntity != null) {
|
||||
chargeCapabilityProvider(blockEntity);
|
||||
}
|
||||
}
|
||||
|
||||
private void chargeEntities() {
|
||||
assert level != null;
|
||||
|
||||
if (energy.getEnergyStored() == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -125,6 +133,8 @@ public final class ChargerTileEntity extends AbstractTileEntity implements Named
|
||||
}
|
||||
|
||||
private void charge(final IEnergyStorage energyStorage) {
|
||||
assert level != null;
|
||||
|
||||
final int amount = Math.min(energy.getEnergyStored(), Config.chargerEnergyPerTick);
|
||||
final boolean simulate = level.isClientSide;
|
||||
if (energy.extractEnergy(energyStorage.receiveEnergy(amount, simulate), simulate) > 0) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.api.bus.DeviceBusElement;
|
||||
import li.cil.oc2.api.bus.device.Device;
|
||||
@@ -9,8 +9,8 @@ import li.cil.oc2.client.audio.LoopingSoundManager;
|
||||
import li.cil.oc2.common.Config;
|
||||
import li.cil.oc2.common.block.ComputerBlock;
|
||||
import li.cil.oc2.common.bus.CommonDeviceBusController;
|
||||
import li.cil.oc2.common.bus.TileEntityDeviceBusController;
|
||||
import li.cil.oc2.common.bus.TileEntityDeviceBusElement;
|
||||
import li.cil.oc2.common.bus.BlockEntityDeviceBusController;
|
||||
import li.cil.oc2.common.bus.BlockEntityDeviceBusElement;
|
||||
import li.cil.oc2.common.bus.device.util.BlockDeviceInfo;
|
||||
import li.cil.oc2.common.bus.device.util.Devices;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
@@ -30,14 +30,14 @@ import li.cil.oc2.common.util.SoundEvents;
|
||||
import li.cil.oc2.common.util.TerminalUtils;
|
||||
import li.cil.oc2.common.vm.*;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
@@ -50,7 +50,7 @@ import java.util.*;
|
||||
|
||||
import static li.cil.oc2.common.Constants.*;
|
||||
|
||||
public final class ComputerTileEntity extends AbstractTileEntity implements TerminalUserProvider {
|
||||
public final class ComputerBlockEntity extends ModBlockEntity implements TerminalUserProvider {
|
||||
private static final String BUS_ELEMENT_TAG_NAME = "busElement";
|
||||
private static final String DEVICES_TAG_NAME = "devices";
|
||||
private static final String TERMINAL_TAG_NAME = "terminal";
|
||||
@@ -75,16 +75,16 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
private final ComputerBusElement busElement = new ComputerBusElement();
|
||||
private final ComputerItemStackHandlers deviceItems = new ComputerItemStackHandlers();
|
||||
private final FixedEnergyStorage energy = new FixedEnergyStorage(Config.computerEnergyStorage);
|
||||
private final ComputerVirtualMachine virtualMachine = new ComputerVirtualMachine(new TileEntityDeviceBusController(busElement, Config.computerEnergyPerTick, this), deviceItems::getDeviceAddressBase);
|
||||
private final ComputerVirtualMachine virtualMachine = new ComputerVirtualMachine(new BlockEntityDeviceBusController(busElement, Config.computerEnergyPerTick, this), deviceItems::getDeviceAddressBase);
|
||||
private final Set<Player> terminalUsers = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public ComputerTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.COMPUTER_TILE_ENTITY.get(), pos, state);
|
||||
public ComputerBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.COMPUTER.get(), pos, state);
|
||||
|
||||
// We want to unload devices even on world unload to free global resources.
|
||||
setNeedsWorldUnloadEvent();
|
||||
// We want to unload devices even on level unload to free global resources.
|
||||
setNeedsLevelUnloadEvent();
|
||||
}
|
||||
|
||||
public Terminal getTerminal() {
|
||||
@@ -165,11 +165,15 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
public static void serverTick(final Level level, final BlockPos pos, final BlockState state, final ComputerTileEntity tileEntity) {
|
||||
tileEntity.serverTick();
|
||||
public static void serverTick(final Level level, final BlockPos pos, final BlockState state, final ComputerBlockEntity computer) {
|
||||
computer.serverTick();
|
||||
}
|
||||
|
||||
private void serverTick() {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Always add devices provided for the computer itself, even if there's no
|
||||
// adjacent cable. Because that would just be weird.
|
||||
if (!hasAddedOwnDevices) {
|
||||
@@ -271,7 +275,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
super.loadServer();
|
||||
|
||||
busElement.initialize();
|
||||
virtualMachine.state.builtinDevices.rtcMinecraft.setWorld(level);
|
||||
virtualMachine.state.builtinDevices.rtcMinecraft.setLevel(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,16 +297,16 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
private final class ComputerItemStackHandlers extends AbstractVMItemStackHandlers {
|
||||
public ComputerItemStackHandlers() {
|
||||
super(
|
||||
GroupDefinition.of(DeviceTypes.MEMORY, MEMORY_SLOTS),
|
||||
GroupDefinition.of(DeviceTypes.HARD_DRIVE, HARD_DRIVE_SLOTS),
|
||||
GroupDefinition.of(DeviceTypes.FLASH_MEMORY, FLASH_MEMORY_SLOTS),
|
||||
GroupDefinition.of(DeviceTypes.CARD, CARD_SLOTS)
|
||||
new GroupDefinition(DeviceTypes.MEMORY, MEMORY_SLOTS),
|
||||
new GroupDefinition(DeviceTypes.HARD_DRIVE, HARD_DRIVE_SLOTS),
|
||||
new GroupDefinition(DeviceTypes.FLASH_MEMORY, FLASH_MEMORY_SLOTS),
|
||||
new GroupDefinition(DeviceTypes.CARD, CARD_SLOTS)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemDeviceQuery getDeviceQuery(final ItemStack stack) {
|
||||
return Devices.makeQuery(ComputerTileEntity.this, stack);
|
||||
return Devices.makeQuery(ComputerBlockEntity.this, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -313,17 +317,19 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
}
|
||||
}
|
||||
|
||||
private final class ComputerBusElement extends TileEntityDeviceBusElement {
|
||||
private final class ComputerBusElement extends BlockEntityDeviceBusElement {
|
||||
private static final String DEVICE_ID_TAG_NAME = "device_id";
|
||||
|
||||
private final HashSet<Device> devices = new HashSet<>();
|
||||
private UUID deviceId = UUID.randomUUID();
|
||||
|
||||
public ComputerBusElement() {
|
||||
super(ComputerTileEntity.this);
|
||||
super(ComputerBlockEntity.this);
|
||||
}
|
||||
|
||||
public void addOwnDevices() {
|
||||
assert level != null;
|
||||
|
||||
for (final BlockDeviceInfo info : collectDevices(level, getPosition(), null)) {
|
||||
devices.add(info.device);
|
||||
super.addDevice(info.device);
|
||||
@@ -376,7 +382,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
|
||||
@Override
|
||||
protected void sendTerminalUpdateToClient(final ByteBuffer output) {
|
||||
Network.sendToClientsTrackingChunk(new ComputerTerminalOutputMessage(ComputerTileEntity.this, output), virtualMachine.chunk);
|
||||
Network.sendToClientsTrackingChunk(new ComputerTerminalOutputMessage(ComputerBlockEntity.this, output), virtualMachine.chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,16 +399,18 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
super.setRunStateClient(value);
|
||||
|
||||
if (value == VMRunState.RUNNING) {
|
||||
if (!LoopingSoundManager.isPlaying(ComputerTileEntity.this)) {
|
||||
LoopingSoundManager.play(ComputerTileEntity.this, SoundEvents.COMPUTER_RUNNING.get(), level.getRandom().nextInt(MAX_RUNNING_SOUND_DELAY));
|
||||
if (!LoopingSoundManager.isPlaying(ComputerBlockEntity.this) && level != null) {
|
||||
LoopingSoundManager.play(ComputerBlockEntity.this, SoundEvents.COMPUTER_RUNNING.get(), level.getRandom().nextInt(MAX_RUNNING_SOUND_DELAY));
|
||||
}
|
||||
} else {
|
||||
LoopingSoundManager.stop(ComputerTileEntity.this);
|
||||
LoopingSoundManager.stop(ComputerBlockEntity.this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
assert level != null;
|
||||
|
||||
if (chunk == null) {
|
||||
chunk = level.getChunkAt(getBlockPos());
|
||||
}
|
||||
@@ -433,7 +441,7 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
super.stopRunnerAndReset();
|
||||
|
||||
TerminalUtils.resetTerminal(terminal, output -> Network.sendToClientsTrackingChunk(
|
||||
new ComputerTerminalOutputMessage(ComputerTileEntity.this, output), chunk));
|
||||
new ComputerTerminalOutputMessage(ComputerBlockEntity.this, output), chunk));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -443,9 +451,9 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
|
||||
@Override
|
||||
protected void handleBusStateChanged(final CommonDeviceBusController.BusState value) {
|
||||
Network.sendToClientsTrackingChunk(new ComputerBusStateMessage(ComputerTileEntity.this), chunk);
|
||||
Network.sendToClientsTrackingChunk(new ComputerBusStateMessage(ComputerBlockEntity.this), chunk);
|
||||
|
||||
if (value == CommonDeviceBusController.BusState.READY) {
|
||||
if (value == CommonDeviceBusController.BusState.READY && level != null) {
|
||||
// Bus just became ready, meaning new devices may be available, meaning new
|
||||
// capabilities may be available, so we need to tell our neighbors.
|
||||
level.updateNeighborsAt(getBlockPos(), getBlockState().getBlock());
|
||||
@@ -457,13 +465,13 @@ public final class ComputerTileEntity extends AbstractTileEntity implements Term
|
||||
// This method can be called from disposal logic, so if we are disposed quickly enough
|
||||
// chunk may not be initialized yet. Avoid resulting NRE in network logic.
|
||||
if (chunk != null) {
|
||||
Network.sendToClientsTrackingChunk(new ComputerRunStateMessage(ComputerTileEntity.this), chunk);
|
||||
Network.sendToClientsTrackingChunk(new ComputerRunStateMessage(ComputerBlockEntity.this), chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBootErrorChanged(@Nullable final Component value) {
|
||||
Network.sendToClientsTrackingChunk(new ComputerBootErrorMessage(ComputerTileEntity.this), chunk);
|
||||
Network.sendToClientsTrackingChunk(new ComputerBootErrorMessage(ComputerBlockEntity.this), chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -8,29 +8,33 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public final class CreativeEnergyTileEntity extends BlockEntity {
|
||||
public final class CreativeEnergyBlockEntity extends BlockEntity {
|
||||
private final Direction[] SIDES = Direction.values();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public CreativeEnergyTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.CREATIVE_ENERGY_TILE_ENTITY.get(), pos, state);
|
||||
public CreativeEnergyBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.CREATIVE_ENERGY.get(), pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static void serverTick(final Level level, final BlockPos pos, final BlockState state, final CreativeEnergyTileEntity tileEntity) {
|
||||
tileEntity.serverTick();
|
||||
public static void serverTick(final Level level, final BlockPos pos, final BlockState state, final CreativeEnergyBlockEntity creativeEnergy) {
|
||||
creativeEnergy.serverTick();
|
||||
}
|
||||
|
||||
private void serverTick() {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Direction side : SIDES) {
|
||||
final BlockPos neighborPos = getBlockPos().relative(side);
|
||||
final ChunkPos neighborChunkPos = new ChunkPos(neighborPos);
|
||||
if (level.hasChunk(neighborChunkPos.x, neighborChunkPos.z)) {
|
||||
final BlockEntity tileEntity = level.getBlockEntity(neighborPos);
|
||||
if (tileEntity != null) {
|
||||
tileEntity.getCapability(Capabilities.ENERGY_STORAGE, side.getOpposite()).ifPresent(energy -> {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(neighborPos);
|
||||
if (blockEntity != null) {
|
||||
blockEntity.getCapability(Capabilities.ENERGY_STORAGE, side.getOpposite()).ifPresent(energy -> {
|
||||
energy.receiveEnergy(Integer.MAX_VALUE, false);
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.api.bus.device.vm.VMDevice;
|
||||
import li.cil.oc2.common.Config;
|
||||
@@ -19,13 +19,13 @@ import li.cil.oc2.common.util.ThrottledSoundEmitter;
|
||||
import li.cil.sedna.api.device.BlockDevice;
|
||||
import li.cil.sedna.device.block.ByteBufferBlockDevice;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -38,7 +38,7 @@ import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.time.Duration;
|
||||
|
||||
public final class DiskDriveTileEntity extends AbstractTileEntity {
|
||||
public final class DiskDriveBlockEntity extends ModBlockEntity {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final String DATA_TAG_NAME = "data";
|
||||
@@ -55,15 +55,15 @@ public final class DiskDriveTileEntity extends AbstractTileEntity {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public DiskDriveTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.DISK_DRIVE_TILE_ENTITY.get(), pos, state);
|
||||
public DiskDriveBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.DISK_DRIVE.get(), pos, state);
|
||||
|
||||
this.accessSoundEmitter = new ThrottledSoundEmitter(LocationSupplierUtils.of(this),
|
||||
SoundEvents.FLOPPY_ACCESS.get()).withMinInterval(Duration.ofSeconds(1));
|
||||
SoundEvents.FLOPPY_ACCESS.get()).withMinInterval(Duration.ofSeconds(1));
|
||||
this.insertSoundEmitter = new ThrottledSoundEmitter(LocationSupplierUtils.of(this),
|
||||
SoundEvents.FLOPPY_INSERT.get()).withMinInterval(Duration.ofMillis(100));
|
||||
SoundEvents.FLOPPY_INSERT.get()).withMinInterval(Duration.ofMillis(100));
|
||||
this.ejectSoundEmitter = new ThrottledSoundEmitter(LocationSupplierUtils.of(this),
|
||||
SoundEvents.FLOPPY_EJECT.get()).withMinInterval(Duration.ofMillis(100));
|
||||
SoundEvents.FLOPPY_EJECT.get()).withMinInterval(Duration.ofMillis(100));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -92,6 +92,10 @@ public final class DiskDriveTileEntity extends AbstractTileEntity {
|
||||
}
|
||||
|
||||
public void eject(@Nullable final Player player) {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack stack = itemHandler.extractItem(0, 1, false);
|
||||
if (!stack.isEmpty()) {
|
||||
final Direction facing = getBlockState().getValue(DiskDriveBlock.FACING);
|
||||
@@ -196,7 +200,7 @@ public final class DiskDriveTileEntity extends AbstractTileEntity {
|
||||
device.updateBlockDevice(tag);
|
||||
}
|
||||
|
||||
Network.sendToClientsTrackingTileEntity(new DiskDriveFloppyMessage(DiskDriveTileEntity.this), DiskDriveTileEntity.this);
|
||||
Network.sendToClientsTrackingBlockEntity(new DiskDriveFloppyMessage(DiskDriveBlockEntity.this), DiskDriveBlockEntity.this);
|
||||
}
|
||||
|
||||
private void exportDeviceDataToItemStack(final ItemStack stack) {
|
||||
@@ -216,7 +220,7 @@ public final class DiskDriveTileEntity extends AbstractTileEntity {
|
||||
|
||||
private final class DiskDriveVMDevice extends AbstractBlockDeviceVMDevice<BlockDevice, BlockEntity> {
|
||||
public DiskDriveVMDevice() {
|
||||
super(DiskDriveTileEntity.this);
|
||||
super(DiskDriveBlockEntity.this);
|
||||
}
|
||||
|
||||
public void updateBlockDevice(final CompoundTag tag) {
|
||||
@@ -258,12 +262,11 @@ public final class DiskDriveTileEntity extends AbstractTileEntity {
|
||||
@Override
|
||||
protected BlockDevice createBlockDevice() throws IOException {
|
||||
final ItemStack stack = itemHandler.getStackInSlotRaw(0);
|
||||
if (stack.isEmpty() || !(stack.getItem() instanceof FloppyItem)) {
|
||||
if (stack.isEmpty() || !(stack.getItem() instanceof final FloppyItem floppy)) {
|
||||
return EMPTY_BLOCK_DEVICE;
|
||||
}
|
||||
|
||||
final FloppyItem item = (FloppyItem) stack.getItem();
|
||||
final int capacity = Mth.clamp(item.getCapacity(stack), 0, Config.maxFloppySize);
|
||||
final int capacity = Mth.clamp(floppy.getCapacity(stack), 0, Config.maxFloppySize);
|
||||
if (capacity <= 0) {
|
||||
return EMPTY_BLOCK_DEVICE;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.common.util.ServerScheduler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -15,15 +15,15 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractTileEntity extends BlockEntity {
|
||||
public abstract class ModBlockEntity extends BlockEntity {
|
||||
private final Runnable onWorldUnloaded = this::onWorldUnloaded;
|
||||
private final HashMap<CapabilityCacheKey, LazyOptional<?>> capabilityCache = new HashMap<>();
|
||||
private boolean needsWorldUnloadEvent;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected AbstractTileEntity(final BlockEntityType<?> tileEntityType, final BlockPos pos, final BlockState state) {
|
||||
super(tileEntityType, pos, state);
|
||||
protected ModBlockEntity(final BlockEntityType<?> blockEntityType, final BlockPos pos, final BlockState state) {
|
||||
super(blockEntityType, pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -130,7 +130,7 @@ public abstract class AbstractTileEntity extends BlockEntity {
|
||||
}
|
||||
}
|
||||
|
||||
protected void setNeedsWorldUnloadEvent() {
|
||||
protected void setNeedsLevelUnloadEvent() {
|
||||
needsWorldUnloadEvent = true;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.api.capabilities.NetworkInterface;
|
||||
import li.cil.oc2.client.renderer.NetworkCableRenderer;
|
||||
@@ -11,16 +11,22 @@ import li.cil.oc2.common.network.message.NetworkConnectorConnectionsMessage;
|
||||
import li.cil.oc2.common.util.ItemStackUtils;
|
||||
import li.cil.oc2.common.util.NBTTagIds;
|
||||
import li.cil.oc2.common.util.ServerScheduler;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
@@ -31,14 +37,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
public final class NetworkConnectorBlockEntity extends ModBlockEntity {
|
||||
public enum ConnectionResult {
|
||||
SUCCESS,
|
||||
FAILURE,
|
||||
@@ -69,27 +68,27 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
private final HashSet<BlockPos> connectorPositions = new HashSet<>();
|
||||
private final HashSet<BlockPos> ownedCables = new HashSet<>();
|
||||
private final HashSet<BlockPos> dirtyConnectors = new HashSet<>();
|
||||
private final HashMap<BlockPos, NetworkConnectorTileEntity> connectors = new HashMap<>();
|
||||
private final HashMap<BlockPos, NetworkConnectorBlockEntity> connectors = new HashMap<>();
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public NetworkConnectorTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.NETWORK_CONNECTOR_TILE_ENTITY.get(), pos, state);
|
||||
public NetworkConnectorBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.NETWORK_CONNECTOR.get(), pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static ConnectionResult connect(final NetworkConnectorTileEntity connectorA, final NetworkConnectorTileEntity connectorB) {
|
||||
public static ConnectionResult connect(final NetworkConnectorBlockEntity connectorA, final NetworkConnectorBlockEntity connectorB) {
|
||||
if (connectorA == connectorB || connectorA.isRemoved() || connectorB.isRemoved()) {
|
||||
return ConnectionResult.FAILURE;
|
||||
}
|
||||
|
||||
final Level world = connectorA.level;
|
||||
if (world == null || world.isClientSide()) {
|
||||
final Level level = connectorA.level;
|
||||
if (level == null || level.isClientSide()) {
|
||||
return ConnectionResult.FAILURE;
|
||||
}
|
||||
|
||||
if (connectorB.level != world) {
|
||||
if (connectorB.level != level) {
|
||||
return ConnectionResult.FAILURE;
|
||||
}
|
||||
|
||||
@@ -104,7 +103,7 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
return ConnectionResult.FAILURE_TOO_FAR;
|
||||
}
|
||||
|
||||
if (isObstructed(world, posA, posB)) {
|
||||
if (isObstructed(level, posA, posB)) {
|
||||
return ConnectionResult.FAILURE_OBSTRUCTED;
|
||||
}
|
||||
|
||||
@@ -173,11 +172,15 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
NetworkCableRenderer.invalidateConnections();
|
||||
}
|
||||
|
||||
public static void serverTick(final Level level, final BlockPos pos, final BlockState state, final NetworkConnectorTileEntity tileEntity) {
|
||||
tileEntity.serverTick();
|
||||
public static void serverTick(final Level level, final BlockPos pos, final BlockState state, final NetworkConnectorBlockEntity networkConnector) {
|
||||
networkConnector.serverTick();
|
||||
}
|
||||
|
||||
private void serverTick() {
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLocalConnectionDirty) {
|
||||
isLocalConnectionDirty = false;
|
||||
resolveLocalInterface();
|
||||
@@ -272,9 +275,9 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
|
||||
// When we're being removed we want to break the actual link to any connected
|
||||
// connectors. This will also cause cables to be dropped.
|
||||
final ArrayList<NetworkConnectorTileEntity> list = new ArrayList<>(connectors.values());
|
||||
final ArrayList<NetworkConnectorBlockEntity> list = new ArrayList<>(connectors.values());
|
||||
connectors.clear();
|
||||
for (final NetworkConnectorTileEntity connector : list) {
|
||||
for (final NetworkConnectorBlockEntity connector : list) {
|
||||
disconnectFrom(connector.getBlockPos());
|
||||
connector.disconnectFrom(getBlockPos());
|
||||
}
|
||||
@@ -284,10 +287,10 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
protected void unloadServer() {
|
||||
super.unloadServer();
|
||||
|
||||
// When unloading, we just want to remove the reference to this tile entity
|
||||
// When unloading, we just want to remove the reference to this block entity
|
||||
// from connected connectors; we don't want to actually break the link.
|
||||
final BlockPos pos = getBlockPos();
|
||||
for (final NetworkConnectorTileEntity connector : connectors.values()) {
|
||||
for (final NetworkConnectorBlockEntity connector : connectors.values()) {
|
||||
connector.connectors.remove(pos);
|
||||
if (connector.connectorPositions.contains(pos)) {
|
||||
connector.dirtyConnectors.add(pos);
|
||||
@@ -299,8 +302,8 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
public AABB getRenderBoundingBox() {
|
||||
if (Minecraft.useShaderTransparency()) {
|
||||
return new AABB(
|
||||
getBlockPos().offset(-MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE),
|
||||
getBlockPos().offset(1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE)
|
||||
getBlockPos().offset(-MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE, -MAX_CONNECTION_DISTANCE),
|
||||
getBlockPos().offset(1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE, 1 + MAX_CONNECTION_DISTANCE)
|
||||
);
|
||||
} else {
|
||||
return super.getRenderBoundingBox();
|
||||
@@ -319,6 +322,8 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private void resolveLocalInterface() {
|
||||
assert level != null;
|
||||
|
||||
localInterface = LazyOptional.empty();
|
||||
|
||||
if (isRemoved()) {
|
||||
@@ -334,12 +339,12 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockEntity tileEntity = level.getBlockEntity(sourcePos);
|
||||
if (tileEntity == null) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(sourcePos);
|
||||
if (blockEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
localInterface = tileEntity.getCapability(Capabilities.NETWORK_INTERFACE, facing);
|
||||
localInterface = blockEntity.getCapability(Capabilities.NETWORK_INTERFACE, facing);
|
||||
if (localInterface.isPresent()) {
|
||||
localInterface.addListener(unused -> setLocalInterfaceChanged());
|
||||
}
|
||||
@@ -362,30 +367,28 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockEntity tileEntity = level.getBlockEntity(connectedPosition);
|
||||
if (!(tileEntity instanceof NetworkConnectorTileEntity)) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(connectedPosition);
|
||||
if (!(blockEntity instanceof final NetworkConnectorBlockEntity networkConnector)) {
|
||||
disconnectFrom(connectedPosition);
|
||||
return;
|
||||
}
|
||||
|
||||
final NetworkConnectorTileEntity connector = (NetworkConnectorTileEntity) tileEntity;
|
||||
|
||||
if (!connectedPosition.closerThan(getBlockPos(), MAX_CONNECTION_DISTANCE)) {
|
||||
disconnectFrom(connectedPosition);
|
||||
connector.disconnectFrom(getBlockPos());
|
||||
networkConnector.disconnectFrom(getBlockPos());
|
||||
return;
|
||||
}
|
||||
|
||||
if (isObstructed(level, getBlockPos(), connectedPosition)) {
|
||||
disconnectFrom(connectedPosition);
|
||||
connector.disconnectFrom(getBlockPos());
|
||||
networkConnector.disconnectFrom(getBlockPos());
|
||||
return;
|
||||
}
|
||||
|
||||
connectors.put(connectedPosition, connector);
|
||||
connectors.put(connectedPosition, networkConnector);
|
||||
}
|
||||
|
||||
private static boolean isObstructed(final Level world, final BlockPos a, final BlockPos b) {
|
||||
private static boolean isObstructed(final Level level, final BlockPos a, final BlockPos b) {
|
||||
final Vec3 va = Vec3.atCenterOf(a);
|
||||
final Vec3 vb = Vec3.atCenterOf(b);
|
||||
final Vec3 ab = vb.subtract(va).normalize().scale(0.5);
|
||||
@@ -393,29 +396,29 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
// Because of floating point inaccuracies the raytrace is not necessarily
|
||||
// symmetric. In particular when grazing corners perfectly, e.g. two connectors
|
||||
// attached to the same block at a 90 degree angle. So we check both ways.
|
||||
final BlockHitResult hitAB = world.clip(new ClipContext(
|
||||
va.add(ab),
|
||||
vb.subtract(ab),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
null
|
||||
final BlockHitResult hitAB = level.clip(new ClipContext(
|
||||
va.add(ab),
|
||||
vb.subtract(ab),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
null
|
||||
));
|
||||
final BlockHitResult hitBA = world.clip(new ClipContext(
|
||||
vb.subtract(ab),
|
||||
va.add(ab),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
null
|
||||
final BlockHitResult hitBA = level.clip(new ClipContext(
|
||||
vb.subtract(ab),
|
||||
va.add(ab),
|
||||
ClipContext.Block.COLLIDER,
|
||||
ClipContext.Fluid.NONE,
|
||||
null
|
||||
));
|
||||
|
||||
return hitAB.getType() != HitResult.Type.MISS ||
|
||||
hitBA.getType() != HitResult.Type.MISS;
|
||||
hitBA.getType() != HitResult.Type.MISS;
|
||||
}
|
||||
|
||||
private void onConnectedPositionsChanged() {
|
||||
if (!level.isClientSide()) {
|
||||
if (level != null && !level.isClientSide()) {
|
||||
final NetworkConnectorConnectionsMessage message = new NetworkConnectorConnectionsMessage(this);
|
||||
Network.sendToClientsTrackingTileEntity(message, this);
|
||||
Network.sendToClientsTrackingBlockEntity(message, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +456,7 @@ public final class NetworkConnectorTileEntity extends AbstractTileEntity {
|
||||
dst.writeEthernetFrame(this, frame, timeToLive - TTL_COST);
|
||||
});
|
||||
|
||||
for (final NetworkConnectorTileEntity dst : connectors.values()) {
|
||||
for (final NetworkConnectorBlockEntity dst : connectors.values()) {
|
||||
if (dst.isRemoved() || dst.networkInterface == source) {
|
||||
continue;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.api.capabilities.NetworkInterface;
|
||||
import li.cil.oc2.common.Constants;
|
||||
@@ -11,7 +11,7 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class NetworkHubTileEntity extends AbstractTileEntity implements NetworkInterface {
|
||||
public final class NetworkHubBlockEntity extends ModBlockEntity implements NetworkInterface {
|
||||
private static final int TTL_COST = 1;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -21,8 +21,8 @@ public final class NetworkHubTileEntity extends AbstractTileEntity implements Ne
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public NetworkHubTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.NETWORK_HUB_TILE_ENTITY.get(), pos, state);
|
||||
public NetworkHubBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.NETWORK_HUB.get(), pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -71,9 +71,9 @@ public final class NetworkHubTileEntity extends AbstractTileEntity implements Ne
|
||||
for (final Direction side : Constants.DIRECTIONS) {
|
||||
adjacentInterfaces[side.get3DDataValue()] = null;
|
||||
|
||||
final BlockEntity neighborTileEntity = level.getBlockEntity(pos.relative(side));
|
||||
if (neighborTileEntity != null) {
|
||||
final LazyOptional<NetworkInterface> capability = neighborTileEntity.getCapability(Capabilities.NETWORK_INTERFACE, side.getOpposite());
|
||||
final BlockEntity neighborBlockEntity = level.getBlockEntity(pos.relative(side));
|
||||
if (neighborBlockEntity != null) {
|
||||
final LazyOptional<NetworkInterface> capability = neighborBlockEntity.getCapability(Capabilities.NETWORK_INTERFACE, side.getOpposite());
|
||||
capability.ifPresent(adjacentInterface -> {
|
||||
adjacentInterfaces[side.get3DDataValue()] = adjacentInterface;
|
||||
capability.addListener(unused -> handleNeighborChanged());
|
||||
@@ -1,4 +1,4 @@
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import li.cil.oc2.api.bus.device.object.Callback;
|
||||
import li.cil.oc2.api.bus.device.object.DocumentedDevice;
|
||||
@@ -20,7 +20,7 @@ import java.util.Collection;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public final class RedstoneInterfaceTileEntity extends BlockEntity implements NamedDevice, DocumentedDevice {
|
||||
public final class RedstoneInterfaceBlockEntity extends BlockEntity implements NamedDevice, DocumentedDevice {
|
||||
private static final String OUTPUT_TAG_NAME = "output";
|
||||
|
||||
private static final String GET_REDSTONE_INPUT = "getRedstoneInput";
|
||||
@@ -35,8 +35,8 @@ public final class RedstoneInterfaceTileEntity extends BlockEntity implements Na
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public RedstoneInterfaceTileEntity(final BlockPos pos, final BlockState state) {
|
||||
super(TileEntities.REDSTONE_INTERFACE_TILE_ENTITY.get(), pos, state);
|
||||
public RedstoneInterfaceBlockEntity(final BlockPos pos, final BlockState state) {
|
||||
super(BlockEntities.REDSTONE_INTERFACE.get(), pos, state);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -1,6 +1,6 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package li.cil.oc2.common.tileentity;
|
||||
package li.cil.oc2.common.blockentity;
|
||||
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
@@ -3,28 +3,28 @@ package li.cil.oc2.common.bus;
|
||||
import li.cil.oc2.api.bus.BlockDeviceBusElement;
|
||||
import li.cil.oc2.api.bus.DeviceBusElement;
|
||||
import li.cil.oc2.common.util.ServerScheduler;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class TileEntityDeviceBusController extends CommonDeviceBusController {
|
||||
public final class BlockEntityDeviceBusController extends CommonDeviceBusController {
|
||||
private final Runnable onBusChunkLoadedStateChanged = this::scheduleBusScan;
|
||||
private final HashSet<TrackedChunk> trackedChunks = new HashSet<>();
|
||||
private final BlockEntity tileEntity;
|
||||
private final BlockEntity blockEntity;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public TileEntityDeviceBusController(final DeviceBusElement root, final int baseEnergyConsumption, final BlockEntity tileEntity) {
|
||||
public BlockEntityDeviceBusController(final DeviceBusElement root, final int baseEnergyConsumption, final BlockEntity blockEntity) {
|
||||
super(root, baseEnergyConsumption);
|
||||
this.tileEntity = tileEntity;
|
||||
this.blockEntity = blockEntity;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -43,28 +43,27 @@ public final class TileEntityDeviceBusController extends CommonDeviceBusControll
|
||||
protected void onAfterBusScan() {
|
||||
super.onAfterBusScan();
|
||||
|
||||
final Level world = tileEntity.getLevel();
|
||||
if (world == null) {
|
||||
final Level level = blockEntity.getLevel();
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final HashSet<TrackedChunk> newTrackedChunks = new HashSet<>();
|
||||
for (final DeviceBusElement element : getElements()) {
|
||||
if (element instanceof BlockDeviceBusElement) {
|
||||
final BlockDeviceBusElement blockElement = (BlockDeviceBusElement) element;
|
||||
final LevelAccessor elementWorld = blockElement.getLevel();
|
||||
if (element instanceof final BlockDeviceBusElement blockElement) {
|
||||
final LevelAccessor elementLevel = blockElement.getLevel();
|
||||
final BlockPos elementPosition = blockElement.getPosition();
|
||||
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition));
|
||||
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.NORTH)));
|
||||
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.EAST)));
|
||||
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.SOUTH)));
|
||||
newTrackedChunks.add(new TrackedChunk(elementWorld, elementPosition.relative(Direction.WEST)));
|
||||
newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition));
|
||||
newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.NORTH)));
|
||||
newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.EAST)));
|
||||
newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.SOUTH)));
|
||||
newTrackedChunks.add(new TrackedChunk(elementLevel, elementPosition.relative(Direction.WEST)));
|
||||
}
|
||||
}
|
||||
|
||||
// Do not track the chunk the controller itself is in -- this is unneeded because
|
||||
// we expect the controller to be disposed if its chunk is unloaded.
|
||||
newTrackedChunks.remove(new TrackedChunk(world, tileEntity.getBlockPos()));
|
||||
newTrackedChunks.remove(new TrackedChunk(level, blockEntity.getBlockPos()));
|
||||
|
||||
final HashSet<TrackedChunk> removedChunks = new HashSet<>(trackedChunks);
|
||||
removedChunks.removeAll(newTrackedChunks);
|
||||
@@ -82,28 +81,30 @@ public final class TileEntityDeviceBusController extends CommonDeviceBusControll
|
||||
|
||||
private void addListeners(final Collection<TrackedChunk> trackedChunks) {
|
||||
for (final TrackedChunk trackedChunk : trackedChunks) {
|
||||
final LevelAccessor world = trackedChunk.world.get();
|
||||
ServerScheduler.scheduleOnLoad(world, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
ServerScheduler.scheduleOnUnload(world, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
final LevelAccessor level = trackedChunk.level.get();
|
||||
if (level != null) {
|
||||
ServerScheduler.scheduleOnLoad(level, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
ServerScheduler.scheduleOnUnload(level, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeListeners(final Collection<TrackedChunk> trackedChunks) {
|
||||
for (final TrackedChunk trackedChunk : trackedChunks) {
|
||||
final LevelAccessor world = trackedChunk.world.get();
|
||||
if (world != null) {
|
||||
ServerScheduler.cancelOnLoad(world, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
ServerScheduler.cancelOnUnload(world, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
final LevelAccessor level = trackedChunk.level.get();
|
||||
if (level != null) {
|
||||
ServerScheduler.cancelOnLoad(level, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
ServerScheduler.cancelOnUnload(level, trackedChunk.position, onBusChunkLoadedStateChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TrackedChunk {
|
||||
public final WeakReference<LevelAccessor> world;
|
||||
public final WeakReference<LevelAccessor> level;
|
||||
public final ChunkPos position;
|
||||
|
||||
private TrackedChunk(final LevelAccessor world, final BlockPos position) {
|
||||
this.world = new WeakReference<>(world);
|
||||
private TrackedChunk(final LevelAccessor level, final BlockPos position) {
|
||||
this.level = new WeakReference<>(level);
|
||||
this.position = new ChunkPos(position);
|
||||
}
|
||||
|
||||
@@ -112,12 +113,12 @@ public final class TileEntityDeviceBusController extends CommonDeviceBusControll
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final TrackedChunk that = (TrackedChunk) o;
|
||||
return world.equals(that.world) && position.equals(that.position);
|
||||
return level.equals(that.level) && position.equals(that.position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(world, position);
|
||||
return Objects.hash(level, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import li.cil.oc2.common.bus.device.util.BlockDeviceInfo;
|
||||
import li.cil.oc2.common.bus.device.util.Devices;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import li.cil.oc2.common.util.ServerScheduler;
|
||||
import li.cil.oc2.common.util.WorldUtils;
|
||||
import li.cil.oc2.common.util.LevelUtils;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -27,32 +27,33 @@ import java.util.Optional;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusElement implements BlockDeviceBusElement {
|
||||
private final BlockEntity tileEntity;
|
||||
public class BlockEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusElement implements BlockDeviceBusElement {
|
||||
private final BlockEntity blockEntity;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public TileEntityDeviceBusElement(final BlockEntity tileEntity) {
|
||||
public BlockEntityDeviceBusElement(final BlockEntity blockEntity) {
|
||||
super(Constants.BLOCK_FACE_COUNT);
|
||||
this.tileEntity = tileEntity;
|
||||
this.blockEntity = blockEntity;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public LevelAccessor getLevel() {
|
||||
return tileEntity.getLevel();
|
||||
return blockEntity.getLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getPosition() {
|
||||
return tileEntity.getBlockPos();
|
||||
return blockEntity.getBlockPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Collection<LazyOptional<DeviceBusElement>>> getNeighbors() {
|
||||
final Level world = tileEntity.getLevel();
|
||||
if (world == null || world.isClientSide()) {
|
||||
final Level level = blockEntity.getLevel();
|
||||
if (level == null || level.isClientSide()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -62,19 +63,19 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
continue;
|
||||
}
|
||||
|
||||
final BlockPos neighborPos = tileEntity.getBlockPos().relative(neighborDirection);
|
||||
final BlockPos neighborPos = blockEntity.getBlockPos().relative(neighborDirection);
|
||||
|
||||
final ChunkPos chunkPos = new ChunkPos(neighborPos);
|
||||
if (!world.hasChunk(chunkPos.x, chunkPos.z)) {
|
||||
if (!level.hasChunk(chunkPos.x, chunkPos.z)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final BlockEntity tileEntity = world.getBlockEntity(neighborPos);
|
||||
if (tileEntity == null) {
|
||||
final BlockEntity blockEntity = level.getBlockEntity(neighborPos);
|
||||
if (blockEntity == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final LazyOptional<DeviceBusElement> capability = tileEntity.getCapability(Capabilities.DEVICE_BUS_ELEMENT, neighborDirection.getOpposite());
|
||||
final LazyOptional<DeviceBusElement> capability = blockEntity.getCapability(Capabilities.DEVICE_BUS_ELEMENT, neighborDirection.getOpposite());
|
||||
if (capability.isPresent()) {
|
||||
neighbors.add(capability);
|
||||
}
|
||||
@@ -84,27 +85,27 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
}
|
||||
|
||||
public void handleNeighborChanged(final BlockPos pos) {
|
||||
final Level world = tileEntity.getLevel();
|
||||
if (world == null || world.isClientSide()) {
|
||||
final Level level = blockEntity.getLevel();
|
||||
if (level == null || level.isClientSide()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockPos toPos = pos.subtract(tileEntity.getBlockPos());
|
||||
final BlockPos toPos = pos.subtract(blockEntity.getBlockPos());
|
||||
final Direction direction = Direction.fromNormal(toPos.getX(), toPos.getY(), toPos.getZ());
|
||||
if (direction == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final HashSet<BlockDeviceInfo> newDevices = collectDevices(world, pos, direction);
|
||||
final HashSet<BlockDeviceInfo> newDevices = collectDevices(level, pos, direction);
|
||||
|
||||
final int index = direction.get3DDataValue();
|
||||
setDevicesForGroup(index, newDevices);
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
final Level world = requireNonNull(tileEntity.getLevel());
|
||||
ServerScheduler.schedule(world, () -> {
|
||||
if (tileEntity.isRemoved()) {
|
||||
final Level level = requireNonNull(blockEntity.getLevel());
|
||||
ServerScheduler.schedule(level, () -> {
|
||||
if (blockEntity.isRemoved()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -123,23 +124,23 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
return canScanContinueTowards(direction);
|
||||
}
|
||||
|
||||
protected HashSet<BlockDeviceInfo> collectDevices(final Level world, final BlockPos pos, @Nullable final Direction direction) {
|
||||
protected HashSet<BlockDeviceInfo> collectDevices(final Level level, final BlockPos pos, @Nullable final Direction direction) {
|
||||
final HashSet<BlockDeviceInfo> newDevices = new HashSet<>();
|
||||
if (canDetectDevicesTowards(direction)) {
|
||||
final BlockDeviceQuery query = Devices.makeQuery(world, pos, direction);
|
||||
final BlockDeviceQuery query = Devices.makeQuery(level, pos, direction);
|
||||
for (final LazyOptional<BlockDeviceInfo> deviceInfo : Devices.getDevices(query)) {
|
||||
deviceInfo.ifPresent(newDevices::add);
|
||||
deviceInfo.addListener(unused -> handleNeighborChanged(pos));
|
||||
}
|
||||
}
|
||||
|
||||
collectSyntheticDevices(world, pos, direction, newDevices);
|
||||
collectSyntheticDevices(level, pos, direction, newDevices);
|
||||
|
||||
return newDevices;
|
||||
}
|
||||
|
||||
protected void collectSyntheticDevices(final Level world, final BlockPos pos, @Nullable final Direction direction, final HashSet<BlockDeviceInfo> devices) {
|
||||
final String blockName = WorldUtils.getBlockName(world, pos);
|
||||
protected void collectSyntheticDevices(final Level level, final BlockPos pos, @Nullable final Direction direction, final HashSet<BlockDeviceInfo> devices) {
|
||||
final String blockName = LevelUtils.getBlockName(level, pos);
|
||||
if (blockName != null) {
|
||||
devices.add(new BlockDeviceInfo(null, new TypeNameRPCDevice(blockName)));
|
||||
}
|
||||
@@ -149,21 +150,21 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
|
||||
|
||||
private void scanNeighborsForDevices() {
|
||||
for (final Direction direction : Constants.DIRECTIONS) {
|
||||
handleNeighborChanged(tileEntity.getBlockPos().relative(direction));
|
||||
handleNeighborChanged(blockEntity.getBlockPos().relative(direction));
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleBusScanInAdjacentBusElements() {
|
||||
final Level world = requireNonNull(tileEntity.getLevel());
|
||||
final BlockPos pos = tileEntity.getBlockPos();
|
||||
final Level level = requireNonNull(blockEntity.getLevel());
|
||||
final BlockPos pos = blockEntity.getBlockPos();
|
||||
for (final Direction direction : Constants.DIRECTIONS) {
|
||||
final BlockPos neighborPos = pos.relative(direction);
|
||||
final BlockEntity tileEntity = WorldUtils.getBlockEntityIfChunkExists(world, neighborPos);
|
||||
if (tileEntity == null) {
|
||||
final BlockEntity blockEntity = LevelUtils.getBlockEntityIfChunkExists(level, neighborPos);
|
||||
if (blockEntity == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final LazyOptional<DeviceBusElement> capability = tileEntity
|
||||
final LazyOptional<DeviceBusElement> capability = blockEntity
|
||||
.getCapability(Capabilities.DEVICE_BUS_ELEMENT, direction.getOpposite());
|
||||
capability.ifPresent(DeviceBus::scheduleScan);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class CommonDeviceBusController implements DeviceBusController {
|
||||
for (final Device device : element.getLocalDevices()) {
|
||||
newDevices.add(device);
|
||||
element.getDeviceIdentifier(device).ifPresent(identifier -> newDeviceIds
|
||||
.computeIfAbsent(device, unused -> new HashSet<>()).add(identifier));
|
||||
.computeIfAbsent(device, unused -> new HashSet<>()).add(identifier));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class CommonDeviceBusController implements DeviceBusController {
|
||||
didDeviceIdsChange = true;
|
||||
} else {
|
||||
didDeviceIdsChange = deviceIds.entrySet().stream().anyMatch(entry ->
|
||||
!Objects.equals(entry.getValue(), newDeviceIds.get(entry.getKey())));
|
||||
!Objects.equals(entry.getValue(), newDeviceIds.get(entry.getKey())));
|
||||
}
|
||||
|
||||
if (didDeviceIdsChange) {
|
||||
@@ -159,7 +159,7 @@ public class CommonDeviceBusController implements DeviceBusController {
|
||||
final DeviceBusElement element = open.pop();
|
||||
|
||||
final Optional<Collection<LazyOptional<DeviceBusElement>>> elementNeighbors = element.getNeighbors();
|
||||
if (!elementNeighbors.isPresent()) {
|
||||
if (elementNeighbors.isEmpty()) {
|
||||
scanDelay = INCOMPLETE_RETRY_INTERVAL;
|
||||
state = BusState.INCOMPLETE;
|
||||
return;
|
||||
@@ -270,19 +270,7 @@ public class CommonDeviceBusController implements DeviceBusController {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public static final class AfterDeviceScanEvent {
|
||||
public final boolean didDevicesChange;
|
||||
public record AfterDeviceScanEvent(boolean didDevicesChange) { }
|
||||
|
||||
public AfterDeviceScanEvent(final boolean didDevicesChange) {
|
||||
this.didDevicesChange = didDevicesChange;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class DevicesChangedEvent {
|
||||
public final Collection<Device> devices;
|
||||
|
||||
public DevicesChangedEvent(final Collection<Device> devices) {
|
||||
this.devices = devices;
|
||||
}
|
||||
}
|
||||
public record DevicesChangedEvent(Collection<Device> devices) { }
|
||||
}
|
||||
|
||||
@@ -118,8 +118,7 @@ public final class RPCDeviceBusAdapter implements Steppable {
|
||||
|
||||
final HashMap<UUID, ArrayList<RPCDevice>> devicesByIdentifier = new HashMap<>();
|
||||
for (final Device device : controller.getDevices()) {
|
||||
if (device instanceof RPCDevice) {
|
||||
final RPCDevice rpcDevice = (RPCDevice) device;
|
||||
if (device instanceof final RPCDevice rpcDevice) {
|
||||
final Set<UUID> identifiers = controller.getDeviceIdentifiers(device);
|
||||
for (final UUID identifier : identifiers) {
|
||||
devicesByIdentifier
|
||||
@@ -247,30 +246,22 @@ public final class RPCDeviceBusAdapter implements Steppable {
|
||||
try {
|
||||
final Message message = gson.fromJson(stream, Message.class);
|
||||
switch (message.type) {
|
||||
case Message.MESSAGE_TYPE_LIST: {
|
||||
writeDeviceList();
|
||||
break;
|
||||
}
|
||||
case Message.MESSAGE_TYPE_METHODS: {
|
||||
case Message.MESSAGE_TYPE_LIST -> writeDeviceList();
|
||||
case Message.MESSAGE_TYPE_METHODS -> {
|
||||
if (message.data != null) {
|
||||
writeDeviceMethods((UUID) message.data);
|
||||
} else {
|
||||
writeError("missing device id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Message.MESSAGE_TYPE_INVOKE_METHOD: {
|
||||
case Message.MESSAGE_TYPE_INVOKE_METHOD -> {
|
||||
if (message.data != null) {
|
||||
processMethodInvocation((MethodInvocation) message.data, false);
|
||||
} else {
|
||||
writeError("missing invocation data");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
writeError(ERROR_UNKNOWN_MESSAGE_TYPE);
|
||||
break;
|
||||
}
|
||||
default -> writeError(ERROR_UNKNOWN_MESSAGE_TYPE);
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
writeError(e.getMessage());
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
//package li.cil.oc2.common.bus.device.data;
|
||||
//
|
||||
//import li.cil.oc2.api.bus.device.data.Firmware;
|
||||
//import li.cil.sedna.api.memory.MemoryMap;
|
||||
//import li.cil.sedna.memory.MemoryMaps;
|
||||
//import li.cil.sednamc.Sedna;
|
||||
//import net.minecraft.network.chat.Component;
|
||||
//import net.minecraft.network.chat.TextComponent;
|
||||
//import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//
|
||||
//public final class ELuaFirmware extends ForgeRegistryEntry<Firmware> implements Firmware {
|
||||
// @Override
|
||||
// public boolean run(final MemoryMap memory, final long startAddress) {
|
||||
// try {
|
||||
// MemoryMaps.store(memory, startAddress, Sedna.getELua());
|
||||
// return true;
|
||||
// } catch (final IOException e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Component getDisplayName() {
|
||||
// return new TextComponent("eLua");
|
||||
// }
|
||||
//}
|
||||
@@ -7,11 +7,11 @@ import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
|
||||
import li.cil.oc2.common.vm.fs.LayeredFileSystem;
|
||||
import li.cil.sedna.fs.FileSystem;
|
||||
import li.cil.sedna.fs.ZipStreamFileSystem;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.AddReloadListenerEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -54,7 +54,7 @@ public final class FileSystems {
|
||||
|
||||
LOGGER.info("Searching for datapack filesystems...");
|
||||
final Collection<ResourceLocation> fileSystemDescriptorLocations = resourceManager
|
||||
.listResources("file_systems", s -> s.endsWith(".json"));
|
||||
.listResources("file_systems", s -> s.endsWith(".json"));
|
||||
|
||||
final ArrayList<ZipStreamFileSystem> fileSystems = new ArrayList<>();
|
||||
final Object2IntArrayMap<ZipStreamFileSystem> fileSystemOrder = new Object2IntArrayMap<>();
|
||||
@@ -63,10 +63,10 @@ public final class FileSystems {
|
||||
LOGGER.info("Found [{}]", fileSystemDescriptorLocation);
|
||||
try {
|
||||
final Resource fileSystemDescriptor = resourceManager.getResource(fileSystemDescriptorLocation);
|
||||
final JsonObject json = new JsonParser().parse(new InputStreamReader(fileSystemDescriptor.getInputStream())).getAsJsonObject();
|
||||
final JsonObject json = JsonParser.parseReader(new InputStreamReader(fileSystemDescriptor.getInputStream())).getAsJsonObject();
|
||||
final String type = json.getAsJsonPrimitive("type").getAsString();
|
||||
switch (type) {
|
||||
case "layer": {
|
||||
case "layer" -> {
|
||||
final ResourceLocation location = new ResourceLocation(json.getAsJsonPrimitive("location").getAsString());
|
||||
|
||||
final ZipStreamFileSystem fileSystem;
|
||||
@@ -88,16 +88,9 @@ public final class FileSystems {
|
||||
} else {
|
||||
fileSystemOrder.put(fileSystem, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "block": {
|
||||
LOGGER.error("Not yet implemented.");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
LOGGER.error("Unsupported file system type [{}].", type);
|
||||
break;
|
||||
}
|
||||
case "block" -> LOGGER.error("Not yet implemented.");
|
||||
default -> LOGGER.error("Unsupported file system type [{}].", type);
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
LOGGER.error(e);
|
||||
@@ -116,8 +109,8 @@ public final class FileSystems {
|
||||
@Override
|
||||
public CompletableFuture<Void> reload(final PreparableReloadListener.PreparationBarrier stage, final ResourceManager resourceManager, final ProfilerFiller preparationsProfiler, final ProfilerFiller reloadProfiler, final Executor backgroundExecutor, final Executor gameExecutor) {
|
||||
return CompletableFuture
|
||||
.runAsync(() -> FileSystems.reload(resourceManager), backgroundExecutor)
|
||||
.thenCompose(stage::wait);
|
||||
.runAsync(() -> FileSystems.reload(resourceManager), backgroundExecutor)
|
||||
.thenCompose(stage::wait);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,24 +6,32 @@ import li.cil.oc2.api.capabilities.Robot;
|
||||
import li.cil.oc2.api.util.RobotOperationSide;
|
||||
import li.cil.oc2.common.Config;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.tags.ItemTags;
|
||||
import li.cil.oc2.common.util.FakePlayerUtils;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Tier;
|
||||
import net.minecraft.world.item.TieredItem;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.CommandBlock;
|
||||
import net.minecraft.world.level.block.JigsawBlock;
|
||||
import net.minecraft.world.level.block.StructureBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.TierSortingRegistry;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
@@ -32,13 +40,6 @@ import net.minecraftforge.items.ItemStackHandler;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.CommandBlock;
|
||||
import net.minecraft.world.level.block.JigsawBlock;
|
||||
import net.minecraft.world.level.block.StructureBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
|
||||
private static final String LAST_OPERATION_TAG_NAME = "cooldown";
|
||||
|
||||
@@ -132,10 +133,10 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
|
||||
final BlockPos blockPos = entity.blockPosition().relative(direction);
|
||||
final Direction oppositeDirection = direction.getOpposite();
|
||||
final BlockHitResult hit = new BlockHitResult(
|
||||
Vec3.atCenterOf(blockPos).add(Vec3.atCenterOf(oppositeDirection.getNormal()).scale(0.5)),
|
||||
oppositeDirection,
|
||||
blockPos,
|
||||
false);
|
||||
Vec3.atCenterOf(blockPos).add(Vec3.atCenterOf(oppositeDirection.getNormal()).scale(0.5)),
|
||||
oppositeDirection,
|
||||
blockPos,
|
||||
false);
|
||||
|
||||
final ItemStack itemStack = extracted.copy();
|
||||
final BlockItem blockItem = (BlockItem) itemStack.getItem();
|
||||
@@ -176,7 +177,7 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
|
||||
|
||||
final ItemStack extracted = inventory.extractItem(selectedSlot, 1, true);
|
||||
|
||||
final Tiers tier = getRepairItemTier(extracted);
|
||||
final Tier tier = getRepairItemTier(extracted);
|
||||
if (tier == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -210,27 +211,27 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
|
||||
return entity.level.getEntitiesOfClass(ItemEntity.class, entity.getBoundingBox().inflate(2));
|
||||
}
|
||||
|
||||
private boolean tryHarvestBlock(final Level world, final BlockPos blockPos) {
|
||||
private boolean tryHarvestBlock(final Level level, final BlockPos blockPos) {
|
||||
// This method is based on PlayerInteractionManager::tryHarvestBlock. Simplified for our needs.
|
||||
final BlockState blockState = world.getBlockState(blockPos);
|
||||
final BlockState blockState = level.getBlockState(blockPos);
|
||||
if (blockState.isAir()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ServerPlayer player = FakePlayerUtils.getFakePlayer((ServerLevel) world, entity);
|
||||
final int experience = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, GameType.DEFAULT_MODE, player, blockPos);
|
||||
final ServerPlayer player = FakePlayerUtils.getFakePlayer((ServerLevel) level, entity);
|
||||
final int experience = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(level, GameType.DEFAULT_MODE, player, blockPos);
|
||||
if (experience == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final BlockEntity tileEntity = world.getBlockEntity(blockPos);
|
||||
final BlockEntity blockEntity = level.getBlockEntity(blockPos);
|
||||
final Block block = blockState.getBlock();
|
||||
final boolean isCommandBlock = block instanceof CommandBlock || block instanceof StructureBlock || block instanceof JigsawBlock;
|
||||
if (isCommandBlock && !player.canUseGameMasterBlocks()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.blockActionRestricted(world, blockPos, GameType.DEFAULT_MODE)) {
|
||||
if (player.blockActionRestricted(level, blockPos, GameType.DEFAULT_MODE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -243,39 +244,28 @@ public final class BlockOperationsModuleDevice extends AbstractItemRPCDevice {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (identity.hurt(1, world.random, null)) {
|
||||
if (identity.hurt(1, level.random, null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!blockState.onDestroyedByPlayer(world, blockPos, player, true, world.getFluidState(blockPos))) {
|
||||
if (!blockState.onDestroyedByPlayer(level, blockPos, player, true, level.getFluidState(blockPos))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
block.destroy(world, blockPos, blockState);
|
||||
block.playerDestroy(world, player, blockPos, blockState, tileEntity, ItemStack.EMPTY);
|
||||
block.destroy(level, blockPos, blockState);
|
||||
block.playerDestroy(level, player, blockPos, blockState, blockEntity, ItemStack.EMPTY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Tiers getRepairItemTier(final ItemStack stack) {
|
||||
private Tier getRepairItemTier(final ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Item item = stack.getItem();
|
||||
if (ItemTags.TOOL_MATERIAL_NETHERITE.contains(item)) {
|
||||
return Tiers.NETHERITE;
|
||||
} else if (ItemTags.TOOL_MATERIAL_GOLD.contains(item)) {
|
||||
return Tiers.DIAMOND;
|
||||
} else if (ItemTags.TOOL_MATERIAL_DIAMOND.contains(item)) {
|
||||
return Tiers.GOLD;
|
||||
} else if (ItemTags.TOOL_MATERIAL_IRON.contains(item)) {
|
||||
return Tiers.IRON;
|
||||
} else if (ItemTags.TOOL_MATERIAL_STONE.contains(item)) {
|
||||
return Tiers.STONE;
|
||||
} else if (ItemTags.TOOL_MATERIAL_WOOD.contains(item)) {
|
||||
return Tiers.WOOD;
|
||||
if (stack.getItem() instanceof TieredItem tieredItem) {
|
||||
return tieredItem.getTier();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -81,7 +81,7 @@ public final class ByteBufferFlashMemoryVMDevice extends IdentityProxy<ItemStack
|
||||
|
||||
@Subscribe
|
||||
public void handleInitializingEvent(final VMInitializingEvent event) {
|
||||
copyDataToMemory(event.getProgramStartAddress());
|
||||
copyDataToMemory(event.programStartAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -163,7 +163,7 @@ public final class FileImportExportCardItemDevice extends AbstractItemRPCDevice
|
||||
}
|
||||
|
||||
@Callback(name = WRITE_EXPORT_FILE, synchronize = false)
|
||||
public void writeExportFile(@Parameter(DATA) final byte[] data) throws IOException {
|
||||
public void writeExportFile(@Parameter(DATA) @Nullable final byte[] data) throws IOException {
|
||||
if (state != State.EXPORTING) {
|
||||
throw new IllegalStateException("invalid state");
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class FirmwareFlashMemoryVMDevice extends IdentityProxy<ItemStack>
|
||||
|
||||
@Subscribe
|
||||
public void handleInitializingEvent(final VMInitializingEvent event) {
|
||||
copyDataToMemory(event.getProgramStartAddress());
|
||||
copyDataToMemory(event.programStartAddress());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -81,7 +81,7 @@ public final class InventoryOperationsModuleDevice extends AbstractItemRPCDevice
|
||||
|
||||
final int originalStackSize = stack.getCount();
|
||||
final Direction direction = RobotOperationSide.getAdjustedDirection(side, entity);
|
||||
final List<IItemHandler> itemHandlers = getItemStackHandlersInDirection(direction).collect(Collectors.toList());
|
||||
final List<IItemHandler> itemHandlers = getItemStackHandlersInDirection(direction).toList();
|
||||
for (final IItemHandler handler : itemHandlers) {
|
||||
stack = ItemHandlerHelper.insertItemStacked(handler, stack, false);
|
||||
|
||||
@@ -204,12 +204,12 @@ public final class InventoryOperationsModuleDevice extends AbstractItemRPCDevice
|
||||
|
||||
private Stream<IItemHandler> getBlockItemHandlersAt(final Vec3 position, final Direction side) {
|
||||
final BlockPos pos = new BlockPos(position);
|
||||
final BlockEntity tileEntity = entity.level.getBlockEntity(pos);
|
||||
if (tileEntity == null) {
|
||||
final BlockEntity blockEntity = entity.level.getBlockEntity(pos);
|
||||
if (blockEntity == null) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
final LazyOptional<IItemHandler> capability = tileEntity.getCapability(Capabilities.ITEM_HANDLER, side);
|
||||
final LazyOptional<IItemHandler> capability = blockEntity.getCapability(Capabilities.ITEM_HANDLER, side);
|
||||
if (capability.isPresent()) {
|
||||
return Stream.of(capability.orElseThrow(AssertionError::new));
|
||||
}
|
||||
@@ -264,7 +264,7 @@ public final class InventoryOperationsModuleDevice extends AbstractItemRPCDevice
|
||||
|
||||
remaining -= delta;
|
||||
|
||||
// Do actual run, take as many as we know we can based on simulation.
|
||||
// Do actual run, take as many as we know we can, based on simulation.
|
||||
extracted = handler.extractItem(fromSlot, delta, false);
|
||||
overflow = insertStartingAt(inventory, extracted, selectedSlot, false);
|
||||
|
||||
@@ -297,7 +297,7 @@ public final class InventoryOperationsModuleDevice extends AbstractItemRPCDevice
|
||||
|
||||
int taken = extracted.getCount() - overflow.getCount();
|
||||
|
||||
// Do actual run, take as many as we know we can based on simulation.
|
||||
// Do actual run, take as many as we know we can, based on simulation.
|
||||
extracted = handler.extractItem(slot, taken, false);
|
||||
overflow = insertStartingAt(inventory, extracted, selectedSlot, false);
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public final class NetworkInterfaceCardItemDevice extends IdentityProxy<ItemStack> implements VMDevice, ItemDevice, ICapabilityProvider {
|
||||
private static final String DEVICE_TAG_NAME = "device";
|
||||
private static final String ADDRESS_TAG_NAME = "address";
|
||||
|
||||
@@ -34,15 +34,15 @@ public final class RedstoneInterfaceCardItemDevice extends AbstractItemRPCDevice
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private final BlockEntity tileEntity;
|
||||
private final BlockEntity blockEntity;
|
||||
private final RedstoneEmitter[] capabilities;
|
||||
private final byte[] output = new byte[Constants.BLOCK_FACE_COUNT];
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public RedstoneInterfaceCardItemDevice(final ItemStack identity, final BlockEntity tileEntity) {
|
||||
public RedstoneInterfaceCardItemDevice(final ItemStack identity, final BlockEntity blockEntity) {
|
||||
super(identity, "redstone");
|
||||
this.tileEntity = tileEntity;
|
||||
this.blockEntity = blockEntity;
|
||||
|
||||
capabilities = new RedstoneEmitter[Constants.BLOCK_FACE_COUNT];
|
||||
for (int i = 0; i < Constants.BLOCK_FACE_COUNT; i++) {
|
||||
@@ -80,22 +80,22 @@ public final class RedstoneInterfaceCardItemDevice extends AbstractItemRPCDevice
|
||||
public int getRedstoneInput(@Parameter(SIDE) @Nullable final Side side) {
|
||||
if (side == null) throw new IllegalArgumentException();
|
||||
|
||||
final Level world = tileEntity.getLevel();
|
||||
if (world == null) {
|
||||
final Level level = blockEntity.getLevel();
|
||||
if (level == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final BlockPos pos = tileEntity.getBlockPos();
|
||||
final Direction direction = HorizontalBlockUtils.toGlobal(tileEntity.getBlockState(), side);
|
||||
final BlockPos pos = blockEntity.getBlockPos();
|
||||
final Direction direction = HorizontalBlockUtils.toGlobal(blockEntity.getBlockState(), side);
|
||||
assert direction != null;
|
||||
|
||||
final BlockPos neighborPos = pos.relative(direction);
|
||||
final ChunkPos chunkPos = new ChunkPos(neighborPos.getX(), neighborPos.getZ());
|
||||
if (!world.hasChunk(chunkPos.x, chunkPos.z)) {
|
||||
if (!level.hasChunk(chunkPos.x, chunkPos.z)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return world.getSignal(neighborPos, direction);
|
||||
return level.getSignal(neighborPos, direction);
|
||||
}
|
||||
|
||||
@Callback(name = GET_REDSTONE_OUTPUT, synchronize = false)
|
||||
@@ -116,7 +116,7 @@ public final class RedstoneInterfaceCardItemDevice extends AbstractItemRPCDevice
|
||||
|
||||
output[side.get3DDataValue()] = clampedValue;
|
||||
|
||||
final Direction direction = HorizontalBlockUtils.toGlobal(tileEntity.getBlockState(), side);
|
||||
final Direction direction = HorizontalBlockUtils.toGlobal(blockEntity.getBlockState(), side);
|
||||
if (direction != null) {
|
||||
notifyNeighbor(direction);
|
||||
}
|
||||
@@ -151,12 +151,12 @@ public final class RedstoneInterfaceCardItemDevice extends AbstractItemRPCDevice
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private void notifyNeighbor(final Direction direction) {
|
||||
final Level world = tileEntity.getLevel();
|
||||
if (world == null) {
|
||||
final Level level = blockEntity.getLevel();
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
world.updateNeighborsAt(tileEntity.getBlockPos(), tileEntity.getBlockState().getBlock());
|
||||
world.updateNeighborsAt(tileEntity.getBlockPos().relative(direction), tileEntity.getBlockState().getBlock());
|
||||
level.updateNeighborsAt(blockEntity.getBlockPos(), blockEntity.getBlockState().getBlock());
|
||||
level.updateNeighborsAt(blockEntity.getBlockPos().relative(direction), blockEntity.getBlockState().getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class SoundCardItemDevice extends AbstractItemRPCDevice {
|
||||
if (name == null) throw new IllegalArgumentException();
|
||||
|
||||
location.get().ifPresent(location -> {
|
||||
final LevelAccessor level = location.world;
|
||||
final LevelAccessor level = location.level();
|
||||
if (!(level instanceof ServerLevel)) {
|
||||
return;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public final class SoundCardItemDevice extends AbstractItemRPCDevice {
|
||||
|
||||
final SoundEvent soundEvent = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(name));
|
||||
if (soundEvent == null) throw new IllegalArgumentException("Sound not found.");
|
||||
level.playSound(null, location.pos, soundEvent, SoundSource.BLOCKS, 1, 1);
|
||||
level.playSound(null, location.pos(), soundEvent, SoundSource.BLOCKS, 1, 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public final class Providers {
|
||||
|
||||
public static void initialize() {
|
||||
BLOCK_DEVICE_PROVIDERS.register("block", BlockStateDeviceProvider::new);
|
||||
BLOCK_DEVICE_PROVIDERS.register("tile_entity", TileEntityDeviceProvider::new);
|
||||
BLOCK_DEVICE_PROVIDERS.register("block_entity", BlockEntityDeviceProvider::new);
|
||||
|
||||
BLOCK_DEVICE_PROVIDERS.register("energy_storage", EnergyStorageBlockDeviceProvider::new);
|
||||
BLOCK_DEVICE_PROVIDERS.register("fluid_handler", FluidHandlerBlockDeviceProvider::new);
|
||||
|
||||
@@ -4,15 +4,15 @@ import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.object.Callbacks;
|
||||
import li.cil.oc2.api.bus.device.object.ObjectDevice;
|
||||
import li.cil.oc2.api.bus.device.provider.BlockDeviceQuery;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractTileEntityDeviceProvider;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractBlockEntityDeviceProvider;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
public final class TileEntityDeviceProvider extends AbstractTileEntityDeviceProvider<BlockEntity> {
|
||||
public final class BlockEntityDeviceProvider extends AbstractBlockEntityDeviceProvider<BlockEntity> {
|
||||
@Override
|
||||
public LazyOptional<Device> getBlockDevice(final BlockDeviceQuery query, final BlockEntity tileEntity) {
|
||||
if (Callbacks.hasMethods(tileEntity)) {
|
||||
return LazyOptional.of(() -> new ObjectDevice(tileEntity));
|
||||
public LazyOptional<Device> getBlockDevice(final BlockDeviceQuery query, final BlockEntity blockEntity) {
|
||||
if (Callbacks.hasMethods(blockEntity)) {
|
||||
return LazyOptional.of(() -> new ObjectDevice(blockEntity));
|
||||
} else {
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
@@ -14,10 +14,10 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
public final class BlockStateDeviceProvider extends AbstractBlockDeviceProvider {
|
||||
@Override
|
||||
public LazyOptional<Device> getDevice(final BlockDeviceQuery query) {
|
||||
final Level world = query.getLevel();
|
||||
final Level level = query.getLevel();
|
||||
final BlockPos position = query.getQueryPosition();
|
||||
|
||||
final BlockState blockState = world.getBlockState(position);
|
||||
final BlockState blockState = level.getBlockState(position);
|
||||
|
||||
if (blockState.isAir()) {
|
||||
return LazyOptional.empty();
|
||||
|
||||
@@ -2,25 +2,25 @@ package li.cil.oc2.common.bus.device.provider.block;
|
||||
|
||||
import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.provider.BlockDeviceQuery;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractTileEntityDeviceProvider;
|
||||
import li.cil.oc2.common.tileentity.DiskDriveTileEntity;
|
||||
import li.cil.oc2.common.tileentity.TileEntities;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractBlockEntityDeviceProvider;
|
||||
import li.cil.oc2.common.blockentity.DiskDriveBlockEntity;
|
||||
import li.cil.oc2.common.blockentity.BlockEntities;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
public final class DiskDriveDeviceProvider extends AbstractTileEntityDeviceProvider<DiskDriveTileEntity> {
|
||||
public final class DiskDriveDeviceProvider extends AbstractBlockEntityDeviceProvider<DiskDriveBlockEntity> {
|
||||
public DiskDriveDeviceProvider() {
|
||||
super(TileEntities.DISK_DRIVE_TILE_ENTITY.get());
|
||||
super(BlockEntities.DISK_DRIVE.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LazyOptional<Device> getBlockDevice(final BlockDeviceQuery query, final DiskDriveTileEntity tileEntity) {
|
||||
protected LazyOptional<Device> getBlockDevice(final BlockDeviceQuery query, final DiskDriveBlockEntity blockEntity) {
|
||||
// We only allow connecting to exactly one face of the disk drive to ensure only one
|
||||
// bus (and thus, one VM) will access the device at any single time.
|
||||
if (query.getQuerySide() != tileEntity.getBlockState().getValue(HorizontalDirectionalBlock.FACING)) {
|
||||
if (query.getQuerySide() != blockEntity.getBlockState().getValue(HorizontalDirectionalBlock.FACING)) {
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
return LazyOptional.of(tileEntity::getDevice);
|
||||
return LazyOptional.of(blockEntity::getDevice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.object.Callback;
|
||||
import li.cil.oc2.api.bus.device.object.ObjectDevice;
|
||||
import li.cil.oc2.api.bus.device.provider.BlockDeviceQuery;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractTileEntityCapabilityDeviceProvider;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractBlockEntityCapabilityDeviceProvider;
|
||||
import li.cil.oc2.common.bus.device.util.IdentityProxy;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
public final class EnergyStorageBlockDeviceProvider extends AbstractTileEntityCapabilityDeviceProvider<IEnergyStorage, BlockEntity> {
|
||||
public final class EnergyStorageBlockDeviceProvider extends AbstractBlockEntityCapabilityDeviceProvider<IEnergyStorage, BlockEntity> {
|
||||
public EnergyStorageBlockDeviceProvider() {
|
||||
super(() -> Capabilities.ENERGY_STORAGE);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.object.Callback;
|
||||
import li.cil.oc2.api.bus.device.object.ObjectDevice;
|
||||
import li.cil.oc2.api.bus.device.provider.BlockDeviceQuery;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractTileEntityCapabilityDeviceProvider;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractBlockEntityCapabilityDeviceProvider;
|
||||
import li.cil.oc2.common.bus.device.util.IdentityProxy;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
@@ -12,7 +12,7 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
public final class FluidHandlerBlockDeviceProvider extends AbstractTileEntityCapabilityDeviceProvider<IFluidHandler, BlockEntity> {
|
||||
public final class FluidHandlerBlockDeviceProvider extends AbstractBlockEntityCapabilityDeviceProvider<IFluidHandler, BlockEntity> {
|
||||
public FluidHandlerBlockDeviceProvider() {
|
||||
super(() -> Capabilities.FLUID_HANDLER);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.object.Callback;
|
||||
import li.cil.oc2.api.bus.device.object.ObjectDevice;
|
||||
import li.cil.oc2.api.bus.device.provider.BlockDeviceQuery;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractTileEntityCapabilityDeviceProvider;
|
||||
import li.cil.oc2.common.bus.device.provider.util.AbstractBlockEntityCapabilityDeviceProvider;
|
||||
import li.cil.oc2.common.bus.device.util.IdentityProxy;
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -12,7 +12,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public final class ItemHandlerBlockDeviceProvider extends AbstractTileEntityCapabilityDeviceProvider<IItemHandler, BlockEntity> {
|
||||
public final class ItemHandlerBlockDeviceProvider extends AbstractBlockEntityCapabilityDeviceProvider<IItemHandler, BlockEntity> {
|
||||
public ItemHandlerBlockDeviceProvider() {
|
||||
super(() -> Capabilities.ITEM_HANDLER);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ public final class FileImportExportCardItemDeviceProvider extends AbstractItemDe
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private Optional<TerminalUserProvider> getTerminalUserProvider(final ItemDeviceQuery query) {
|
||||
if (query.getContainerTileEntity().isPresent()) {
|
||||
final LazyOptional<TerminalUserProvider> capability = query.getContainerTileEntity().get()
|
||||
if (query.getContainerBlockEntity().isPresent()) {
|
||||
final LazyOptional<TerminalUserProvider> capability = query.getContainerBlockEntity().get()
|
||||
.getCapability(Capabilities.TERMINAL_USER_PROVIDER);
|
||||
if (capability.isPresent()) {
|
||||
return capability.resolve();
|
||||
|
||||
@@ -18,7 +18,7 @@ public final class NetworkInterfaceCardItemDeviceProvider extends AbstractItemDe
|
||||
|
||||
@Override
|
||||
protected Optional<ItemDevice> getItemDevice(final ItemDeviceQuery query) {
|
||||
return query.getContainerTileEntity().map(tileEntity ->
|
||||
return query.getContainerBlockEntity().map(blockEntity ->
|
||||
new NetworkInterfaceCardItemDevice(query.getItemStack()));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ public final class RedstoneInterfaceCardItemDeviceProvider extends AbstractItemD
|
||||
|
||||
@Override
|
||||
protected Optional<ItemDevice> getItemDevice(final ItemDeviceQuery query) {
|
||||
return query.getContainerTileEntity().map(tileEntity ->
|
||||
new RedstoneInterfaceCardItemDevice(query.getItemStack(), tileEntity));
|
||||
return query.getContainerBlockEntity().map(blockEntity ->
|
||||
new RedstoneInterfaceCardItemDevice(query.getItemStack(), blockEntity));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,5 +3,4 @@ package li.cil.oc2.common.bus.device.provider.util;
|
||||
import li.cil.oc2.api.bus.device.provider.BlockDeviceProvider;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
|
||||
public abstract class AbstractBlockDeviceProvider extends ForgeRegistryEntry<BlockDeviceProvider> implements BlockDeviceProvider {
|
||||
}
|
||||
public abstract class AbstractBlockDeviceProvider extends ForgeRegistryEntry<BlockDeviceProvider> implements BlockDeviceProvider { }
|
||||
|
||||
@@ -9,27 +9,27 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class AbstractTileEntityCapabilityDeviceProvider<TCapability, TTileEntity extends BlockEntity> extends AbstractTileEntityDeviceProvider<TTileEntity> {
|
||||
public abstract class AbstractBlockEntityCapabilityDeviceProvider<TCapability, TBlockEntity extends BlockEntity> extends AbstractBlockEntityDeviceProvider<TBlockEntity> {
|
||||
private final Supplier<Capability<TCapability>> capabilitySupplier;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected AbstractTileEntityCapabilityDeviceProvider(final BlockEntityType<TTileEntity> tileEntityType, final Supplier<Capability<TCapability>> capabilitySupplier) {
|
||||
super(tileEntityType);
|
||||
protected AbstractBlockEntityCapabilityDeviceProvider(final BlockEntityType<TBlockEntity> blockEntityType, final Supplier<Capability<TCapability>> capabilitySupplier) {
|
||||
super(blockEntityType);
|
||||
this.capabilitySupplier = capabilitySupplier;
|
||||
}
|
||||
|
||||
protected AbstractTileEntityCapabilityDeviceProvider(final Supplier<Capability<TCapability>> capabilitySupplier) {
|
||||
protected AbstractBlockEntityCapabilityDeviceProvider(final Supplier<Capability<TCapability>> capabilitySupplier) {
|
||||
this.capabilitySupplier = capabilitySupplier;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected final LazyOptional<Device> getBlockDevice(final BlockDeviceQuery blockQuery, final BlockEntity tileEntity) {
|
||||
protected final LazyOptional<Device> getBlockDevice(final BlockDeviceQuery blockQuery, final BlockEntity blockEntity) {
|
||||
final Capability<TCapability> capability = capabilitySupplier.get();
|
||||
if (capability == null) throw new IllegalStateException();
|
||||
final LazyOptional<TCapability> optional = tileEntity.getCapability(capability, blockQuery.getQuerySide());
|
||||
final LazyOptional<TCapability> optional = blockEntity.getCapability(capability, blockQuery.getQuerySide());
|
||||
if (!optional.isPresent()) {
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
@@ -2,22 +2,22 @@ package li.cil.oc2.common.bus.device.provider.util;
|
||||
|
||||
import li.cil.oc2.api.bus.device.Device;
|
||||
import li.cil.oc2.api.bus.device.provider.BlockDeviceQuery;
|
||||
import li.cil.oc2.common.util.WorldUtils;
|
||||
import li.cil.oc2.common.util.LevelUtils;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
public abstract class AbstractTileEntityDeviceProvider<T extends BlockEntity> extends AbstractBlockDeviceProvider {
|
||||
private final BlockEntityType<T> tileEntityType;
|
||||
public abstract class AbstractBlockEntityDeviceProvider<T extends BlockEntity> extends AbstractBlockDeviceProvider {
|
||||
private final BlockEntityType<T> blockEntityType;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected AbstractTileEntityDeviceProvider(final BlockEntityType<T> tileEntityType) {
|
||||
this.tileEntityType = tileEntityType;
|
||||
protected AbstractBlockEntityDeviceProvider(final BlockEntityType<T> blockEntityType) {
|
||||
this.blockEntityType = blockEntityType;
|
||||
}
|
||||
|
||||
protected AbstractTileEntityDeviceProvider() {
|
||||
this.tileEntityType = null;
|
||||
protected AbstractBlockEntityDeviceProvider() {
|
||||
this.blockEntityType = null;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -25,19 +25,19 @@ public abstract class AbstractTileEntityDeviceProvider<T extends BlockEntity> ex
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final LazyOptional<Device> getDevice(final BlockDeviceQuery query) {
|
||||
final BlockEntity tileEntity = WorldUtils.getBlockEntityIfChunkExists(query.getLevel(), query.getQueryPosition());
|
||||
if (tileEntity == null) {
|
||||
final BlockEntity blockEntity = LevelUtils.getBlockEntityIfChunkExists(query.getLevel(), query.getQueryPosition());
|
||||
if (blockEntity == null) {
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
if (tileEntityType != null && tileEntity.getType() != tileEntityType) {
|
||||
if (blockEntityType != null && blockEntity.getType() != blockEntityType) {
|
||||
return LazyOptional.empty();
|
||||
}
|
||||
|
||||
return getBlockDevice(query, (T) tileEntity);
|
||||
return getBlockDevice(query, (T) blockEntity);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected abstract LazyOptional<Device> getBlockDevice(final BlockDeviceQuery query, final T tileEntity);
|
||||
protected abstract LazyOptional<Device> getBlockDevice(final BlockDeviceQuery query, final T blockEntity);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package li.cil.oc2.common.bus.device.rpc;
|
||||
|
||||
import li.cil.oc2.common.util.NBTTagIds;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -63,11 +64,12 @@ public final class RPCItemStackTagFilter {
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentSource.contains(path[path.length - 1])) {
|
||||
final Tag tag = currentSource.get(path[path.length - 1]);
|
||||
if (tag == null) {
|
||||
return null; // Cannot find tag at path.
|
||||
}
|
||||
|
||||
currentTarget.put(path[path.length - 1], currentSource.get(path[path.length - 1]));
|
||||
currentTarget.put(path[path.length - 1], tag);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class RPCMethodParameterTypeAdapters {
|
||||
final GsonBuilder builder = new GsonBuilder();
|
||||
|
||||
for (final RPCMethodParameterTypeAdapter value : TYPE_ADAPTERS) {
|
||||
builder.registerTypeAdapter(value.getType(), value.getTypeAdapter());
|
||||
builder.registerTypeAdapter(value.type(), value.typeAdapter());
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
||||
@@ -23,22 +23,22 @@ import java.util.*;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public final class Devices {
|
||||
public static BlockDeviceQuery makeQuery(final BlockEntity tileEntity, @Nullable final Direction side) {
|
||||
final Level world = requireNonNull(tileEntity.getLevel());
|
||||
final BlockPos pos = tileEntity.getBlockPos();
|
||||
return new BlockQuery(world, pos, side);
|
||||
public static BlockDeviceQuery makeQuery(final BlockEntity blockEntity, @Nullable final Direction side) {
|
||||
final Level level = requireNonNull(blockEntity.getLevel());
|
||||
final BlockPos pos = blockEntity.getBlockPos();
|
||||
return new BlockQuery(level, pos, side);
|
||||
}
|
||||
|
||||
public static BlockDeviceQuery makeQuery(final Level world, final BlockPos pos, @Nullable final Direction side) {
|
||||
return new BlockQuery(world, pos, side);
|
||||
public static BlockDeviceQuery makeQuery(final Level level, final BlockPos pos, @Nullable final Direction side) {
|
||||
return new BlockQuery(level, pos, side);
|
||||
}
|
||||
|
||||
public static ItemDeviceQuery makeQuery(final ItemStack stack) {
|
||||
return new ItemQuery(stack);
|
||||
}
|
||||
|
||||
public static ItemDeviceQuery makeQuery(final BlockEntity tileEntity, final ItemStack stack) {
|
||||
return new ItemQuery(tileEntity, stack);
|
||||
public static ItemDeviceQuery makeQuery(final BlockEntity blockEntity, final ItemStack stack) {
|
||||
return new ItemQuery(blockEntity, stack);
|
||||
}
|
||||
|
||||
public static ItemDeviceQuery makeQuery(final Entity entity, final ItemStack stack) {
|
||||
@@ -95,19 +95,19 @@ public final class Devices {
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private static class BlockQuery implements BlockDeviceQuery {
|
||||
private final Level world;
|
||||
private final Level level;
|
||||
private final BlockPos pos;
|
||||
@Nullable private final Direction side;
|
||||
|
||||
public BlockQuery(final Level world, final BlockPos pos, @Nullable final Direction side) {
|
||||
this.world = world;
|
||||
public BlockQuery(final Level level, final BlockPos pos, @Nullable final Direction side) {
|
||||
this.level = level;
|
||||
this.pos = pos;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Level getLevel() {
|
||||
return world;
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,31 +123,31 @@ public final class Devices {
|
||||
}
|
||||
|
||||
private static final class ItemQuery implements ItemDeviceQuery {
|
||||
@Nullable private final BlockEntity tileEntity;
|
||||
@Nullable private final BlockEntity blockEntity;
|
||||
@Nullable private final Entity entity;
|
||||
private final ItemStack stack;
|
||||
|
||||
public ItemQuery(final ItemStack stack) {
|
||||
tileEntity = null;
|
||||
blockEntity = null;
|
||||
entity = null;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public ItemQuery(final BlockEntity tileEntity, final ItemStack stack) {
|
||||
this.tileEntity = tileEntity;
|
||||
public ItemQuery(final BlockEntity blockEntity, final ItemStack stack) {
|
||||
this.blockEntity = blockEntity;
|
||||
entity = null;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public ItemQuery(final Entity entity, final ItemStack stack) {
|
||||
tileEntity = null;
|
||||
blockEntity = null;
|
||||
this.entity = entity;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<BlockEntity> getContainerTileEntity() {
|
||||
return Optional.ofNullable(tileEntity);
|
||||
public Optional<BlockEntity> getContainerBlockEntity() {
|
||||
return Optional.ofNullable(blockEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,19 +16,13 @@ import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public final class Capabilities {
|
||||
public static Capability<IEnergyStorage> ENERGY_STORAGE = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
public static Capability<IFluidHandler> FLUID_HANDLER = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
public static Capability<IItemHandler> ITEM_HANDLER = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
public static Capability<DeviceBusElement> DEVICE_BUS_ELEMENT = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
public static Capability<RedstoneEmitter> REDSTONE_EMITTER = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
public static Capability<NetworkInterface> NETWORK_INTERFACE = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
public static Capability<TerminalUserProvider> TERMINAL_USER_PROVIDER = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
public static Capability<Robot> ROBOT = CapabilityManager.get(new CapabilityToken<>() { });
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -7,7 +7,7 @@ import li.cil.oc2.common.network.message.ComputerPowerMessage;
|
||||
import li.cil.oc2.common.network.message.ComputerTerminalInputMessage;
|
||||
import li.cil.oc2.common.network.message.OpenComputerInventoryMessage;
|
||||
import li.cil.oc2.common.network.message.OpenComputerTerminalMessage;
|
||||
import li.cil.oc2.common.tileentity.ComputerTileEntity;
|
||||
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import li.cil.oc2.common.vm.VirtualMachine;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -19,11 +19,11 @@ import net.minecraftforge.energy.IEnergyStorage;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public abstract class AbstractComputerContainer extends AbstractMachineTerminalContainer {
|
||||
private final ComputerTileEntity computer;
|
||||
private final ComputerBlockEntity computer;
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
protected AbstractComputerContainer(final MenuType<?> type, final int id, final Player player, final ComputerTileEntity computer, final ContainerData energyInfo) {
|
||||
protected AbstractComputerContainer(final MenuType<?> type, final int id, final Player player, final ComputerBlockEntity computer, final ContainerData energyInfo) {
|
||||
super(type, id, energyInfo);
|
||||
this.computer = computer;
|
||||
|
||||
|
||||
@@ -73,16 +73,12 @@ public abstract class AbstractRobotContainer extends AbstractMachineTerminalCont
|
||||
return new ContainerData() {
|
||||
@Override
|
||||
public int get(final int index) {
|
||||
switch (index) {
|
||||
case AbstractMachineContainer.ENERGY_STORED_INDEX:
|
||||
return energy.getEnergyStored();
|
||||
case AbstractMachineContainer.ENERGY_CAPACITY_INDEX:
|
||||
return energy.getMaxEnergyStored();
|
||||
case AbstractMachineContainer.ENERGY_CONSUMPTION_INDEX:
|
||||
return busController.getEnergyConsumption();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return switch (index) {
|
||||
case AbstractMachineContainer.ENERGY_STORED_INDEX -> energy.getEnergyStored();
|
||||
case AbstractMachineContainer.ENERGY_CAPACITY_INDEX -> energy.getMaxEnergyStored();
|
||||
case AbstractMachineContainer.ENERGY_CONSUMPTION_INDEX -> busController.getEnergyConsumption();
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package li.cil.oc2.common.container;
|
||||
|
||||
import li.cil.oc2.api.bus.device.DeviceTypes;
|
||||
import li.cil.oc2.common.bus.CommonDeviceBusController;
|
||||
import li.cil.oc2.common.tileentity.ComputerTileEntity;
|
||||
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
|
||||
import li.cil.oc2.common.vm.VMItemStackHandlers;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
@@ -19,7 +19,7 @@ import net.minecraftforge.energy.IEnergyStorage;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public final class ComputerInventoryContainer extends AbstractComputerContainer {
|
||||
public static void createServer(final ComputerTileEntity computer, final IEnergyStorage energy, final CommonDeviceBusController busController, final ServerPlayer player) {
|
||||
public static void createServer(final ComputerBlockEntity computer, final IEnergyStorage energy, final CommonDeviceBusController busController, final ServerPlayer player) {
|
||||
NetworkHooks.openGui(player, new MenuProvider() {
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
@@ -35,16 +35,16 @@ public final class ComputerInventoryContainer extends AbstractComputerContainer
|
||||
|
||||
public static ComputerInventoryContainer createClient(final int id, final Inventory playerInventory, final FriendlyByteBuf data) {
|
||||
final BlockPos pos = data.readBlockPos();
|
||||
final BlockEntity tileEntity = playerInventory.player.level.getBlockEntity(pos);
|
||||
if (!(tileEntity instanceof ComputerTileEntity)) {
|
||||
final BlockEntity blockEntity = playerInventory.player.level.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof ComputerBlockEntity computer)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return new ComputerInventoryContainer(id, (ComputerTileEntity) tileEntity, playerInventory.player, createEnergyInfo());
|
||||
return new ComputerInventoryContainer(id, computer, playerInventory.player, createEnergyInfo());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private ComputerInventoryContainer(final int id, final ComputerTileEntity computer, final Player player, final ContainerData energyInfo) {
|
||||
private ComputerInventoryContainer(final int id, final ComputerBlockEntity computer, final Player player, final ContainerData energyInfo) {
|
||||
super(Containers.COMPUTER.get(), id, player, computer, energyInfo);
|
||||
|
||||
final VMItemStackHandlers handlers = computer.getItemStackHandlers();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package li.cil.oc2.common.container;
|
||||
|
||||
import li.cil.oc2.common.bus.CommonDeviceBusController;
|
||||
import li.cil.oc2.common.tileentity.ComputerTileEntity;
|
||||
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -17,7 +17,7 @@ import net.minecraftforge.energy.IEnergyStorage;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public final class ComputerTerminalContainer extends AbstractComputerContainer {
|
||||
public static void createServer(final ComputerTileEntity computer, final IEnergyStorage energy, final CommonDeviceBusController busController, final ServerPlayer player) {
|
||||
public static void createServer(final ComputerBlockEntity computer, final IEnergyStorage energy, final CommonDeviceBusController busController, final ServerPlayer player) {
|
||||
NetworkHooks.openGui(player, new MenuProvider() {
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
@@ -33,16 +33,16 @@ public final class ComputerTerminalContainer extends AbstractComputerContainer {
|
||||
|
||||
public static ComputerTerminalContainer createClient(final int id, final Inventory playerInventory, final FriendlyByteBuf data) {
|
||||
final BlockPos pos = data.readBlockPos();
|
||||
final BlockEntity tileEntity = playerInventory.player.level.getBlockEntity(pos);
|
||||
if (!(tileEntity instanceof ComputerTileEntity)) {
|
||||
final BlockEntity blockEntity = playerInventory.player.level.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof ComputerBlockEntity computer)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return new ComputerTerminalContainer(id, playerInventory.player, (ComputerTileEntity) tileEntity, createEnergyInfo());
|
||||
return new ComputerTerminalContainer(id, playerInventory.player, computer, createEnergyInfo());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private ComputerTerminalContainer(final int id, final Player player, final ComputerTileEntity computer, final ContainerData energyInfo) {
|
||||
private ComputerTerminalContainer(final int id, final Player player, final ComputerBlockEntity computer, final ContainerData energyInfo) {
|
||||
super(Containers.COMPUTER_TERMINAL.get(), id, player, computer, energyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user