Skip to content

Commit

Permalink
add prismarine forge, add gui indicator for lava in forge, change dee…
Browse files Browse the repository at this point in the history
…pslate forge controller to use deepslate bricks texture, sort controllers in item group
  • Loading branch information
gliscowo committed Mar 29, 2022
1 parent 512a641 commit 9a75033
Show file tree
Hide file tree
Showing 32 changed files with 222 additions and 256 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rei_version=8.0.438
modmenu_version=3.0.1

# https://github.com/glisco03/owo-lib
owo_version=0.5.4+1.18
owo_version=0.6.0+1.18

# https://modrinth.com/mod/lithium
lithium_version=mc1.18.2-0.7.9
53 changes: 14 additions & 39 deletions src/main/java/wraith/alloyforgery/AlloyForgeScreenHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package wraith.alloyforgery;

import io.wispforest.owo.client.screens.ScreenUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
Expand All @@ -9,6 +10,7 @@
import net.minecraft.screen.PropertyDelegate;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import wraith.alloyforgery.block.ForgeControllerBlockEntity;
import wraith.alloyforgery.forges.ForgeFuelRegistry;

public class AlloyForgeScreenHandler extends ScreenHandler {
Expand All @@ -17,7 +19,7 @@ public class AlloyForgeScreenHandler extends ScreenHandler {
private final PropertyDelegate propertyDelegate;

public AlloyForgeScreenHandler(int syncId, PlayerInventory inventory) {
this(syncId, inventory, new SimpleInventory(12), new ArrayPropertyDelegate(2));
this(syncId, inventory, new SimpleInventory(ForgeControllerBlockEntity.INVENTORY_SIZE), new ArrayPropertyDelegate(3));
}

public AlloyForgeScreenHandler(int syncId, PlayerInventory playerInventory, Inventory inventory, PropertyDelegate propertyDelegate) {
Expand All @@ -27,66 +29,35 @@ public AlloyForgeScreenHandler(int syncId, PlayerInventory playerInventory, Inve
this.propertyDelegate = propertyDelegate;
this.addProperties(propertyDelegate);

int m, l;

//Fuel Slot
this.addSlot(new Slot(controllerInventory, 11, 8, 58) {
this.addSlot(new Slot(controllerInventory, 11, 8, 74) {
@Override
public boolean canInsert(ItemStack stack) {
return ForgeFuelRegistry.hasFuel(stack.getItem());
}
});

//Recipe Output
this.addSlot(new Slot(controllerInventory, 10, 145, 34) {
this.addSlot(new Slot(controllerInventory, 10, 145, 50) {
@Override
public boolean canInsert(ItemStack stack) {
return false;
}
});

//Recipe Inputs
for (m = 0; m < 2; m++) {
for (l = 0; l < 5; l++) {
this.addSlot(new Slot(controllerInventory, l + m * 5, 44 + l * 18, 27 + m * 18));
for (int m = 0; m < 2; m++) {
for (int l = 0; l < 5; l++) {
this.addSlot(new Slot(controllerInventory, l + m * 5, 44 + l * 18, 43 + m * 18));
}
}

//Player inventory
for (m = 0; m < 3; ++m) {
for (l = 0; l < 9; ++l) {
this.addSlot(new Slot(playerInventory, l + m * 9 + 9, 8 + l * 18, 91 + m * 18));
}
}
//Player Hotbar
for (m = 0; m < 9; ++m) {
this.addSlot(new Slot(playerInventory, m, 8 + m * 18, 149));
}
ScreenUtils.generatePlayerSlots(8, 107, playerInventory, this::addSlot);
}

@Override
public ItemStack transferSlot(PlayerEntity player, int invSlot) {
ItemStack newStack = ItemStack.EMPTY;
Slot slot = this.slots.get(invSlot);
if (slot.hasStack()) {
ItemStack originalStack = slot.getStack();
newStack = originalStack.copy();
if (invSlot < this.controllerInventory.size()) {
if (!this.insertItem(originalStack, this.controllerInventory.size(), this.slots.size(), true)) {
return ItemStack.EMPTY;
}
} else if (!this.insertItem(originalStack, 0, this.controllerInventory.size(), false)) {
return ItemStack.EMPTY;
}

if (originalStack.isEmpty()) {
slot.setStack(ItemStack.EMPTY);
} else {
slot.markDirty();
}
}

return newStack;
return ScreenUtils.handleSlotTransfer(this, invSlot, this.controllerInventory.size());
}

public int getSmeltProgress() {
Expand All @@ -97,6 +68,10 @@ public int getFuelProgress() {
return propertyDelegate.get(1);
}

public int getLavaProgress() {
return propertyDelegate.get(2);
}

@Override
public boolean canUse(PlayerEntity player) {
return this.controllerInventory.canPlayerUse(player);
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/wraith/alloyforgery/AlloyForgery.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package wraith.alloyforgery;

import io.wispforest.owo.itemgroup.OwoItemGroup;
import io.wispforest.owo.moddata.ModDataLoader;
import io.wispforest.owo.particles.ClientParticles;
import io.wispforest.owo.particles.systems.ParticleSystem;
import io.wispforest.owo.particles.systems.ParticleSystemController;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.resource.ResourceType;
import net.minecraft.screen.ScreenHandlerType;
Expand All @@ -30,7 +27,7 @@ public class AlloyForgery implements ModInitializer {

public static final String MOD_ID = "alloy_forgery";

public static ItemGroup ALLOY_FORGERY_GROUP;
public static final OwoItemGroup ALLOY_FORGERY_GROUP = new AlloyForgeryItemGroup(id("alloy_forgery"));

public static BlockEntityType<ForgeControllerBlockEntity> FORGE_CONTROLLER_BLOCK_ENTITY;
public static ScreenHandlerType<AlloyForgeScreenHandler> ALLOY_FORGE_SCREEN_HANDLER_TYPE;
Expand All @@ -45,19 +42,20 @@ public class AlloyForgery implements ModInitializer {
@Override
@SuppressWarnings("UnstableApiUsage")
public void onInitialize() {
ALLOY_FORGERY_GROUP = FabricItemGroupBuilder.create(id("alloy_forgery")).icon(() -> new ItemStack(Items.BRICKS)).build();
ALLOY_FORGE_SCREEN_HANDLER_TYPE = ScreenHandlerRegistry.registerSimple(id("alloy_forge"), AlloyForgeScreenHandler::new);

ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new FuelDataLoader());
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(FuelDataLoader.INSTANCE);

ModDataLoader.load(new ForgeRegistry.Loader());
ModDataLoader.load(ForgeRegistry.Loader.INSTANCE);
FORGE_CONTROLLER_BLOCK_ENTITY = ForgeControllerBlockEntity.Type.INSTANCE;

Registry.register(Registry.BLOCK_ENTITY_TYPE, id("forge_controller"), FORGE_CONTROLLER_BLOCK_ENTITY);
FluidStorage.SIDED.registerSelf(FORGE_CONTROLLER_BLOCK_ENTITY);

Registry.register(Registry.RECIPE_TYPE, AlloyForgeRecipe.Type.ID, AlloyForgeRecipe.Type.INSTANCE);
Registry.register(Registry.RECIPE_SERIALIZER, AlloyForgeRecipe.Type.ID, AlloyForgeRecipeSerializer.INSTANCE);

ALLOY_FORGERY_GROUP.initialize();
}

public static Identifier id(String path) {
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/wraith/alloyforgery/AlloyForgeryItemGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package wraith.alloyforgery;

import io.wispforest.owo.itemgroup.OwoItemGroup;
import io.wispforest.owo.itemgroup.gui.ItemGroupButton;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import wraith.alloyforgery.block.ForgeControllerBlock;
import wraith.alloyforgery.forges.ForgeRegistry;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class AlloyForgeryItemGroup extends OwoItemGroup {

private List<ItemStack> controllerCache = null;

protected AlloyForgeryItemGroup(Identifier id) {
super(id);
}

@Override
public ItemStack createIcon() {
return this.controllerCache.isEmpty() ? Items.BRICKS.getDefaultStack() : this.controllerCache.get(0);
}

@Override
public void appendStacks(DefaultedList<ItemStack> stacks) {
if (controllerCache == null) this.createControllerCache();
stacks.addAll(this.controllerCache);
}

private void createControllerCache() {
final var blockList = new ArrayList<>(ForgeRegistry.getControllerBlocks());
blockList.sort(Comparator.comparingInt(value -> ((ForgeControllerBlock) value).forgeDefinition.forgeTier()));

this.controllerCache = new ArrayList<>(blockList.size());
blockList.forEach(block -> this.controllerCache.add(block.asItem().getDefaultStack()));
}

@Override
protected void setup() {
this.addButton(ItemGroupButton.github("https://github.com/LordDeatHunter/Alloy-Forgery"));
this.addButton(ItemGroupButton.curseforge("https://www.curseforge.com/minecraft/mc-mods/alloy-forgery"));
this.addButton(ItemGroupButton.modrinth("https://modrinth.com/mod/alloy-forgery"));
this.addButton(ItemGroupButton.discord("https://discord.gg/Pa5wDVm8Xv"));
}
}
63 changes: 31 additions & 32 deletions src/main/java/wraith/alloyforgery/block/ForgeControllerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
Expand Down Expand Up @@ -44,43 +43,26 @@ public ForgeControllerBlock(ForgeDefinition forgeDefinition) {
this.setDefaultState(this.getStateManager().getDefaultState().with(LIT, false));
}

@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(LIT, FACING);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return world.isClient ? null : checkType(type, AlloyForgery.FORGE_CONTROLLER_BLOCK_ENTITY, (world1, pos, state1, blockEntity) -> blockEntity.tick());
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient) {
final var playerStack = player.getStackInHand(hand);

final var fuelDefinition = ForgeFuelRegistry.getFuelForItem(playerStack.getItem());
final var controller = (ForgeControllerBlockEntity) world.getBlockEntity(pos);
if (!(world.getBlockEntity(pos) instanceof ForgeControllerBlockEntity controller)) return ActionResult.PASS;

if (fuelDefinition.hasReturnType() && controller.canAddFuel(fuelDefinition.fuel())) {
if (!player.getAbilities().creativeMode)
if (!player.getAbilities().creativeMode) {
player.setStackInHand(hand, new ItemStack(fuelDefinition.returnType()));
}
controller.addFuel(fuelDefinition.fuel());
} else {

if (!controller.verifyMultiblock()) {
player.sendMessage(new TranslatableText("message.alloy_forgery.invalid_multiblock").formatted(Formatting.GRAY), true);
return ActionResult.SUCCESS;
}

NamedScreenHandlerFactory screenHandlerFactory = state.createScreenHandlerFactory(world, pos);

final var screenHandlerFactory = state.createScreenHandlerFactory(world, pos);
if (screenHandlerFactory != null) {
player.openHandledScreen(screenHandlerFactory);
}
Expand All @@ -91,18 +73,13 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
return ActionResult.SUCCESS;
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite());
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
final var forgeController = (ForgeControllerBlockEntity) world.getBlockEntity(pos);
ItemScatterer.spawn(world, pos, forgeController);
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), forgeController.getFuelStack());
if (world.getBlockEntity(pos) instanceof ForgeControllerBlockEntity forgeController) {
ItemScatterer.spawn(world, pos, forgeController);
ItemScatterer.spawn(world, pos.getX(), pos.getY(), pos.getZ(), forgeController.getFuelStack());
}
super.onStateReplaced(state, world, pos, newState, moved);
}
}
Expand All @@ -128,9 +105,31 @@ public void randomDisplayTick(BlockState state, World world, BlockPos pos, Rando
}
}

@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(LIT, FACING);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return world.isClient ? null : checkType(type, AlloyForgery.FORGE_CONTROLLER_BLOCK_ENTITY, (world1, pos, state1, blockEntity) -> blockEntity.tick());
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite());
}

@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
final var controller = (ForgeControllerBlockEntity) world.getBlockEntity(pos);
if (!(world.getBlockEntity(pos) instanceof ForgeControllerBlockEntity controller)) return 0;
return controller.getCurrentSmeltTime() == 0 ? 0 : Math.max(1, Math.round(controller.getSmeltProgress() * 0.46875f));
}

Expand Down
Loading

0 comments on commit 9a75033

Please sign in to comment.