Skip to content

Commit

Permalink
chore: ported to 1.20.4, added neoforge
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Dec 15, 2023
1 parent bb042dd commit 8668d28
Show file tree
Hide file tree
Showing 38 changed files with 969 additions and 78 deletions.
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
}

architectury {
common("forge", "fabric")
common("forge", "fabric", "neoforge")
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbquests.block;

import com.mojang.serialization.MapCodec;
import dev.ftb.mods.ftbquests.block.entity.DetectorBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -16,8 +17,12 @@
import org.jetbrains.annotations.Nullable;

public class DetectorBlock extends BaseEntityBlock {
public DetectorBlock() {
super(BlockBehaviour.Properties.of().strength(0.3F));
private static final MapCodec<DetectorBlock> CODEC = simpleCodec(DetectorBlock::new);
public static final Properties PROPS = Properties.of().strength(0.3F);

public DetectorBlock(BlockBehaviour.Properties props) {
super(props);

registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.POWERED, false));
}

Expand All @@ -27,6 +32,11 @@ public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new DetectorBlockEntity(blockPos, blockState);
}

@Override
protected MapCodec<DetectorBlock> codec() {
return CODEC;
}

@Override
public RenderShape getRenderShape(BlockState blockState) {
return RenderShape.MODEL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@
public class FTBQuestsBlocks {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(FTBQuestsAPI.MOD_ID, Registries.BLOCK);

public static final RegistrySupplier<Block> BARRIER = BLOCKS.register("barrier", QuestBarrierBlock::new);
public static final RegistrySupplier<Block> STAGE_BARRIER = BLOCKS.register("stage_barrier", StageBarrierBlock::new);
public static final RegistrySupplier<Block> DETECTOR = BLOCKS.register("detector", DetectorBlock::new);
public static final RegistrySupplier<Block> LOOT_CRATE_OPENER = BLOCKS.register("loot_crate_opener", LootCrateOpenerBlock::new);
public static final RegistrySupplier<Block> BARRIER
= BLOCKS.register("barrier", () -> new QuestBarrierBlock(QuestBarrierBlock.PROPS));
public static final RegistrySupplier<Block> STAGE_BARRIER
= BLOCKS.register("stage_barrier", () -> new StageBarrierBlock(QuestBarrierBlock.PROPS));
public static final RegistrySupplier<Block> DETECTOR
= BLOCKS.register("detector", () -> new DetectorBlock(DetectorBlock.PROPS));
public static final RegistrySupplier<Block> LOOT_CRATE_OPENER
= BLOCKS.register("loot_crate_opener", () -> new LootCrateOpenerBlock(LootCrateOpenerBlock.PROPS));

public static final RegistrySupplier<Block> TASK_SCREEN_1 = BLOCKS.register("screen_1", () -> new TaskScreenBlock(1));
public static final RegistrySupplier<Block> TASK_SCREEN_3 = BLOCKS.register("screen_3", () -> new TaskScreenBlock(3));
public static final RegistrySupplier<Block> TASK_SCREEN_5 = BLOCKS.register("screen_5", () -> new TaskScreenBlock(5));
public static final RegistrySupplier<Block> TASK_SCREEN_7 = BLOCKS.register("screen_7", () -> new TaskScreenBlock(7));
public static final RegistrySupplier<Block> AUX_SCREEN = BLOCKS.register("aux_task_screen", TaskScreenBlock.Aux::new);
public static final RegistrySupplier<Block> TASK_SCREEN_1
= BLOCKS.register("screen_1", () -> new TaskScreenBlock(TaskScreenBlock.PROPS, 1));
public static final RegistrySupplier<Block> TASK_SCREEN_3
= BLOCKS.register("screen_3", () -> new TaskScreenBlock(TaskScreenBlock.PROPS, 3));
public static final RegistrySupplier<Block> TASK_SCREEN_5
= BLOCKS.register("screen_5", () -> new TaskScreenBlock(TaskScreenBlock.PROPS, 5));
public static final RegistrySupplier<Block> TASK_SCREEN_7
= BLOCKS.register("screen_7", () -> new TaskScreenBlock(TaskScreenBlock.PROPS, 7));
public static final RegistrySupplier<Block> AUX_SCREEN
= BLOCKS.register("aux_task_screen", () -> new TaskScreenBlock.Aux(TaskScreenBlock.PROPS));

public static void register() {
BLOCKS.register();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbquests.block;

import com.mojang.serialization.MapCodec;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.ftb.mods.ftbquests.block.entity.LootCrateOpenerBlockEntity;
import net.minecraft.core.BlockPos;
Expand All @@ -10,8 +11,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand All @@ -20,9 +20,12 @@
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;

public class LootCrateOpenerBlock extends Block implements EntityBlock {
public LootCrateOpenerBlock() {
super(Properties.of().mapColor(MapColor.WOOD).strength(1.8f));
public class LootCrateOpenerBlock extends BaseEntityBlock {
private static final MapCodec<LootCrateOpenerBlock> CODEC = simpleCodec(LootCrateOpenerBlock::new);
public static final Properties PROPS = Properties.of().mapColor(MapColor.WOOD).strength(1.8f);

public LootCrateOpenerBlock(Properties props) {
super(PROPS);
}

@Nullable
Expand All @@ -36,6 +39,11 @@ public static BlockEntityType.BlockEntitySupplier<LootCrateOpenerBlockEntity> bl
throw new AssertionError();
}

@Override
protected MapCodec<LootCrateOpenerBlock> codec() {
return null;
}

@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ftb.mods.ftbquests.block;

import com.mojang.serialization.MapCodec;
import dev.architectury.hooks.level.entity.EntityHooks;
import dev.ftb.mods.ftbquests.block.entity.BarrierBlockEntity;
import dev.ftb.mods.ftbquests.block.entity.QuestBarrierBlockEntity;
Expand Down Expand Up @@ -29,19 +30,22 @@
import org.jetbrains.annotations.Nullable;

public class QuestBarrierBlock extends BaseEntityBlock {
private static final MapCodec<QuestBarrierBlock> CODEC = simpleCodec(QuestBarrierBlock::new);

public static final BooleanProperty OPEN = BooleanProperty.create("open");

protected QuestBarrierBlock() {
super(Properties.of()
.mapColor(MapColor.COLOR_LIGHT_BLUE)
.pushReaction(PushReaction.BLOCK)
.noOcclusion()
.isViewBlocking((blockState, blockGetter, blockPos) -> false)
.isSuffocating((blockState, blockGetter, blockPos) -> false)
.strength(-1, 6000000F)
.lightLevel(blockState -> 3)
.emissiveRendering((blockState, blockGetter, blockPos) -> true)
);
public static final Properties PROPS = Properties.of()
.mapColor(MapColor.COLOR_LIGHT_BLUE)
.pushReaction(PushReaction.BLOCK)
.noOcclusion()
.isViewBlocking((blockState, blockGetter, blockPos) -> false)
.isSuffocating((blockState, blockGetter, blockPos) -> false)
.strength(-1, 6000000F)
.lightLevel(blockState -> 3)
.emissiveRendering((blockState, blockGetter, blockPos) -> true);

protected QuestBarrierBlock(Properties props) {
super(props);

registerDefaultState(defaultBlockState().setValue(OPEN, false));
}
Expand All @@ -51,6 +55,11 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
builder.add(OPEN);
}

@Override
protected MapCodec<? extends QuestBarrierBlock> codec() {
return CODEC;
}

@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package dev.ftb.mods.ftbquests.block;

import com.mojang.serialization.MapCodec;
import dev.ftb.mods.ftbquests.block.entity.StageBarrierBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;

public class StageBarrierBlock extends QuestBarrierBlock {
private static final MapCodec<StageBarrierBlock> CODEC = simpleCodec(StageBarrierBlock::new);

protected StageBarrierBlock(Properties props) {
super(props);
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new StageBarrierBlockEntity(blockPos, blockState);
}

@Override
protected MapCodec<StageBarrierBlock> codec() {
return CODEC;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.ftb.mods.ftbquests.block;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.ftb.mods.ftbquests.block.entity.ITaskScreen;
import dev.ftb.mods.ftbquests.block.entity.TaskScreenAuxBlockEntity;
Expand Down Expand Up @@ -45,11 +48,19 @@
import java.util.Objects;

public class TaskScreenBlock extends BaseEntityBlock {
private static final MapCodec<TaskScreenBlock> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(propertiesCodec())
.and(Codec.INT.fieldOf("size").forGetter(TaskScreenBlock::getSize))
.apply(instance, TaskScreenBlock::new)
);

public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final Properties PROPS = Properties.of().mapColor(DyeColor.BLACK).strength(0.3f);

private final int size;

protected TaskScreenBlock(int size) {
super(Properties.of().mapColor(DyeColor.BLACK).strength(0.3f));
protected TaskScreenBlock(Properties props, int size) {
super(props);
this.size = size;

registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH));
Expand Down Expand Up @@ -82,6 +93,11 @@ public static BlockEntityType.BlockEntitySupplier<TaskScreenAuxBlockEntity> bloc
throw new AssertionError();
}

@Override
protected MapCodec<? extends TaskScreenBlock> codec() {
return CODEC;
}

@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
Expand Down Expand Up @@ -203,7 +219,7 @@ public static boolean hasPermissionToEdit(ServerPlayer player, ITaskScreen scree
* @return the bounding box containing all blocks of the multiblock
*/
public static AABB getMultiblockBounds(BlockPos corePos, int size, Direction facing) {
if (size == 1) return new AABB(corePos, corePos);
if (size == 1) return new AABB(corePos);

int size2 = size / 2;
facing = facing.getCounterClockWise();
Expand All @@ -215,14 +231,20 @@ public static AABB getMultiblockBounds(BlockPos corePos, int size, Direction fac
}

public static class Aux extends TaskScreenBlock {
protected Aux() {
super(0);
private static final MapCodec<Aux> CODEC = simpleCodec(Aux::new);

protected Aux(Properties props) {
super(props, 0);
}

@Override
public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return blockEntityAuxProvider().create(blockPos, blockState);
}

@Override
protected MapCodec<Aux> codec() {
return CODEC;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.architectury.event.events.client.ClientLifecycleEvent;
import dev.architectury.event.events.client.ClientPlayerEvent;
import dev.architectury.event.events.client.ClientTickEvent;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.registry.client.rendering.BlockEntityRendererRegistry;
import dev.architectury.registry.client.rendering.ColorHandlerRegistry;
import dev.ftb.mods.ftblibrary.icon.Color4I;
Expand All @@ -14,6 +15,7 @@
import dev.ftb.mods.ftblibrary.ui.GuiHelper;
import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
import dev.ftb.mods.ftbquests.block.entity.FTBQuestsBlockEntities;
import dev.ftb.mods.ftbquests.block.entity.TaskScreenBlockEntity;
import dev.ftb.mods.ftbquests.events.ClearFileCacheEvent;
import dev.ftb.mods.ftbquests.item.FTBQuestsItems;
import dev.ftb.mods.ftbquests.item.LootCrateItem;
Expand All @@ -31,6 +33,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -81,7 +84,7 @@ public void init() {
}

// Note: Architectury doesn't have a texture stitch post event anymore,
// so this is handled by the Forge event, and a mixin on Fabric
// so this is handled by the Forge/NeoForge events, and a mixin on Fabric
public static void onTextureStitchPost(TextureAtlas textureAtlas) {
if (textureAtlas.location().equals(InventoryMenu.BLOCK_ATLAS)) {
inputOnlySprite = textureAtlas.getSprite(INPUT_ONLY_TEXTURE);
Expand All @@ -94,7 +97,12 @@ public static void onTextureStitchPost(TextureAtlas textureAtlas) {
}

private void registerBERs(Minecraft minecraft) {
BlockEntityRendererRegistry.register(FTBQuestsBlockEntities.CORE_TASK_SCREEN.get(), TaskScreenRenderer::new);
BlockEntityRendererRegistry.register(FTBQuestsBlockEntities.CORE_TASK_SCREEN.get(), taskScreenRenderer());
}

@ExpectPlatform
public static BlockEntityRendererProvider<TaskScreenBlockEntity> taskScreenRenderer() {
throw new AssertionError();
}

private void registerItemColors(Minecraft minecraft) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ImageComponentWidget(ViewQuestPanel viewQuestPanel, Panel panel, ImageCom
this.index = index;

mutableComponent = MutableComponent.create(this.component);
setSize(this.component.width, this.component.height);
setSize(this.component.getWidth(), this.component.getHeight());
}

public void addMouseOverText(TooltipList list) {
Expand All @@ -35,7 +35,7 @@ public void addMouseOverText(TooltipList list) {
}

public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) {
component.image.draw(graphics, x, y, w, h);
component.getImage().draw(graphics, x, y, w, h);
}

public ImageComponent getComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ private void openImageSelector() {
}
});

group.add("image", new ImageConfig(), component.image.toString(), v -> component.image = Icon.getIcon(v), "");
group.addInt("width", component.width, v -> component.width = v, 0, 1, 1000);
group.addInt("height", component.height, v -> component.height = v, 0, 1, 1000);
group.addInt("align", component.align, v -> component.align = v, 0, 1, 2);
group.addBool("fit", component.fit, v -> component.fit = v, false);
group.add("image", new ImageConfig(), component.imageStr(), v -> component.setImage(Icon.getIcon(v)), "");
group.addInt("width", component.getWidth(), component::setWidth, 0, 1, 1000);
group.addInt("height", component.getHeight(), component::setHeight, 0, 1, 1000);
group.addEnum("align", component.getAlign(), component::setAlign, ImageComponent.ImageAlign.NAME_MAP, ImageComponent.ImageAlign.CENTER);
group.addBool("fit", component.isFit(), component::setFit, false);

new EditConfigScreen(group).openGui();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.contents.PlainTextContents;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
Expand Down Expand Up @@ -133,7 +133,7 @@ public TwoColumnList(Panel p, List<Pair<Component, Component>> data) {
int widestL = 0, widestR = 0;
int h = 0;
for (var entry : data) {
boolean header = entry.getRight().getContents().equals(ComponentContents.EMPTY);
boolean header = entry.getRight().getContents().equals(PlainTextContents.EMPTY);
widestL = Math.max(widestL, theme.getStringWidth(entry.getLeft()));
widestR = Math.max(widestR, theme.getStringWidth(entry.getRight()));
h += theme.getFontHeight() + (header ? 3 : 1);
Expand All @@ -150,7 +150,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
int yPos = y;

for (var entry : data) {
boolean header = entry.getRight().getContents().equals(ComponentContents.EMPTY);
boolean header = entry.getRight().getContents().equals(PlainTextContents.EMPTY);
int xOff = header ? widestL + 10 : widestL - theme.getStringWidth(entry.getLeft()) - 2;
theme.drawString(graphics, entry.getLeft(), x + xOff, yPos);
theme.drawString(graphics, entry.getRight(), x + widestL + 10, yPos);
Expand Down
Loading

0 comments on commit 8668d28

Please sign in to comment.