mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-07 08:52:59 +00:00
remap with yarrnforge
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import dan200.computercraft.shared.util.NamedBlockEntityType;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class BlockGeneric extends Block implements BlockEntityProvider {
|
||||
private final BlockEntityType<? extends TileGeneric> type;
|
||||
|
||||
public BlockGeneric(Settings settings, NamedBlockEntityType<? extends TileGeneric> type) {
|
||||
super(settings);
|
||||
this.type = type;
|
||||
type.setBlock(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void neighborUpdate(BlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos neighbourPos, boolean flag) {
|
||||
super.neighborUpdate(state, world, pos, neighbourBlock, neighbourPos, flag);
|
||||
BlockEntity tile = world.getBlockEntity(pos);
|
||||
if (tile instanceof TileGeneric) {
|
||||
((TileGeneric) tile).onNeighbourChange(neighbourPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void onStateReplaced(@Nonnull BlockState block, @Nonnull World world, @Nonnull BlockPos pos, BlockState replace, boolean bool) {
|
||||
if (block.getBlock() == replace.getBlock()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockEntity tile = world.getBlockEntity(pos);
|
||||
super.onStateReplaced(block, world, pos, replace, bool);
|
||||
world.removeBlockEntity(pos);
|
||||
if (tile instanceof TileGeneric) {
|
||||
((TileGeneric) tile).destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public final boolean onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
BlockEntity tile = world.getBlockEntity(pos);
|
||||
return tile instanceof TileGeneric && ((TileGeneric) tile).onActivate(player, hand, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void scheduledTick(BlockState state, World world, BlockPos pos, Random rand) {
|
||||
BlockEntity te = world.getBlockEntity(pos);
|
||||
if (te instanceof TileGeneric) {
|
||||
((TileGeneric) te).blockTick();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockView blockView) {
|
||||
return this.type.instantiate();
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ClientTerminal implements ITerminal {
|
||||
private boolean m_colour;
|
||||
private Terminal m_terminal;
|
||||
private boolean m_terminalChanged;
|
||||
|
||||
public ClientTerminal(boolean colour) {
|
||||
this.m_colour = colour;
|
||||
this.m_terminal = null;
|
||||
this.m_terminalChanged = false;
|
||||
}
|
||||
|
||||
public boolean pollTerminalChanged() {
|
||||
boolean changed = this.m_terminalChanged;
|
||||
this.m_terminalChanged = false;
|
||||
|
||||
Terminal terminal = this.m_terminal;
|
||||
if (terminal != null) {
|
||||
terminal.clearChanged();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
// ITerminal implementation
|
||||
|
||||
@Override
|
||||
public Terminal getTerminal() {
|
||||
return this.m_terminal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColour() {
|
||||
return this.m_colour;
|
||||
}
|
||||
|
||||
public void readDescription(CompoundTag nbt) {
|
||||
this.m_colour = nbt.getBoolean("colour");
|
||||
if (nbt.contains("terminal")) {
|
||||
CompoundTag terminal = nbt.getCompound("terminal");
|
||||
this.resizeTerminal(terminal.getInt("term_width"), terminal.getInt("term_height"));
|
||||
this.m_terminal.readFromNBT(terminal);
|
||||
} else {
|
||||
this.deleteTerminal();
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeTerminal(int width, int height) {
|
||||
if (this.m_terminal == null) {
|
||||
this.m_terminal = new Terminal(width, height, () -> this.m_terminalChanged = true);
|
||||
this.m_terminalChanged = true;
|
||||
} else {
|
||||
this.m_terminal.resize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteTerminal() {
|
||||
if (this.m_terminal != null) {
|
||||
this.m_terminal = null;
|
||||
this.m_terminalChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.ColourTracker;
|
||||
import dan200.computercraft.shared.util.ColourUtils;
|
||||
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.SpecialCraftingRecipe;
|
||||
import net.minecraft.recipe.SpecialRecipeSerializer;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ColourableRecipe extends SpecialCraftingRecipe {
|
||||
public static final RecipeSerializer<?> SERIALIZER = new SpecialRecipeSerializer<>(ColourableRecipe::new);
|
||||
|
||||
public ColourableRecipe(Identifier id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nonnull CraftingInventory inv, @Nonnull World world) {
|
||||
boolean hasColourable = false;
|
||||
boolean hasDye = false;
|
||||
for (int i = 0; i < inv.size(); i++) {
|
||||
ItemStack stack = inv.getStack(i);
|
||||
if (stack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stack.getItem() instanceof IColouredItem) {
|
||||
if (hasColourable) {
|
||||
return false;
|
||||
}
|
||||
hasColourable = true;
|
||||
} else if (ColourUtils.getStackColour(stack) != null) {
|
||||
hasDye = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return hasColourable && hasDye;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack craft(@Nonnull CraftingInventory inv) {
|
||||
ItemStack colourable = ItemStack.EMPTY;
|
||||
|
||||
ColourTracker tracker = new ColourTracker();
|
||||
|
||||
for (int i = 0; i < inv.size(); i++) {
|
||||
ItemStack stack = inv.getStack(i);
|
||||
|
||||
if (stack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stack.getItem() instanceof IColouredItem) {
|
||||
colourable = stack;
|
||||
} else {
|
||||
DyeColor dye = ColourUtils.getStackColour(stack);
|
||||
if (dye == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Colour colour = Colour.fromInt(15 - dye.getId());
|
||||
tracker.addColour(colour.getR(), colour.getG(), colour.getB());
|
||||
}
|
||||
}
|
||||
|
||||
if (colourable.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return ((IColouredItem) colourable.getItem()).withColour(colourable, tracker.getColour());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fits(int x, int y) {
|
||||
return x >= 2 && y >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import dan200.computercraft.shared.util.InventoryUtil;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
public class ContainerHeldItem extends ScreenHandler {
|
||||
private final ItemStack m_stack;
|
||||
private final Hand m_hand;
|
||||
|
||||
public ContainerHeldItem(int id, PlayerEntity player, Hand hand) {
|
||||
super(null, id);
|
||||
this.m_hand = hand;
|
||||
this.m_stack = InventoryUtil.copyItem(player.getStackInHand(hand));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ItemStack getStack() {
|
||||
return this.m_stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(@Nonnull PlayerEntity player) {
|
||||
if (!player.isAlive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getStackInHand(this.m_hand);
|
||||
return stack == this.m_stack || !stack.isEmpty() && !this.m_stack.isEmpty() && stack.getItem() == this.m_stack.getItem();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class DefaultBundledRedstoneProvider implements IBundledRedstoneProvider {
|
||||
@Override
|
||||
public int getBundledRedstoneOutput(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side) {
|
||||
return getDefaultBundledRedstoneOutput(world, pos, side);
|
||||
}
|
||||
|
||||
public static int getDefaultBundledRedstoneOutput(World world, BlockPos pos, Direction side) {
|
||||
Block block = world.getBlockState(pos)
|
||||
.getBlock();
|
||||
if (block instanceof IBundledRedstoneBlock) {
|
||||
IBundledRedstoneBlock generic = (IBundledRedstoneBlock) block;
|
||||
if (generic.getBundledRedstoneConnectivity(world, pos, side)) {
|
||||
return generic.getBundledRedstoneOutput(world, pos, side);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IBundledRedstoneBlock {
|
||||
boolean getBundledRedstoneConnectivity(World world, BlockPos pos, Direction side);
|
||||
|
||||
int getBundledRedstoneOutput(World world, BlockPos pos, Direction side);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public interface IColouredItem {
|
||||
String NBT_COLOUR = "Color";
|
||||
|
||||
default int getColour(ItemStack stack) {
|
||||
return getColourBasic(stack);
|
||||
}
|
||||
|
||||
static int getColourBasic(ItemStack stack) {
|
||||
CompoundTag tag = stack.getTag();
|
||||
return tag != null && tag.contains(NBT_COLOUR) ? tag.getInt(NBT_COLOUR) : -1;
|
||||
}
|
||||
|
||||
default ItemStack withColour(ItemStack stack, int colour) {
|
||||
ItemStack copy = stack.copy();
|
||||
setColourBasic(copy, colour);
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void setColourBasic(ItemStack stack, int colour) {
|
||||
if (colour == -1) {
|
||||
CompoundTag tag = stack.getTag();
|
||||
if (tag != null) {
|
||||
tag.remove(NBT_COLOUR);
|
||||
}
|
||||
} else {
|
||||
stack.getOrCreateTag()
|
||||
.putInt(NBT_COLOUR, colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
|
||||
public interface ITerminal {
|
||||
Terminal getTerminal();
|
||||
|
||||
boolean isColour();
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ServerTerminal implements ITerminal {
|
||||
private final boolean m_colour;
|
||||
private final AtomicBoolean m_terminalChanged = new AtomicBoolean(false);
|
||||
private Terminal m_terminal;
|
||||
private boolean m_terminalChangedLastFrame = false;
|
||||
|
||||
public ServerTerminal(boolean colour) {
|
||||
this.m_colour = colour;
|
||||
this.m_terminal = null;
|
||||
}
|
||||
|
||||
public ServerTerminal(boolean colour, int terminalWidth, int terminalHeight) {
|
||||
this.m_colour = colour;
|
||||
this.m_terminal = new Terminal(terminalWidth, terminalHeight, this::markTerminalChanged);
|
||||
}
|
||||
|
||||
protected void markTerminalChanged() {
|
||||
this.m_terminalChanged.set(true);
|
||||
}
|
||||
|
||||
protected void resize(int width, int height) {
|
||||
if (this.m_terminal == null) {
|
||||
this.m_terminal = new Terminal(width, height, this::markTerminalChanged);
|
||||
this.markTerminalChanged();
|
||||
} else {
|
||||
this.m_terminal.resize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if (this.m_terminal != null) {
|
||||
this.m_terminal = null;
|
||||
this.markTerminalChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
Terminal terminal = this.m_terminal;
|
||||
if (terminal != null) {
|
||||
terminal.clearChanged();
|
||||
}
|
||||
|
||||
this.m_terminalChangedLastFrame = this.m_terminalChanged.getAndSet(false);
|
||||
}
|
||||
|
||||
public boolean hasTerminalChanged() {
|
||||
return this.m_terminalChangedLastFrame;
|
||||
}
|
||||
|
||||
// ITerminal implementation
|
||||
|
||||
@Override
|
||||
public Terminal getTerminal() {
|
||||
return this.m_terminal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isColour() {
|
||||
return this.m_colour;
|
||||
}
|
||||
|
||||
// Networking stuff
|
||||
|
||||
public void writeDescription(CompoundTag nbt) {
|
||||
nbt.putBoolean("colour", this.m_colour);
|
||||
if (this.m_terminal != null) {
|
||||
CompoundTag terminal = new CompoundTag();
|
||||
terminal.putInt("term_width", this.m_terminal.getWidth());
|
||||
terminal.putInt("term_height", this.m_terminal.getHeight());
|
||||
this.m_terminal.writeToNBT(terminal);
|
||||
nbt.put("terminal", terminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable;
|
||||
|
||||
public abstract class TileGeneric extends BlockEntity implements BlockEntityClientSerializable {
|
||||
public TileGeneric(BlockEntityType<? extends TileGeneric> type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public final void updateBlock() {
|
||||
this.markDirty();
|
||||
BlockPos pos = this.getPos();
|
||||
BlockState state = this.getCachedState();
|
||||
this.getWorld().updateListeners(pos, state, state, 3);
|
||||
}
|
||||
|
||||
public boolean onActivate(PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onNeighbourChange(@Nonnull BlockPos neighbour) {
|
||||
}
|
||||
|
||||
public void onNeighbourTileEntityChange(@Nonnull BlockPos neighbour) {
|
||||
}
|
||||
|
||||
protected void blockTick() {
|
||||
}
|
||||
|
||||
public boolean isUsable(PlayerEntity player, boolean ignoreRange) {
|
||||
if (player == null || !player.isAlive() || this.getWorld().getBlockEntity(this.getPos()) != this) {
|
||||
return false;
|
||||
}
|
||||
if (ignoreRange) {
|
||||
return true;
|
||||
}
|
||||
|
||||
double range = this.getInteractRange(player);
|
||||
BlockPos pos = this.getPos();
|
||||
return player.getEntityWorld() == this.getWorld() && player.squaredDistanceTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5) <= range * range;
|
||||
}
|
||||
|
||||
protected double getInteractRange(PlayerEntity player) {
|
||||
return 8.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void fromClientTag(CompoundTag tag) {
|
||||
this.readDescription(tag);
|
||||
}
|
||||
|
||||
protected void readDescription(@Nonnull CompoundTag nbt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CompoundTag toClientTag(CompoundTag tag) {
|
||||
this.writeDescription(tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
protected void writeDescription(@Nonnull CompoundTag nbt) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user