Use modern java features where we can, optimise imports.

This commit is contained in:
modmuss50 2021-05-29 20:32:05 +01:00
parent 52e4767247
commit 31e7b357dc
135 changed files with 342 additions and 794 deletions

View file

@ -33,9 +33,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import reborncore.common.util.ItemUtils;
import org.jetbrains.annotations.Nullable;
import reborncore.common.util.ItemUtils;
public class InventoryUtils {
@ -67,8 +66,7 @@ public class InventoryUtils {
public static ItemStack insertItem(ItemStack input, Inventory inventory, Direction direction) {
ItemStack stack = input.copy();
if (inventory instanceof SidedInventory) {
SidedInventory sidedInventory = (SidedInventory) inventory;
if (inventory instanceof SidedInventory sidedInventory) {
for (int slot : sidedInventory.getAvailableSlots(direction)) {
if (sidedInventory.canInsert(slot, stack, direction)) {
stack = insertIntoInv(sidedInventory, slot, stack);

View file

@ -35,9 +35,9 @@ import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Vec3f;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3f;
import reborncore.common.RebornCoreConfig;
import reborncore.common.util.CalenderUtils;

View file

@ -32,7 +32,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gl.SimpleFramebuffer;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.ItemRenderer;
@ -46,7 +45,6 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.registry.Registry;
import org.apache.commons.io.FileUtils;
import org.lwjgl.opengl.GL11;
import java.io.File;

View file

@ -24,13 +24,10 @@
package reborncore.client;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.render.*;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.SpriteAtlasTexture;

View file

@ -27,9 +27,7 @@ package reborncore.client;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.resource.language.I18n;

View file

@ -46,6 +46,7 @@ import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Util;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import reborncore.api.blockentity.IUpgradeable;
import reborncore.client.gui.builder.slot.FluidConfigGui;
@ -56,8 +57,6 @@ import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.slot.PlayerInventorySlot;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import org.jetbrains.annotations.Nullable;
import reborncore.mixin.client.AccessorScreen;
import java.util.ArrayList;
@ -212,8 +211,7 @@ public class GuiBase<T extends ScreenHandler> extends HandledScreen<T> {
if (drawPlayerSlots) {
builder.drawPlayerSlots(matrixStack, this, x + backgroundWidth / 2, y + 93, true);
}
if (tryAddUpgrades() && be instanceof IUpgradeable) {
IUpgradeable upgradeable = (IUpgradeable) be;
if (tryAddUpgrades() && be instanceof IUpgradeable upgradeable) {
if (upgradeable.canBeUpgraded()) {
builder.drawUpgrades(matrixStack, this, x - 24, y + 6);
upgrades = true;

View file

@ -26,7 +26,6 @@ package reborncore.client.gui.builder;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.Packet;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import reborncore.client.RenderUtil;

View file

@ -27,13 +27,13 @@ package reborncore.client.gui.builder.slot;
import com.google.common.collect.Lists;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import org.jetbrains.annotations.Nullable;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.slot.elements.ConfigFluidElement;
import reborncore.client.gui.builder.slot.elements.ElementBase;
import reborncore.client.gui.builder.slot.elements.SlotType;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@ -131,15 +131,13 @@ public class FluidConfigGui {
@Nullable
private static MachineBaseBlockEntity getMachine() {
if (!(MinecraftClient.getInstance().currentScreen instanceof GuiBase)) {
if (!(MinecraftClient.getInstance().currentScreen instanceof GuiBase<?> base)) {
return null;
}
GuiBase<?> base = (GuiBase<?>) MinecraftClient.getInstance().currentScreen;
if (!(base.be instanceof MachineBaseBlockEntity)) {
return null;
if (base.be instanceof MachineBaseBlockEntity machineBase) {
return machineBase;
}
MachineBaseBlockEntity machineBase = (MachineBaseBlockEntity) base.be;
return machineBase;
return null;
}
}

View file

@ -31,6 +31,7 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Util;
import org.jetbrains.annotations.Nullable;
import reborncore.client.gui.GuiUtil;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.slot.elements.ConfigSlotElement;
@ -43,7 +44,6 @@ import reborncore.common.network.ServerBoundPackets;
import reborncore.common.util.Color;
import reborncore.mixin.common.AccessorSlot;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -129,15 +129,13 @@ public class SlotConfigGui {
@Nullable
private static MachineBaseBlockEntity getMachine() {
if (!(MinecraftClient.getInstance().currentScreen instanceof GuiBase)) {
if (!(MinecraftClient.getInstance().currentScreen instanceof GuiBase<?> base)) {
return null;
}
GuiBase<?> base = (GuiBase<?>) MinecraftClient.getInstance().currentScreen;
if (!(base.be instanceof MachineBaseBlockEntity)) {
return null;
if (base.be instanceof MachineBaseBlockEntity machineBase) {
return machineBase;
}
MachineBaseBlockEntity machineBase = (MachineBaseBlockEntity) base.be;
return machineBase;
return null;
}
public static boolean mouseClicked(GuiBase<?> guiBase, double mouseX, double mouseY, int mouseButton) {

View file

@ -29,13 +29,13 @@ public class ButtonElement extends ElementBase {
private final Sprite.Button buttonSprite;
public ButtonElement(int x, int y, Sprite.Button buttonSprite) {
super(x, y, buttonSprite.getNormal());
super(x, y, buttonSprite.normal());
this.buttonSprite = buttonSprite;
this.addUpdateAction((gui, element) -> {
if (isHovering) {
element.container.setSprite(0, buttonSprite.getHovered());
element.container.setSprite(0, buttonSprite.hovered());
} else {
element.container.setSprite(0, buttonSprite.getNormal());
element.container.setSprite(0, buttonSprite.normal());
}
});
}

View file

@ -41,7 +41,7 @@ public class CheckBoxElement extends ElementBase {
private final Sprite.CheckBox checkBoxSprite;
public CheckBoxElement(Text label, int labelColor, int x, int y, String type, int slotID, Sprite.CheckBox checkBoxSprite, MachineBaseBlockEntity machineBase, Predicate<CheckBoxElement> ticked) {
super(x, y, checkBoxSprite.getNormal());
super(x, y, checkBoxSprite.normal());
this.checkBoxSprite = checkBoxSprite;
this.type = type;
this.slotID = slotID;
@ -50,15 +50,15 @@ public class CheckBoxElement extends ElementBase {
this.labelColor = labelColor;
this.ticked = ticked;
if (ticked.test(this)) {
container.setSprite(0, checkBoxSprite.getTicked());
container.setSprite(0, checkBoxSprite.ticked());
} else {
container.setSprite(0, checkBoxSprite.getNormal());
container.setSprite(0, checkBoxSprite.normal());
}
this.addPressAction((element, gui, provider, mouseX, mouseY) -> {
if (ticked.test(this)) {
element.container.setSprite(0, checkBoxSprite.getTicked());
element.container.setSprite(0, checkBoxSprite.ticked());
} else {
element.container.setSprite(0, checkBoxSprite.getNormal());
element.container.setSprite(0, checkBoxSprite.normal());
}
return true;
});
@ -67,12 +67,12 @@ public class CheckBoxElement extends ElementBase {
@Override
public void draw(MatrixStack matrixStack, GuiBase<?> gui) {
// super.draw(gui);
ISprite sprite = checkBoxSprite.getNormal();
ISprite sprite = checkBoxSprite.normal();
if (ticked.test(this)) {
sprite = checkBoxSprite.getTicked();
sprite = checkBoxSprite.ticked();
}
drawSprite(matrixStack, gui, sprite, x, y);
drawText(matrixStack, gui, label, x + checkBoxSprite.getNormal().width + 5, ((y + getHeight(gui.getMachine()) / 2) - (gui.getTextRenderer().fontHeight / 2)), labelColor);
drawText(matrixStack, gui, label, x + checkBoxSprite.normal().width + 5, ((y + getHeight(gui.getMachine()) / 2) - (gui.getTextRenderer().fontHeight / 2)), labelColor);
}
}

View file

@ -87,8 +87,7 @@ public class ConfigSlotElement extends ElementBase {
return true;
}));
if (gui.getMachine() instanceof SlotConfiguration.SlotFilter) {
SlotConfiguration.SlotFilter slotFilter = (SlotConfiguration.SlotFilter) gui.getMachine();
if (gui.getMachine() instanceof SlotConfiguration.SlotFilter slotFilter) {
if (Arrays.stream(slotFilter.getInputSlots()).anyMatch(value -> value == slotId)) {
elements.add(new CheckBoxElement(new TranslatableText("reborncore.gui.slotconfig.filter_input"), 0xFFFFFFFF, x - 26, y + 72, "filter", slotId, Sprite.LIGHT_CHECK_BOX, gui.getMachine(),
checkBoxElement -> checkBoxElement.machineBase.getSlotConfiguration().getSlotDetails(checkBoxElement.slotID).filter()).addPressAction((element, gui13, provider, mouseX, mouseY) -> {

View file

@ -35,7 +35,6 @@ import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.Packet;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Quaternion;
@ -153,24 +152,12 @@ public class FluidConfigPopupElement extends ElementBase {
return;
}
FluidConfiguration.FluidConfig fluidConfig = fluidConfiguration.getSideDetail(side);
Color color;
switch (fluidConfig.getIoConfig()) {
case NONE:
color = new Color(0, 0, 0, 0);
break;
case INPUT:
color = new Color(0, 0, 255, 128);
break;
case OUTPUT:
color = new Color(255, 69, 0, 128);
break;
case ALL:
color = new Color(52, 255, 30, 128);
break;
default:
color = new Color(0, 0, 0, 0);
break;
}
Color color = switch (fluidConfig.getIoConfig()) {
case NONE -> new Color(0, 0, 0, 0);
case INPUT -> new Color(0, 0, 255, 128);
case OUTPUT -> new Color(255, 69, 0, 128);
case ALL -> new Color(52, 255, 30, 128);
};
RenderSystem.setShaderColor(1, 1, 1, 1);
GuiUtil.drawGradientRect(matrices, sx, sy, 18, 18, color.getColor(), color.getColor());
RenderSystem.setShaderColor(1, 1, 1, 1);

View file

@ -35,7 +35,6 @@ import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.Packet;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Quaternion;
@ -159,18 +158,11 @@ public class SlotConfigPopupElement extends ElementBase {
return;
}
SlotConfiguration.SlotConfig slotConfig = slotConfigHolder.getSideDetail(side);
Color color;
switch (slotConfig.getSlotIO().getIoConfig()) {
case INPUT:
color = new Color(0, 0, 255, 128);
break;
case OUTPUT:
color = new Color(255, 69, 0, 128);
break;
default:
color = new Color(0, 0, 0, 0);
break;
}
Color color = switch (slotConfig.getSlotIO().getIoConfig()) {
case INPUT -> new Color(0, 0, 255, 128);
case OUTPUT -> new Color(255, 69, 0, 128);
default -> new Color(0, 0, 0, 0);
};
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
GuiUtil.drawGradientRect(matrices, sx, sy, 18, 18, color.getColor(), color.getColor());
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

View file

@ -107,63 +107,16 @@ public class Sprite implements ISprite {
return this;
}
public static class Button {
private final Sprite normal;
private final Sprite hovered;
public Button(Sprite normal, Sprite hovered) {
this.normal = normal;
this.hovered = hovered;
}
public Sprite getNormal() {
return normal;
}
public Sprite getHovered() {
return hovered;
}
public record Button(Sprite normal,
Sprite hovered) {
}
public static class ToggleButton {
private final Sprite normal;
private final Sprite hovered;
private final Sprite pressed;
public ToggleButton(Sprite normal, Sprite hovered, Sprite pressed) {
this.normal = normal;
this.hovered = hovered;
this.pressed = pressed;
}
public Sprite getNormal() {
return normal;
}
public Sprite getHovered() {
return hovered;
}
public Sprite getPressed() {
return pressed;
}
public record ToggleButton(Sprite normal,
Sprite hovered,
Sprite pressed) {
}
public static class CheckBox {
private final Sprite normal;
private final Sprite ticked;
public CheckBox(Sprite normal, Sprite ticked) {
this.normal = normal;
this.ticked = ticked;
}
public Sprite getNormal() {
return normal;
}
public Sprite getTicked() {
return ticked;
}
public record CheckBox(Sprite normal,
Sprite ticked) {
}
}

View file

@ -414,7 +414,7 @@ public class GuiBuilder {
}
private class TipsListWidget extends EntryListWidget<TipsListWidget.TipsListEntry> {
private static class TipsListWidget extends EntryListWidget<TipsListWidget.TipsListEntry> {
public TipsListWidget(GuiBase<?> gui, int width, int height, int top, int bottom, int entryHeight, List<Text> tips) {
super(gui.getMinecraft(), width, height, top, bottom, entryHeight);

View file

@ -28,11 +28,12 @@ import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SlotFilteredVoid extends BaseSlot {
private final List<ItemStack> filter = new ArrayList<ItemStack>();
private final List<ItemStack> filter = new ArrayList<>();
public SlotFilteredVoid(Inventory itemHandler, int id, int x, int y) {
super(itemHandler, id, x, y);
@ -40,9 +41,7 @@ public class SlotFilteredVoid extends BaseSlot {
public SlotFilteredVoid(Inventory itemHandler, int id, int x, int y, ItemStack[] filterList) {
super(itemHandler, id, x, y);
for (ItemStack itemStack : filterList) {
this.filter.add(itemStack);
}
this.filter.addAll(Arrays.asList(filterList));
}
@Override

View file

@ -24,13 +24,10 @@
package reborncore.client.multiblock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blockentity.MultiblockWriter;

View file

@ -170,8 +170,7 @@ public class BlockEntityScreenHandlerBuilder {
}
public BlockEntityScreenHandlerBuilder syncEnergyValue() {
if (this.blockEntity instanceof PowerAcceptorBlockEntity) {
PowerAcceptorBlockEntity powerAcceptor = ((PowerAcceptorBlockEntity) this.blockEntity);
if (this.blockEntity instanceof PowerAcceptorBlockEntity powerAcceptor) {
return this.sync(powerAcceptor::getEnergy, powerAcceptor::setEnergy)
.sync(powerAcceptor::getExtraPowerStorage, powerAcceptor::setExtraPowerStorage)
@ -183,8 +182,7 @@ public class BlockEntityScreenHandlerBuilder {
}
public BlockEntityScreenHandlerBuilder syncCrafterValue() {
if (this.blockEntity instanceof IRecipeCrafterProvider) {
IRecipeCrafterProvider recipeCrafter = ((IRecipeCrafterProvider) this.blockEntity);
if (this.blockEntity instanceof IRecipeCrafterProvider recipeCrafter) {
return this
.sync(() -> recipeCrafter.getRecipeCrafter().currentTickTime, (time) -> recipeCrafter.getRecipeCrafter().currentTickTime = time)
.sync(() -> recipeCrafter.getRecipeCrafter().currentNeededTicks, (ticks) -> recipeCrafter.getRecipeCrafter().currentNeededTicks = ticks);

View file

@ -49,7 +49,9 @@ import reborncore.mixin.ifaces.ServerPlayerEntityScreenHandler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class BuiltScreenHandler extends ScreenHandler {
private static final Logger LOGGER = LogManager.getLogger();

View file

@ -30,7 +30,6 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.inventory.Inventory;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
public class SpriteSlot extends FilteredSlot {

View file

@ -39,10 +39,9 @@ public class UpgradeSlot extends BaseSlot {
@Override
public boolean canInsert(final ItemStack stack) {
if (!(stack.getItem() instanceof IUpgrade)) {
if (!(stack.getItem() instanceof IUpgrade upgrade)) {
return false;
}
IUpgrade upgrade = (IUpgrade) stack.getItem();
IUpgradeable upgradeable = null;
RebornInventory inv = (RebornInventory) inventory;
BlockEntity blockEntity = inv.getBlockEntity();

View file

@ -27,7 +27,6 @@ package reborncore.common;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlastFurnaceBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;

View file

@ -34,12 +34,12 @@ import com.mojang.brigadier.suggestion.SuggestionProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.command.CommandManager;
import net.minecraft.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerChunkManager;

View file

@ -28,11 +28,11 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.NotNull;
import reborncore.common.fluid.FluidUtil;
import reborncore.common.util.NBTSerializable;
import reborncore.common.util.Tank;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

View file

@ -27,8 +27,8 @@ package reborncore.common.blockentity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
@ -36,16 +36,15 @@ import net.minecraft.inventory.SidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.Formatting;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IListInfoProvider;
import reborncore.api.blockentity.IUpgrade;
import reborncore.api.blockentity.IUpgradeable;
@ -60,8 +59,6 @@ import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import reborncore.common.util.Tank;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@ -210,8 +207,7 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
}
public Optional<RebornInventory<?>> getOptionalInventory() {
if (this instanceof InventoryProvider) {
InventoryProvider inventory = (InventoryProvider) this;
if (this instanceof InventoryProvider inventory) {
if (inventory.getInventory() == null) {
return Optional.empty();
}
@ -221,8 +217,7 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
}
protected Optional<RecipeCrafter> getOptionalCrafter() {
if (this instanceof IRecipeCrafterProvider) {
IRecipeCrafterProvider crafterProvider = (IRecipeCrafterProvider) this;
if (this instanceof IRecipeCrafterProvider crafterProvider) {
if (crafterProvider.getRecipeCrafter() == null) {
return Optional.empty();
}

View file

@ -26,12 +26,14 @@ package reborncore.common.blockentity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FluidBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.MatrixStack;
@ -195,12 +197,7 @@ public interface MultiblockWriter {
/**
* A writer which prints the hologram to {@link System#out}
*/
class DebugWriter implements MultiblockWriter {
private final MultiblockWriter writer;
public DebugWriter(MultiblockWriter writer) {
this.writer = writer;
}
record DebugWriter(MultiblockWriter writer) implements MultiblockWriter {
@Override
public MultiblockWriter add(int x, int y, int z, BiPredicate<BlockView, BlockPos> predicate, BlockState state) {
@ -246,21 +243,9 @@ public interface MultiblockWriter {
* Renders a hologram
*/
@Environment(EnvType.CLIENT)
class HologramRenderer implements MultiblockWriter {
record HologramRenderer(BlockRenderView view, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, float scale) implements MultiblockWriter {
private static final BlockPos OUT_OF_WORLD_POS = new BlockPos(0, 260, 0); // Bad hack; disables lighting
private final BlockRenderView view;
private final MatrixStack matrix;
private final VertexConsumerProvider vertexConsumerProvider;
private final float scale;
public HologramRenderer(BlockRenderView view, MatrixStack matrix, VertexConsumerProvider vertexConsumerProvider, float scale) {
this.view = view;
this.matrix = matrix;
this.vertexConsumerProvider = vertexConsumerProvider;
this.scale = scale;
}
@Override
public MultiblockWriter add(int x, int y, int z, BiPredicate<BlockView, BlockPos> predicate, BlockState state) {
final BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
@ -278,7 +263,7 @@ public interface MultiblockWriter {
VertexConsumer consumer = vertexConsumerProvider.getBuffer(RenderLayers.getBlockLayer(state));
blockRenderManager.renderBlock(state, OUT_OF_WORLD_POS, view, matrix, consumer, false, new Random());
}
matrix.pop();
return this;
}

View file

@ -31,12 +31,12 @@ import net.minecraft.nbt.NbtCompound;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.client.screen.builder.Syncable;
import reborncore.common.util.BooleanFunction;
import reborncore.common.util.NBTSerializable;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

View file

@ -27,7 +27,6 @@ package reborncore.common.blockentity;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntLists;
import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SidedInventory;
import net.minecraft.item.ItemStack;
@ -35,14 +34,14 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.util.math.Direction;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.RebornCore;
import reborncore.api.items.InventoryUtils;
import reborncore.common.util.ItemUtils;
import reborncore.common.util.NBTSerializable;
import reborncore.common.util.RebornInventory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.stream.Collectors;

View file

@ -44,7 +44,6 @@ import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import reborncore.api.ToolManager;
@ -195,8 +194,7 @@ public abstract class BlockMachineBase extends BaseBlockEntityProvider implement
if (WrenchUtils.handleWrench(stack, worldIn, pos, playerIn, hitResult.getSide())) {
return ActionResult.SUCCESS;
}
} else if (stack.getItem() instanceof IUpgrade && blockEntity instanceof IUpgradeable) {
IUpgradeable upgradeableEntity = (IUpgradeable) blockEntity;
} else if (stack.getItem() instanceof IUpgrade && blockEntity instanceof IUpgradeable upgradeableEntity) {
if (upgradeableEntity.canBeUpgraded()) {
if (InventoryUtils.insertItemStacked(upgradeableEntity.getUpgradeInvetory(), stack,
true).getCount() > 0) {

View file

@ -35,12 +35,9 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.DimensionType;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import reborncore.common.network.ClientBoundPackets;

View file

@ -24,18 +24,17 @@
package reborncore.common.crafting;
import java.util.HashMap;
import java.util.function.Function;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.tag.ItemTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import org.apache.commons.lang3.Validate;
import net.fabricmc.loader.api.FabricLoader;
import java.util.HashMap;
import java.util.function.Function;
public final class ConditionManager {

View file

@ -30,15 +30,14 @@ import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.NotNull;
import reborncore.common.crafting.ingredient.RebornIngredient;
import reborncore.common.fluid.FluidValue;
import reborncore.common.fluid.container.FluidInstance;
import net.minecraft.util.collection.DefaultedList;
import reborncore.common.util.Tank;
import org.jetbrains.annotations.NotNull;
public abstract class RebornFluidRecipe extends RebornRecipe {
@NotNull

View file

@ -38,34 +38,27 @@ import reborncore.common.util.serialization.SerializationUtil;
import java.util.List;
import java.util.function.BiFunction;
public class RebornRecipeType<R extends RebornRecipe> implements RecipeType, RecipeSerializer {
private final BiFunction<RebornRecipeType<R>, Identifier, R> recipeFunction;
private final Identifier typeId;
public RebornRecipeType(BiFunction<RebornRecipeType<R>, Identifier, R> recipeFunction, Identifier typeId) {
this.recipeFunction = recipeFunction;
this.typeId = typeId;
}
public record RebornRecipeType<R extends RebornRecipe>(
BiFunction<RebornRecipeType<R>, Identifier, R> recipeFunction,
Identifier name) implements RecipeType, RecipeSerializer {
@Override
public R read(Identifier recipeId, JsonObject json) {
Identifier type = new Identifier(JsonHelper.getString(json, "type"));
if (!type.equals(typeId)) {
if (!type.equals(name)) {
throw new RuntimeException("RebornRecipe type not supported!");
}
R recipe = newRecipe(recipeId);
try{
if(!ConditionManager.shouldLoadRecipe(json)) {
try {
if (!ConditionManager.shouldLoadRecipe(json)) {
recipe.makeDummy();
return recipe;
}
recipe.deserialize(json);
} catch (Throwable t){
} catch (Throwable t) {
t.printStackTrace();
RebornCore.LOGGER.error("Failed to read recipe: " + recipeId);
}
@ -75,7 +68,7 @@ public class RebornRecipeType<R extends RebornRecipe> implements RecipeType, Rec
public JsonObject toJson(R recipe) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("type", typeId.toString());
jsonObject.addProperty("type", name.toString());
recipe.serialize(jsonObject);
@ -107,12 +100,7 @@ public class RebornRecipeType<R extends RebornRecipe> implements RecipeType, Rec
((R) recipe).serialize(buffer);
}
public Identifier getName() {
return typeId;
}
public List<R> getRecipes(World world) {
return RecipeUtils.getRecipes(world, this);
}
}

View file

@ -65,7 +65,7 @@ public class RecipeManager {
}
public static List<RebornRecipeType> getRecipeTypes(String namespace) {
return recipeTypes.values().stream().filter(rebornRecipeType -> rebornRecipeType.getName().getNamespace().equals(namespace)).collect(Collectors.toList());
return recipeTypes.values().stream().filter(rebornRecipeType -> rebornRecipeType.name().getNamespace().equals(namespace)).collect(Collectors.toList());
}
public static void validateRecipes(World world) {

View file

@ -29,8 +29,8 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.function.Function;

View file

@ -26,20 +26,15 @@ package reborncore.common.crafting.ingredient;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import net.minecraft.client.MinecraftClient;
import net.minecraft.data.server.ItemTagsProvider;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.tag.RequiredTagList;
import net.minecraft.tag.RequiredTagListRegistry;
import net.minecraft.tag.ServerTagManagerHolder;
import net.minecraft.tag.Tag;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import org.apache.commons.lang3.Validate;
import java.util.ArrayList;

View file

@ -32,10 +32,10 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import org.apache.commons.lang3.time.StopWatch;
import reborncore.RebornCore;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.RebornCore;
import java.util.ArrayList;
import java.util.List;

View file

@ -31,11 +31,10 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.registry.Registry;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.util.Tank;
import org.jetbrains.annotations.NotNull;
public class FluidUtil {

View file

@ -26,10 +26,9 @@ package reborncore.common.fluid.container;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack;
import reborncore.common.fluid.FluidValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.common.fluid.FluidValue;
/*

View file

@ -28,40 +28,24 @@ import net.minecraft.util.math.Direction;
public class Functions {
public static int getIntDirFromDirection(Direction dir) {
switch (dir) {
case DOWN:
return 0;
case EAST:
return 5;
case NORTH:
return 2;
case SOUTH:
return 3;
case UP:
return 1;
case WEST:
return 4;
default:
return 0;
}
return switch (dir) {
case DOWN -> 0;
case EAST -> 5;
case NORTH -> 2;
case SOUTH -> 3;
case UP -> 1;
case WEST -> 4;
};
}
public static Direction getDirectionFromInt(int dir) {
int metaDataToSet = 0;
switch (dir) {
case 0:
metaDataToSet = 2;
break;
case 1:
metaDataToSet = 4;
break;
case 2:
metaDataToSet = 3;
break;
case 3:
metaDataToSet = 5;
break;
}
int metaDataToSet = switch (dir) {
case 0 -> 2;
case 1 -> 4;
case 2 -> 3;
case 3 -> 5;
default -> 0;
};
return Direction.byId(metaDataToSet);
}
}

View file

@ -28,8 +28,8 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
public interface MultiBlockBreakingTool {

View file

@ -26,10 +26,10 @@ package reborncore.common.multiblock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.RebornCore;
@ -79,7 +79,7 @@ public abstract class MultiblockBlockEntityBase extends IMultiblockPart implemen
}
if (controllers == null) {
controllers = new HashSet<MultiblockControllerBase>();
controllers = new HashSet<>();
bestController = candidate;
} else if (!controllers.contains(candidate) && candidate.shouldConsume(bestController)) {
bestController = candidate;
@ -313,7 +313,7 @@ public abstract class MultiblockBlockEntityBase extends IMultiblockPart implemen
@Override
public IMultiblockPart[] getNeighboringParts() {
BlockEntity te;
List<IMultiblockPart> neighborParts = new ArrayList<IMultiblockPart>();
List<IMultiblockPart> neighborParts = new ArrayList<>();
BlockPos neighborPosition, partPosition = this.getWorldLocation();
for (Direction facing : Direction.values()) {
@ -326,7 +326,7 @@ public abstract class MultiblockBlockEntityBase extends IMultiblockPart implemen
}
}
return neighborParts.toArray(new IMultiblockPart[neighborParts.size()]);
return neighborParts.toArray(new IMultiblockPart[0]);
}
@Override

View file

@ -98,7 +98,7 @@ public abstract class MultiblockControllerBase {
protected MultiblockControllerBase(World world) {
// Multiblock stuff
worldObj = world;
connectedParts = new HashSet<IMultiblockPart>();
connectedParts = new HashSet<>();
referenceCoord = null;
assemblyState = AssemblyState.Disassembled;
@ -178,7 +178,7 @@ public abstract class MultiblockControllerBase {
part.forfeitMultiblockSaveDelegate();
}
Boolean updateRequired = false;
boolean updateRequired = false;
BlockPos partPos = part.getPos();
if (minimumCoord != null) {
@ -467,7 +467,7 @@ public abstract class MultiblockControllerBase {
"The controller with the lowest minimum-coord value must consume the one with the higher coords");
}
Set<IMultiblockPart> partsToAcquire = new HashSet<IMultiblockPart>(other.connectedParts);
Set<IMultiblockPart> partsToAcquire = new HashSet<>(other.connectedParts);
// releases all blocks and references gently so they can be incorporated into another multiblock
other._onAssimilated(this);
@ -688,8 +688,8 @@ public abstract class MultiblockControllerBase {
* from the list of connected parts.
*/
public void recalculateMinMaxCoords() {
Integer minX, minY, minZ;
Integer maxX, maxY, maxZ;
int minX, minY, minZ;
int maxX, maxY, maxZ;
minX = minY = minZ = Integer.MAX_VALUE;
maxX = maxY = maxZ = Integer.MIN_VALUE;
@ -845,7 +845,7 @@ public abstract class MultiblockControllerBase {
* exist in the world, they are removed.
*/
private void auditParts() {
HashSet<IMultiblockPart> deadParts = new HashSet<IMultiblockPart>();
HashSet<IMultiblockPart> deadParts = new HashSet<>();
for (IMultiblockPart part : connectedParts) {
if (part.isInvalid() || worldObj.getBlockEntity(part.getPos()) != part) {
onDetachBlock(part);
@ -878,7 +878,7 @@ public abstract class MultiblockControllerBase {
referenceCoord = null;
// Reset visitations and find the minimum coordinate
Set<IMultiblockPart> deadParts = new HashSet<IMultiblockPart>();
Set<IMultiblockPart> deadParts = new HashSet<>();
BlockPos pos;
IMultiblockPart referencePart = null;
@ -926,7 +926,7 @@ public abstract class MultiblockControllerBase {
// Now visit all connected parts, breadth-first, starting from reference
// coord's part
IMultiblockPart part;
LinkedList<IMultiblockPart> partsToCheck = new LinkedList<IMultiblockPart>();
LinkedList<IMultiblockPart> partsToCheck = new LinkedList<>();
IMultiblockPart[] nearbyParts = null;
int visitedParts = 0;
@ -953,7 +953,7 @@ public abstract class MultiblockControllerBase {
}
// Finally, remove all parts that remain disconnected.
Set<IMultiblockPart> removedParts = new HashSet<IMultiblockPart>();
Set<IMultiblockPart> removedParts = new HashSet<>();
for (IMultiblockPart orphanCandidate : connectedParts) {
if (!orphanCandidate.isVisited()) {
deadParts.add(orphanCandidate);
@ -988,7 +988,7 @@ public abstract class MultiblockControllerBase {
*/
public Set<IMultiblockPart> detachAllBlocks() {
if (worldObj == null) {
return new HashSet<IMultiblockPart>();
return new HashSet<>();
}
for (IMultiblockPart part : connectedParts) {
@ -998,7 +998,7 @@ public abstract class MultiblockControllerBase {
}
Set<IMultiblockPart> detachedParts = connectedParts;
connectedParts = new HashSet<IMultiblockPart>();
connectedParts = new HashSet<>();
return detachedParts;
}

View file

@ -73,14 +73,14 @@ public class MultiblockWorldRegistry {
public MultiblockWorldRegistry(final World world) {
worldObj = world;
controllers = new HashSet<MultiblockControllerBase>();
deadControllers = new HashSet<MultiblockControllerBase>();
dirtyControllers = new HashSet<MultiblockControllerBase>();
controllers = new HashSet<>();
deadControllers = new HashSet<>();
dirtyControllers = new HashSet<>();
detachedParts = new HashSet<IMultiblockPart>();
orphanedParts = new HashSet<IMultiblockPart>();
detachedParts = new HashSet<>();
orphanedParts = new HashSet<>();
partsAwaitingChunkLoad = new HashMap<Integer, Set<IMultiblockPart>>();
partsAwaitingChunkLoad = new HashMap<>();
partsAwaitingChunkLoadMutex = new Object();
orphanedPartsMutex = new Object();
}
@ -128,7 +128,7 @@ public class MultiblockWorldRegistry {
synchronized (orphanedPartsMutex) {
if (orphanedParts.size() > 0) {
orphansToProcess = orphanedParts;
orphanedParts = new HashSet<IMultiblockPart>();
orphanedParts = new HashSet<>();
}
}
@ -166,7 +166,7 @@ public class MultiblockWorldRegistry {
this.controllers.add(newController);
} else if (compatibleControllers.size() > 1) {
if (mergePools == null) {
mergePools = new ArrayList<Set<MultiblockControllerBase>>();
mergePools = new ArrayList<>();
}
// THIS IS THE ONLY PLACE WHERE MERGES ARE DETECTED
@ -174,7 +174,7 @@ public class MultiblockWorldRegistry {
// impending merge.
// Locate the appropriate merge pool(s)
//boolean hasAddedToPool = false;
List<Set<MultiblockControllerBase>> candidatePools = new ArrayList<Set<MultiblockControllerBase>>();
List<Set<MultiblockControllerBase>> candidatePools = new ArrayList<>();
for (Set<MultiblockControllerBase> candidatePool : mergePools) {
if (!Collections.disjoint(candidatePool, compatibleControllers)) {
// They share at least one element, so that
@ -325,7 +325,7 @@ public class MultiblockWorldRegistry {
synchronized (partsAwaitingChunkLoadMutex) {
if (!partsAwaitingChunkLoad.containsKey(chunkHash)) {
partSet = new HashSet<IMultiblockPart>();
partSet = new HashSet<>();
partsAwaitingChunkLoad.put(chunkHash, partSet);
} else {
partSet = partsAwaitingChunkLoad.get(chunkHash);

View file

@ -28,16 +28,9 @@ public enum PartPosition {
Unknown, Interior, FrameCorner, Frame, TopFace, BottomFace, NorthFace, SouthFace, EastFace, WestFace;
public boolean isFace(PartPosition position) {
switch (position) {
case TopFace:
case BottomFace:
case NorthFace:
case SouthFace:
case EastFace:
case WestFace:
return true;
default:
return false;
}
return switch (position) {
case TopFace, BottomFace, NorthFace, SouthFace, EastFace, WestFace -> true;
default -> false;
};
}
}

View file

@ -28,8 +28,8 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import reborncore.common.multiblock.MultiblockControllerBase;
import reborncore.common.multiblock.MultiblockBlockEntityBase;
import reborncore.common.multiblock.MultiblockControllerBase;
import reborncore.common.multiblock.MultiblockValidationException;
public abstract class RectangularMultiblockBlockEntityBase extends MultiblockBlockEntityBase {

View file

@ -27,21 +27,4 @@ package reborncore.common.network;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
public final class IdentifiedPacket {
private final Identifier channel;
private final PacketByteBuf packetByteBuf;
public IdentifiedPacket(Identifier channel, PacketByteBuf packetByteBuf) {
this.channel = channel;
this.packetByteBuf = packetByteBuf;
}
public Identifier getChannel() {
return channel;
}
public PacketByteBuf getPacketByteBuf() {
return packetByteBuf;
}
}
public record IdentifiedPacket(Identifier channel, PacketByteBuf packetByteBuf) { }

View file

@ -64,7 +64,7 @@ public class NetworkManager {
public static void sendToServer(IdentifiedPacket packet) {
ClientPlayNetworking.send(packet.getChannel(), packet.getPacketByteBuf());
ClientPlayNetworking.send(packet.channel(), packet.packetByteBuf());
}
public static void sendToAll(IdentifiedPacket packet, MinecraftServer server) {
@ -86,7 +86,7 @@ public class NetworkManager {
public static void send(IdentifiedPacket packet, Collection<ServerPlayerEntity> players) {
for (ServerPlayerEntity player : players) {
ServerPlayNetworking.send(player, packet.getChannel(), packet.getPacketByteBuf());
ServerPlayNetworking.send(player, packet.channel(), packet.packetByteBuf());
}
}

View file

@ -180,8 +180,7 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
* @return the calculated comparator output or 0 if {@code blockEntity} is not a {@code PowerAcceptorBlockEntity}
*/
public static int calculateComparatorOutputFromEnergy(@Nullable BlockEntity blockEntity) {
if (blockEntity instanceof PowerAcceptorBlockEntity) {
PowerAcceptorBlockEntity storage = (PowerAcceptorBlockEntity) blockEntity;
if (blockEntity instanceof PowerAcceptorBlockEntity storage) {
return MathHelper.ceil(storage.getStored(EnergySide.UNKNOWN) * 15.0 / storage.getMaxStoredPower());
} else {
return 0;

View file

@ -29,6 +29,7 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
import reborncore.RebornCore;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.common.blocks.BlockMachineBase;
@ -41,7 +42,6 @@ import team.reborn.energy.Energy;
import team.reborn.energy.EnergySide;
import team.reborn.energy.EnergyStorage;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Optional;
@ -336,8 +336,7 @@ public class RecipeCrafter implements IUpgradeHandler {
BlockPos pos = blockEntity.getPos();
if (blockEntity.getWorld() == null) return;
BlockState oldState = blockEntity.getWorld().getBlockState(pos);
if (oldState.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) oldState.getBlock();
if (oldState.getBlock() instanceof BlockMachineBase blockMachineBase) {
boolean isActive = isActive() || canCraftAgain();
if (isActive == oldState.get(BlockMachineBase.ACTIVE)) {

View file

@ -1,49 +0,0 @@
/*
* This file is part of RebornCore, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 TeamReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package reborncore.common.util;
import java.util.Collection;
import java.util.Locale;
/**
* Created by covers1624 on 3/27/2016.
*/
public class ArrayUtils {
public static String[] arrayToLowercase(String[] array) {
String[] copy = new String[array.length];
for (int i = 0; i < array.length; i++) {
copy[i] = array[i].toLowerCase(Locale.ROOT).intern();
}
return copy;
}
public static <E> Collection<E> addAll(Collection<E> dest, Collection<? extends E>... src) {
for (Collection<? extends E> c : src) {
dest.addAll(c);
}
return dest;
}
}

View file

@ -27,42 +27,4 @@ package reborncore.common.util;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class IdentifiableObject<T> {
@NotNull
private final T object;
@NotNull
private final Identifier identifier;
public IdentifiableObject(@NotNull T object, @NotNull Identifier identifier) {
Objects.requireNonNull(object);
Objects.requireNonNull(identifier);
this.object = object;
this.identifier = identifier;
}
@NotNull
public T getObject() {
return object;
}
@NotNull
public Identifier getIdentifier() {
return identifier;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IdentifiableObject<?> that = (IdentifiableObject<?>) o;
return object.equals(that.object) &&
identifier.equals(that.identifier);
}
@Override
public int hashCode() {
return Objects.hash(object, identifier);
}
}
public record IdentifiableObject<T>(@NotNull T object, @NotNull Identifier identifier) { }

View file

@ -27,9 +27,9 @@ package reborncore.common.util;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
import reborncore.api.items.InventoryBase;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

View file

@ -41,8 +41,7 @@ public class ItemHandlerUtils {
if (blockEntity == null) {
return;
}
if (blockEntity instanceof Inventory) {
Inventory inventory = (Inventory) blockEntity;
if (blockEntity instanceof Inventory inventory) {
dropItemHandler(world, pos, inventory);
}
if (blockEntity instanceof IUpgradeable) {

View file

@ -30,7 +30,6 @@ import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
public class ItemUsageContextCustomStack extends ItemUsageContext {

View file

@ -28,12 +28,11 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.NotNull;
import reborncore.api.items.InventoryBase;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.blockentity.SlotConfiguration;
import org.jetbrains.annotations.NotNull;
public class RebornInventory<T extends MachineBaseBlockEntity> extends InventoryBase {
private final String name;
@ -56,13 +55,10 @@ public class RebornInventory<T extends MachineBaseBlockEntity> extends Inventory
if (facing == null) {
return true;
}
switch (direction) {
case INSERT:
return SlotConfiguration.canInsertItem(slotID, stack, facing, be);
case EXTRACT:
return SlotConfiguration.canExtractItem(slotID, stack, facing, be);
}
return false;
return switch (direction) {
case INSERT -> SlotConfiguration.canInsertItem(slotID, stack, facing, be);
case EXTRACT -> SlotConfiguration.canExtractItem(slotID, stack, facing, be);
};
});
}

View file

@ -32,14 +32,14 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import reborncore.client.screen.builder.Syncable;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.fluid.FluidValue;
import reborncore.common.fluid.container.FluidInstance;
import reborncore.common.fluid.container.GenericFluidContainer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

View file

@ -29,7 +29,6 @@ import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -113,7 +112,7 @@ public class TranslationTools {
System.out.println(key);
System.out.println();
for (int i = 0; i < newKeys.size(); i++) {
System.out.println(String.format("%d) %s", i, newKeys.get(i)));
System.out.printf("%d) %s%n", i, newKeys.get(i));
}
System.out.print("Input selection:");
int input = SCANNER.nextInt();
@ -129,7 +128,7 @@ public class TranslationTools {
private static Map<String, String> readJsonFile(Path path) throws IOException {
Type mapType = new TypeToken<Map<String, String>>() {
}.getType();
return new Gson().fromJson(new String(Files.readAllBytes(path), StandardCharsets.UTF_8), mapType);
return new Gson().fromJson(Files.readString(path), mapType);
}
private static Map<String, String> readLangFile(Path path) throws IOException {

View file

@ -30,6 +30,7 @@ import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -37,8 +38,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import reborncore.common.util.ItemDurabilityExtensions;
import org.jetbrains.annotations.Nullable;
//Not too happy with this, need to find and get a better solution into fabric soon
@Mixin(ItemRenderer.class)
public abstract class MixinItemRenderer {
@ -48,8 +47,7 @@ public abstract class MixinItemRenderer {
@Inject(method = "renderGuiItemOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At("HEAD"))
private void renderGuiItemOverlay(TextRenderer textRenderer, ItemStack stack, int x, int y, @Nullable String string, CallbackInfo info) {
if (stack.getItem() instanceof ItemDurabilityExtensions) {
ItemDurabilityExtensions durabilityExtensions = (ItemDurabilityExtensions) stack.getItem();
if (stack.getItem() instanceof ItemDurabilityExtensions durabilityExtensions) {
if (!durabilityExtensions.showDurability(stack)) {
return;
}

View file

@ -33,7 +33,7 @@ import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
@ -49,6 +49,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
;
@Mixin(WorldRenderer.class)
public abstract class MixinWorldRenderer {

View file

@ -47,8 +47,7 @@ public abstract class MixinItemStack {
@Inject(method = "getAttributeModifiers", at = @At("RETURN"), cancellable = true)
private void getAttributeModifiers(EquipmentSlot equipmentSlot, CallbackInfoReturnable<Multimap<EntityAttribute, EntityAttributeModifier>> info) {
if (getItem() instanceof ItemStackModifiers) {
ItemStackModifiers item = (ItemStackModifiers) getItem();
if (getItem() instanceof ItemStackModifiers item) {
Multimap<EntityAttribute, EntityAttributeModifier> modifierHashMap = ArrayListMultimap.create(info.getReturnValue());
item.getAttributeModifiers(equipmentSlot, (ItemStack) (Object) this, modifierHashMap);
info.setReturnValue(ImmutableMultimap.copyOf(modifierHashMap));

View file

@ -35,8 +35,8 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import reborncore.api.items.ArmorRemoveHandler;
import reborncore.api.items.ArmorBlockEntityTicker;
import reborncore.api.items.ArmorRemoveHandler;
import reborncore.common.util.ItemUtils;
@Mixin(PlayerEntity.class)

View file

@ -74,7 +74,7 @@ public class TechReborn implements ModInitializer {
// Done to force the class to load
//noinspection ResultOfMethodCallIgnored
ModRecipes.GRINDER.getName();
ModRecipes.GRINDER.name();
ClientboundPackets.init();
ServerboundPackets.init();

View file

@ -30,7 +30,6 @@ import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.minecraft.client.item.ModelPredicateProvider;
import net.minecraft.client.item.UnclampedModelPredicateProvider;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.model.BakedModel;
@ -49,6 +48,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.Nullable;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.multiblock.MultiblockRenderer;
import reborncore.common.util.ItemUtils;
@ -70,7 +70,6 @@ import techreborn.items.armor.BatpackItem;
import techreborn.items.tool.ChainsawItem;
import techreborn.items.tool.industrial.NanosaberItem;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

View file

@ -28,45 +28,13 @@ package techreborn.api.generator;
import net.minecraft.fluid.Fluid;
import techreborn.utils.FluidUtils;
public class FluidGeneratorRecipe {
private final EFluidGenerator generatorType;
private final Fluid fluid;
private final int energyPerMb;
public FluidGeneratorRecipe(Fluid fluid, int energyPerMb, EFluidGenerator generatorType) {
this.fluid = fluid;
this.energyPerMb = energyPerMb;
this.generatorType = generatorType;
}
public Fluid getFluid() {
return fluid;
}
public record FluidGeneratorRecipe(Fluid fluid, int energyPerMb,
EFluidGenerator generatorType) {
public int getEnergyPerBucket() {
return energyPerMb * 1000;
}
public EFluidGenerator getGeneratorType() {
return generatorType;
}
@Override
public String toString() {
return "FluidGeneratorRecipe [generatorType=" + generatorType + ", fluid=" + fluid + ", energyPerMb="
+ energyPerMb + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + energyPerMb;
result = prime * result + ((fluid == null) ? 0 : fluid.hashCode());
result = prime * result + ((generatorType == null) ? 0 : generatorType.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)

View file

@ -39,7 +39,7 @@ public class FluidGeneratorRecipeList {
}
public boolean addRecipe(FluidGeneratorRecipe fluidGeneratorRecipe) {
if (!this.getRecipeForFluid(fluidGeneratorRecipe.getFluid()).isPresent())
if (!this.getRecipeForFluid(fluidGeneratorRecipe.fluid()).isPresent())
return this.getRecipes().add(fluidGeneratorRecipe);
return false;
}
@ -49,7 +49,7 @@ public class FluidGeneratorRecipeList {
}
public Optional<FluidGeneratorRecipe> getRecipeForFluid(Fluid fluid) {
return this.recipes.stream().filter(recipe -> FluidUtils.fluidEquals(recipe.getFluid(), fluid)).findAny();
return this.recipes.stream().filter(recipe -> FluidUtils.fluidEquals(recipe.fluid(), fluid)).findAny();
}
public HashSet<FluidGeneratorRecipe> getRecipes() {

View file

@ -66,8 +66,7 @@ public class BlastFurnaceRecipe extends RebornRecipe {
@Override
public boolean canCraft(final BlockEntity blockEntity) {
if (blockEntity instanceof IndustrialBlastFurnaceBlockEntity) {
final IndustrialBlastFurnaceBlockEntity blastFurnace = (IndustrialBlastFurnaceBlockEntity) blockEntity;
if (blockEntity instanceof final IndustrialBlastFurnaceBlockEntity blastFurnace) {
return blastFurnace.getHeat() >= heat;
}
return false;

View file

@ -73,8 +73,7 @@ public class FusionReactorRecipe extends RebornRecipe {
@Override
public boolean canCraft(final BlockEntity blockEntity) {
if (blockEntity instanceof FusionControlComputerBlockEntity) {
final FusionControlComputerBlockEntity reactor = (FusionControlComputerBlockEntity) blockEntity;
if (blockEntity instanceof final FusionControlComputerBlockEntity reactor) {
return reactor.getSize() >= minSize;
}
return false;

View file

@ -27,6 +27,7 @@ package techreborn.blockentity.cable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
@ -36,7 +37,6 @@ import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
@ -180,9 +180,7 @@ public class CableBlockEntity extends BlockEntity
continue;
}
if (blockEntity instanceof CableBlockEntity) {
CableBlockEntity cableBlockEntity = (CableBlockEntity) blockEntity;
if (blockEntity instanceof CableBlockEntity cableBlockEntity) {
if (cableBlockEntity.getTier() != this.getTier()) {
continue;
}

View file

@ -138,19 +138,19 @@ public class DataDrivenBEProvider extends BlockEntityType<DataDrivenBEProvider.D
}
private int getEnergySlot() {
return slots.stream().filter(slot -> slot.getType() == SlotType.ENERGY).findFirst().orElse(null).getId();
return slots.stream().filter(slot -> slot.type() == SlotType.ENERGY).findFirst().orElse(null).id();
}
private int countOfSlotType(SlotType type) {
return (int) slots.stream()
.filter(slot -> slot.getType() == type)
.filter(slot -> slot.type() == type)
.count();
}
private int[] slotIds(SlotType type) {
return slots.stream()
.filter(slot -> slot.getType() == type)
.mapToInt(DataDrivenSlot::getId)
.filter(slot -> slot.type() == type)
.mapToInt(DataDrivenSlot::id)
.toArray();
}

View file

@ -30,7 +30,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.JsonHelper;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
import reborncore.client.gui.builder.GuiBase;
import reborncore.client.screen.builder.BlockEntityScreenHandlerBuilder;
import reborncore.common.util.serialization.SerializationUtil;
@ -39,7 +39,7 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class DataDrivenSlot {
public record DataDrivenSlot(int id, int x, int y, @NotNull SlotType type) {
public static List<DataDrivenSlot> read(JsonArray jsonArray) {
AtomicInteger idCount = new AtomicInteger();
@ -49,35 +49,6 @@ public class DataDrivenSlot {
.collect(Collectors.toList());
}
private final int id;
private final int x;
private final int y;
private final SlotType type;
public DataDrivenSlot(int id, int x, int y, SlotType type) {
this.id = id;
this.x = x;
this.y = y;
this.type = type;
Validate.notNull(type);
}
public int getId() {
return id;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public SlotType getType() {
return type;
}
public void add(BlockEntityScreenHandlerBuilder inventoryBuilder) {
type.getSlotBiConsumer().accept(inventoryBuilder, this);
}
@ -85,10 +56,10 @@ public class DataDrivenSlot {
@Environment(EnvType.CLIENT)
public void draw(MatrixStack matrixStack, GuiBase<?> guiBase, GuiBase.Layer layer) {
//TODO find a better way to do this
if (getType() == SlotType.OUTPUT) {
guiBase.drawOutputSlot(matrixStack, getX(), getY(), layer);
if (type() == SlotType.OUTPUT) {
guiBase.drawOutputSlot(matrixStack, x(), y(), layer);
} else {
guiBase.drawSlot(matrixStack, getX(), getY(), layer);
guiBase.drawSlot(matrixStack, x(), y(), layer);
}
}
}

View file

@ -32,13 +32,13 @@ import java.util.function.BiConsumer;
public enum SlotType {
//Im really not a fan of the way I add the slots to the builder here
INPUT((builder, slot) -> {
builder.slot(slot.getId(), slot.getX(), slot.getY());
builder.slot(slot.id(), slot.x(), slot.y());
}),
OUTPUT((builder, slot) -> {
builder.outputSlot(slot.getId(), slot.getX(), slot.getY());
builder.outputSlot(slot.id(), slot.x(), slot.y());
}),
ENERGY((builder, slot) -> {
builder.energySlot(slot.getId(), slot.getX(), slot.getY());
builder.energySlot(slot.id(), slot.x(), slot.y());
});
public static SlotType fromString(String string) {

View file

@ -105,7 +105,7 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
}
if (!tank.getFluidAmount().isEmpty()) {
if (currentRecipe == null || !FluidUtils.fluidEquals(currentRecipe.getFluid(), tank.getFluid()))
if (currentRecipe == null || !FluidUtils.fluidEquals(currentRecipe.fluid(), tank.getFluid()))
currentRecipe = getRecipes().getRecipeForFluid(tank.getFluid()).orElse(null);
if (currentRecipe != null) {

View file

@ -65,12 +65,10 @@ public class LightningRodBlockEntity extends PowerAcceptorBlockEntity implements
}
Block BEBlock = getCachedState().getBlock();
if (!(BEBlock instanceof BlockMachineBase)) {
if (!(BEBlock instanceof BlockMachineBase machineBaseBlock)) {
return;
}
BlockMachineBase machineBaseBlock = (BlockMachineBase) BEBlock;
if (onStatusHoldTicks == 0 || getEnergy() <= 0) {
machineBaseBlock.setActive(false, world, pos);
onStatusHoldTicks = -1;

View file

@ -82,8 +82,7 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
return;
}
Block panelBlock = world.getBlockState(pos).getBlock();
if (panelBlock instanceof BlockSolarPanel) {
BlockSolarPanel solarPanelBlock = (BlockSolarPanel) panelBlock;
if (panelBlock instanceof BlockSolarPanel solarPanelBlock) {
panel = solarPanelBlock.panelType;
}
}
@ -133,17 +132,11 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
}
public int getGenerationRate() {
int rate = 0;
switch (getSunState()) {
case DAYGEN:
rate = getPanel().generationRateD;
break;
case NIGHTGEN:
rate = getPanel().generationRateN;
}
return rate;
return switch (getSunState()) {
case DAYGEN -> getPanel().generationRateD;
case NIGHTGEN -> getPanel().generationRateN;
default -> 0;
};
}

View file

@ -122,8 +122,7 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
public void updateState() {
final BlockState BlockStateContainer = world.getBlockState(pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getBlock() instanceof final BlockMachineBase blockMachineBase) {
boolean active = burnTime > 0 && getFreeSpace() > 0.0f;
if (BlockStateContainer.get(BlockMachineBase.ACTIVE) != active) {
blockMachineBase.setActive(active, world, pos);

View file

@ -125,8 +125,7 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
private void updateState() {
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock();
if (state.getBlock() instanceof BlockMachineBase blockMachineBase) {
if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0)
blockMachineBase.setActive(burnTime > 0, world, pos);
}

View file

@ -59,8 +59,7 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
}
public void handleGuiInputFromClient(PlayerEntity playerIn) {
if (playerIn instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) playerIn;
if (playerIn instanceof ServerPlayerEntity player) {
int totalExperience = (int) experience;
while (totalExperience > 0) {
int expToDrop = ExperienceOrbEntity.roundToOrbSize(totalExperience);

View file

@ -26,14 +26,13 @@ package techreborn.blockentity.machine.misc;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.sound.SoundCategory;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.api.IToolDrop;
@ -94,15 +93,9 @@ public class AlarmBlockEntity extends BlockEntity
if (world.isReceivingRedstonePower(getPos())) {
BlockAlarm.setActive(true, world, pos);
switch (selectedSound) {
case 1:
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM, SoundCategory.BLOCKS, 4F, 1F);
break;
case 2:
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_2, SoundCategory.BLOCKS, 4F, 1F);
break;
case 3:
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_3, SoundCategory.BLOCKS, 4F, 1F);
break;
case 1 -> world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM, SoundCategory.BLOCKS, 4F, 1F);
case 2 -> world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_2, SoundCategory.BLOCKS, 4F, 1F);
case 3 -> world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.ALARM_3, SoundCategory.BLOCKS, 4F, 1F);
}
} else {
BlockAlarm.setActive(false, world, pos);

View file

@ -40,6 +40,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -56,7 +57,6 @@ import techreborn.init.ModSounds;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

View file

@ -131,8 +131,7 @@ public class ElectricFurnaceBlockEntity extends PowerAcceptorBlockEntity
private void updateState() {
Block furnaceBlock = getWorld().getBlockState(pos).getBlock();
if (furnaceBlock instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) furnaceBlock;
if (furnaceBlock instanceof BlockMachineBase blockMachineBase) {
boolean isActive = currentRecipe != null || canCraftAgain();
blockMachineBase.setActive(isActive, world, pos);
}

View file

@ -178,8 +178,7 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
return;
}
isRunning = active;
if (this.getWorld().getBlockState(this.getPos()).getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) this.getWorld().getBlockState(this.getPos()).getBlock();
if (this.getWorld().getBlockState(this.getPos()).getBlock() instanceof BlockMachineBase blockMachineBase) {
blockMachineBase.setActive(active, this.getWorld(), this.getPos());
}
this.getWorld().updateListeners(this.getPos(), this.getWorld().getBlockState(this.getPos()), this.getWorld().getBlockState(this.getPos()), 3);

View file

@ -27,11 +27,9 @@ package techreborn.blockentity.machine.tier1;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.client.screen.BuiltScreenHandlerProvider;
import reborncore.client.screen.builder.BuiltScreenHandler;
import reborncore.client.screen.builder.ScreenHandlerBuilder;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.RebornInventory;
import techreborn.blockentity.machine.GenericMachineBlockEntity;

View file

@ -34,6 +34,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -46,8 +47,6 @@ import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import org.jetbrains.annotations.Nullable;
public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IToolDrop, InventoryProvider, BuiltScreenHandlerProvider {
public RebornInventory<ChunkLoaderBlockEntity> inventory = new RebornInventory<>(0, "ChunkLoaderBlockEntity", 64, this);

View file

@ -28,9 +28,9 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.PersistentState;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import reborncore.common.util.NBTSerializable;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
public class IDSUManager extends PersistentState {

View file

@ -50,10 +50,9 @@ public class LSUStorageBlockEntity extends MachineBaseBlockEntity
network.addElement(this);
for (Direction direction : Direction.values()) {
BlockEntity be = world.getBlockEntity(pos.offset(direction));
if (!(be instanceof LSUStorageBlockEntity)) {
if (!(be instanceof LSUStorageBlockEntity lesuStorage)) {
continue;
}
LSUStorageBlockEntity lesuStorage = (LSUStorageBlockEntity) be;
if (lesuStorage.network != null) {
lesuStorage.network.merge(network);
}

View file

@ -36,6 +36,7 @@ import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.IListInfoProvider;
import reborncore.api.IToolDrop;
import reborncore.api.blockentity.InventoryProvider;
@ -49,7 +50,6 @@ import reborncore.common.util.WorldUtils;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implements InventoryProvider, IToolDrop, IListInfoProvider, BuiltScreenHandlerProvider {

View file

@ -54,6 +54,7 @@ import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;
import reborncore.api.ToolManager;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.util.WrenchUtils;
@ -65,8 +66,6 @@ import techreborn.init.ModSounds;
import techreborn.init.TRContent;
import techreborn.utils.damageSources.ElectrialShockSource;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
@ -106,20 +105,14 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
}
public BooleanProperty getProperty(Direction facing) {
switch (facing) {
case WEST:
return WEST;
case NORTH:
return NORTH;
case SOUTH:
return SOUTH;
case UP:
return UP;
case DOWN:
return DOWN;
default:
return EAST;
}
return switch (facing) {
case WEST -> WEST;
case NORTH -> NORTH;
case SOUTH -> SOUTH;
case UP -> UP;
case DOWN -> DOWN;
default -> EAST;
};
}
private BlockState makeConnections(World world, BlockPos pos) {
@ -250,11 +243,10 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
if (blockEntity == null) {
return;
}
if (!(blockEntity instanceof CableBlockEntity)) {
if (!(blockEntity instanceof CableBlockEntity blockEntityCable)) {
return;
}
CableBlockEntity blockEntityCable = (CableBlockEntity) blockEntity;
if (blockEntityCable.getEnergy() <= 0) {
return;
}

View file

@ -42,14 +42,13 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.ToolManager;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.util.WrenchUtils;
import techreborn.blockentity.lighting.LampBlockEntity;
import org.jetbrains.annotations.Nullable;
import java.util.function.ToIntFunction;
public class LampBlock extends BaseBlockEntityProvider {

View file

@ -45,13 +45,13 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.api.ToolManager;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.util.WrenchUtils;
import techreborn.blockentity.machine.misc.AlarmBlockEntity;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class BlockAlarm extends BaseBlockEntityProvider {

View file

@ -45,11 +45,11 @@ public class BlockMachineCasing extends BlockMultiblockBase {
public static int getHeatFromState(BlockState state) {
Block block = state.getBlock();
if (!(block instanceof BlockMachineCasing)) {
return 0;
if (block instanceof BlockMachineCasing casing) {
return casing.heatCapacity;
}
BlockMachineCasing casing = (BlockMachineCasing) block;
return casing.heatCapacity;
return 0;
}
@Override

View file

@ -75,13 +75,12 @@ public class BlockNuke extends BaseBlock {
@Override
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
if (!worldIn.isClient && entityIn instanceof ProjectileEntity) {
ProjectileEntity entityarrow = (ProjectileEntity) entityIn;
if (!worldIn.isClient && entityIn instanceof ProjectileEntity projectileEntity) {
LivingEntity shooter = null;
if (entityarrow.getOwner() instanceof LivingEntity) {
shooter = (LivingEntity) entityarrow.getOwner();
if (projectileEntity.getOwner() instanceof LivingEntity) {
shooter = (LivingEntity) projectileEntity.getOwner();
}
if (entityarrow.isOnFire()) {
if (projectileEntity.isOnFire()) {
ignite(worldIn, pos, state, shooter);
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
}

View file

@ -58,8 +58,7 @@ public class LSUStorageBlock extends BaseBlockEntityProvider {
if (state.getBlock() == newState.getBlock()) {
return;
}
if (worldIn.getBlockEntity(pos) instanceof LSUStorageBlockEntity) {
LSUStorageBlockEntity blockEntity = (LSUStorageBlockEntity) worldIn.getBlockEntity(pos);
if (worldIn.getBlockEntity(pos) instanceof LSUStorageBlockEntity blockEntity) {
if (blockEntity != null) {
blockEntity.removeFromNetwork();
}
@ -75,8 +74,7 @@ public class LSUStorageBlock extends BaseBlockEntityProvider {
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity player, ItemStack itemstack) {
super.onPlaced(world, pos, state, player, itemstack);
if (world.getBlockEntity(pos) instanceof LSUStorageBlockEntity) {
LSUStorageBlockEntity blockEntity = (LSUStorageBlockEntity) world.getBlockEntity(pos);
if (world.getBlockEntity(pos) instanceof LSUStorageBlockEntity blockEntity) {
if (blockEntity != null) {
blockEntity.rebuildNetwork();
}

View file

@ -75,10 +75,9 @@ public class TankUnitBlock extends BlockMachineBase {
// Assuming ItemFluidInfo is 1 BUCKET, for now only allow exact amount or less
// I am only going to trust cells or buckets, they are known to be 1 BUCKET size, too suss of other items not abiding by that.
if ((itemInHand instanceof DynamicCellItem || itemInHand instanceof BucketItem)
&& tankUnitEntity != null && itemInHand instanceof ItemFluidInfo) {
&& tankUnitEntity != null && itemInHand instanceof ItemFluidInfo itemFluid) {
// Get fluid information from item
ItemFluidInfo itemFluid = (ItemFluidInfo) itemInHand;
Fluid fluid = itemFluid.getFluid(stackInHand);
int amount = stackInHand.getCount();
@ -154,14 +153,11 @@ public class TankUnitBlock extends BlockMachineBase {
boolean isSameItemFluid(ItemStack i1, ItemStack i2){
// Only care about cells, buckets don't stack
if(!(i1.getItem() instanceof DynamicCellItem && i2.getItem() instanceof DynamicCellItem)){
return false;
if(i1.getItem() instanceof DynamicCellItem dc1 && i2.getItem() instanceof DynamicCellItem dc2){
return dc1.getFluid(i1).matchesType(dc2.getFluid(i2));
}
DynamicCellItem dc1 = (DynamicCellItem)i1.getItem();
DynamicCellItem dc2 = (DynamicCellItem)i2.getItem();
return dc1.getFluid(i1).matchesType(dc2.getFluid(i2));
return false;
}
@Override

View file

@ -42,6 +42,7 @@ import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import reborncore.RebornCore;
import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.client.screen.BuiltScreenHandlerProvider;
@ -73,7 +74,6 @@ import techreborn.blockentity.storage.fluid.TankUnitBaseBlockEntity;
import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity;
import techreborn.client.gui.*;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

View file

@ -24,7 +24,6 @@
package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;

View file

@ -24,7 +24,6 @@
package techreborn.client.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;

View file

@ -24,7 +24,6 @@
package techreborn.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;

View file

@ -49,15 +49,9 @@ public class GuiSolar extends GuiBase<BuiltScreenHandler> {
builder.drawMultiEnergyBar(matrixStack, this, 156, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxStoredPower(), mouseX, mouseY, 0, layer);
switch (blockEntity.getSunState()) {
case SolarPanelBlockEntity.DAYGEN:
builder.drawText(matrixStack, this, new TranslatableText("techreborn.message.daygen"), 10, 20, 15129632);
break;
case SolarPanelBlockEntity.NIGHTGEN:
builder.drawText(matrixStack, this, new TranslatableText("techreborn.message.nightgen"), 10, 20, 7566195);
break;
case SolarPanelBlockEntity.ZEROGEN:
builder.drawText(matrixStack, this, new TranslatableText("techreborn.message.zerogen"), 10, 20, 12066591);
break;
case SolarPanelBlockEntity.DAYGEN -> builder.drawText(matrixStack, this, new TranslatableText("techreborn.message.daygen"), 10, 20, 15129632);
case SolarPanelBlockEntity.NIGHTGEN -> builder.drawText(matrixStack, this, new TranslatableText("techreborn.message.nightgen"), 10, 20, 7566195);
case SolarPanelBlockEntity.ZEROGEN -> builder.drawText(matrixStack, this, new TranslatableText("techreborn.message.zerogen"), 10, 20, 12066591);
}
builder.drawText(matrixStack, this, new LiteralText("Generating: " + blockEntity.getGenerationRate() + " E/t"), 10, 30, 0);

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