Skip to content

Commit

Permalink
Fixed some resource station issues and added livestock pen screen
Browse files Browse the repository at this point in the history
  • Loading branch information
rbasamoyai committed Jul 5, 2022
1 parent 1a9832e commit 9624b9a
Show file tree
Hide file tree
Showing 28 changed files with 348 additions and 86 deletions.
4 changes: 0 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
Current TODO:

- IT'S PORTIN' TIME!
- Fix stuff

- Bounds rendering for configurable blocks

- Formulate an economy
- Resource gathering
- Mob resource gathering
- Rancher
- Rancher screen
- Resource refining
- Metal smelting
- Sawyer
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ repositories {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.18.2-40.1.51'
minecraft 'net.minecraftforge:forge:1.18.2-40.1.54'
implementation fg.deobf('software.bernie.geckolib:geckolib-forge-1.18:3.0.27') // GeckoLib
}

Expand Down
3 changes: 2 additions & 1 deletion src/generated/resources/.cache/cache
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ d44ae39a75d1489fdf49d3f887b07fa0cdcfe8d7 assets/industrialwarfare/blockstates/ta
8e7ad0313e5c674015ca2568766c6f67fe069851 assets/industrialwarfare/blockstates/worker_support.json
6ab1ed2bc23776af0b0017150f94797ff3293979 assets/industrialwarfare/models/item/american_kepi.json
e0d699915b0a28d76628348c15b9a3b5ce0f319d assets/industrialwarfare/models/item/ammo_generic.json
18d6c5035bbd266c53dfee826ae74498c1b7f2a9 assets/industrialwarfare/models/item/animal_feed.json
19366433724d7ca5d9d24f251e79788e18bf5e6e assets/industrialwarfare/models/item/assembler_workstation.json
607f520ae1764b99ca448e6a07a1edfc7fecc8a8 assets/industrialwarfare/models/item/body_part.json
28fe6078f1bc9d6016e081c9618583f8fb12a795 assets/industrialwarfare/models/item/cartridge_case.json
Expand Down Expand Up @@ -61,7 +62,7 @@ dd0e34b4f66bd8b20a0432a377b04d5e66cda336 data/industrialwarfare/loot_tables/bloc
b70984139a51fbc8ea23564f57ad005b919b02fa data/industrialwarfare/loot_tables/blocks/tree_farm.json
072e6ae419a77caa4f5ef8781df2bbb2bace6b9a data/industrialwarfare/loot_tables/blocks/worker_support.json
c7ddee0b522855299a1682c5ee2b5df455947a9a data/industrialwarfare/recipes/part_iron_wire.json
01d60ec8f745ad354c78ba84aa0ae777ba5d6754 data/industrialwarfare/recipes/part_screw.json
994aa17082e4014b41457bf3f3e828fd77ff5ab5 data/industrialwarfare/recipes/part_screw.json
ad3e5145a88c2e7d2f35f1211b242e61ec730084 data/industrialwarfare/tags/blocks/can_plant_forestry.json
56196ce18ce9abf13cad6aa4ba17142a6cdbf360 data/industrialwarfare/tags/blocks/can_plant_fungus.json
83902db0bf4c0678a1637285fb34d1108bc60363 data/industrialwarfare/tags/blocks/can_plant_sapling.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "industrialwarfare:item/animal_feed"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"type": "industrialwarfare:normal_workstation_recipe",
"input": [
{
"item": "industrialwarfare:part_iron_wire"
"item": "minecraft:iron_nugget"
},
{
"item": "minecraft:iron_nugget"
"item": "industrialwarfare:part_iron_wire"
}
],
"output": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import rbasamoyai.industrialwarfare.client.screen.diplomacy.DiplomacyScreen;
import rbasamoyai.industrialwarfare.client.screen.editlabel.EditLabelScreen;
import rbasamoyai.industrialwarfare.client.screen.npc.NPCBaseScreen;
import rbasamoyai.industrialwarfare.client.screen.resourcestation.LivestockPenScreen;
import rbasamoyai.industrialwarfare.client.screen.resourcestation.ResourceStationScreen;
import rbasamoyai.industrialwarfare.client.screen.schedule.EditScheduleScreen;
import rbasamoyai.industrialwarfare.client.screen.taskscroll.TaskScrollScreen;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static void onClientSetup(FMLClientSetupEvent event) {
MenuScreens.register(MenuInit.TASK_SCROLL.get(), TaskScrollScreen::new);
MenuScreens.register(MenuInit.TASK_SCROLL_SHELF.get(), TaskScrollShelfScreen::new);
MenuScreens.register(MenuInit.WHISTLE.get(), WhistleScreen::new);
MenuScreens.register(MenuInit.LIVESTOCK_PEN.get(), null);
MenuScreens.register(MenuInit.LIVESTOCK_PEN.get(), LivestockPenScreen::new);

ForgeRegistries.ITEMS.forEach(i -> {
if (i instanceof FirearmItem) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package rbasamoyai.industrialwarfare.client.screen.resourcestation;

import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.client.gui.widget.ForgeSlider;
import rbasamoyai.industrialwarfare.IndustrialWarfare;
import rbasamoyai.industrialwarfare.client.screen.widgets.WidgetUtils;
import rbasamoyai.industrialwarfare.common.containers.resourcestation.LivestockPenMenu;
import rbasamoyai.industrialwarfare.core.network.IWNetwork;
import rbasamoyai.industrialwarfare.core.network.messages.ResourceStationMessages.SSyncLivestockCount;

public class LivestockPenScreen extends ResourceStationScreen<LivestockPenMenu> {

private static final int TOP_MENU_START_X = 7;
private static final int TOP_MENU_START_Y = 17;

private ForgeSlider countSlider;

public LivestockPenScreen(LivestockPenMenu menu, Inventory playerInv, Component title) {
super(menu, playerInv, title);
}

@Override
protected void init() {
super.init();
this.countSlider = this.addRenderableWidget(new ForgeSlider(
this.leftPos + TOP_MENU_START_X + 62,
this.topPos + TOP_MENU_START_Y + 30,
100, 20,
new TranslatableComponent("gui." + IndustrialWarfare.MOD_ID + ".livestock_pen.minimum_livestock"),
TextComponent.EMPTY,
2, 16,
this.menu.getMinimumLivestock(),
true));
WidgetUtils.setActiveAndVisible(this.countSlider, this.menu.getSelected() == 0);
}

@Override
public void containerTick() {
super.containerTick();

int tab = this.menu.getSelected();
WidgetUtils.setActiveAndVisible(this.countSlider, tab == 0);
if (tab == 0) {
int count = this.countSlider.getValueInt();
boolean flag = this.menu.getMinimumLivestock() != count;
if (flag) {
this.menu.setMinimumLivestock(count);
IWNetwork.CHANNEL.sendToServer(new SSyncLivestockCount(count));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import rbasamoyai.industrialwarfare.core.network.messages.ResourceStationMessages.SSelectTab;
import rbasamoyai.industrialwarfare.core.network.messages.ResourceStationMessages.SSetRunning;

public class ResourceStationScreen extends AbstractContainerScreen<ResourceStationMenu> {
public class ResourceStationScreen<T extends ResourceStationMenu> extends AbstractContainerScreen<T> {

private static final ResourceLocation RESOURCE_GATHERING_GUI = new ResourceLocation(IndustrialWarfare.MOD_ID, "textures/gui/workstations/resource_station.png");
private static final ResourceLocation TABS_LOCATION = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
Expand Down Expand Up @@ -85,7 +85,7 @@ public class ResourceStationScreen extends AbstractContainerScreen<ResourceStati
private Button startButton;
private ItemInputWidget addExtraStockWidget;

public ResourceStationScreen(ResourceStationMenu menu, Inventory playerInv, Component title) {
public ResourceStationScreen(T menu, Inventory playerInv, Component title) {
super(menu, playerInv, title);
this.imageHeight = 168;
this.inventoryLabelY = this.imageHeight - 94;
Expand All @@ -96,8 +96,8 @@ public ResourceStationScreen(ResourceStationMenu menu, Inventory playerInv, Comp
protected void init() {
super.init();

this.stopButton = this.addRenderableWidget(new Button(this.leftPos + TOP_MENU_START_X + 65, this.topPos + TOP_MENU_START_Y + 1, 80, 20, STOP_TEXT, b -> this.setRunning(b, false)));
this.startButton = this.addRenderableWidget(new Button(this.leftPos + TOP_MENU_START_X + 65, this.topPos + TOP_MENU_START_Y + 1, 80, 20, START_TEXT, b -> this.setRunning(b, true)));
this.stopButton = this.addRenderableWidget(new Button(this.leftPos + TOP_MENU_START_X + 72, this.topPos + TOP_MENU_START_Y + 1, 80, 20, STOP_TEXT, b -> this.setRunning(b, false)));
this.startButton = this.addRenderableWidget(new Button(this.leftPos + TOP_MENU_START_X + 72, this.topPos + TOP_MENU_START_Y + 1, 80, 20, START_TEXT, b -> this.setRunning(b, true)));
boolean running = this.menu.isRunning();
WidgetUtils.setActiveAndVisible(this.startButton, !running);
WidgetUtils.setActiveAndVisible(this.stopButton, running);
Expand Down Expand Up @@ -176,7 +176,7 @@ private void renderTabButton(PoseStack stack, int x, int y, ItemStack icon, int
this.itemRenderer.blitOffset = 0.0f;
}

private <T> void renderScrollList(PoseStack stack, List<T> list, Function<T, ItemStack> func) {
private <S> void renderScrollList(PoseStack stack, List<S> list, Function<S, ItemStack> func) {
blit(stack, this.leftPos + TOP_MENU_START_X, this.topPos + TOP_MENU_START_Y, TOP_MENU_REQUESTS_TEX_X, TOP_MENU_REQUESTS_TEX_Y, TOP_MENU_REQUESTS_WIDTH, TOP_MENU_REQUESTS_HEIGHT, TEX_WIDTH, TEX_HEIGHT);

int base = this.getBaseIndex(list);
Expand Down Expand Up @@ -234,7 +234,7 @@ protected void renderTooltip(PoseStack stack, int mouseX, int mouseY) {
}
}

private <T> void renderListTooltip(PoseStack stack, int mouseX, int mouseY, List<T> list, Function<T, ItemStack> func) {
private <S> void renderListTooltip(PoseStack stack, int mouseX, int mouseY, List<S> list, Function<S, ItemStack> func) {
int d0 = mouseX - this.leftPos;
int d1 = mouseY - this.topPos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ public BlockInteraction getInteraction(LivingEntity entity) {
return null;
}

for (Map.Entry<BlockPos, LivingEntity> entry : this.currentTasks.entrySet()) {
if (entry.getValue() == entity) {
this.posCache.remove(entry.getKey());
this.currentTasks.remove(entry.getKey());
break;
}
BlockPos workingPos = this.currentTasks.inverse().get(entity);
if (workingPos != null) {
this.posCache.remove(workingPos);
this.currentTasks.remove(workingPos);
}

if (this.posCache.isEmpty() && this.searchCooldown <= 0) {
Expand Down Expand Up @@ -207,11 +205,14 @@ private boolean canHarvest(BlockPos pos) {
}

private void plantSeeds(Level level, BlockPos pos, LivingEntity entity) {
ItemStack stack = entity.getOffhandItem();
Item item = stack.getItem();
if (stack.is(Tags.Items.SEEDS) && item instanceof BlockItem) {
level.setBlockAndUpdate(pos, ((BlockItem) item).getBlock().defaultBlockState());
stack.shrink(1);
for (InteractionHand hand : InteractionHand.values()) {
ItemStack stack = entity.getItemInHand(hand);
Item item = stack.getItem();
if (stack.is(Tags.Items.SEEDS) && item instanceof BlockItem) {
level.setBlockAndUpdate(pos, ((BlockItem) item).getBlock().defaultBlockState());
stack.shrink(1);
return;
}
}
}

Expand Down Expand Up @@ -289,10 +290,11 @@ public AABB getBoxForRenderingCurrentBounds(ItemStack stack) {
@Override public BlockPos startingCorner() { return this.startingCorner; }
@Override public BlockPos endingCorner() { return this.endingCorner; }

protected void purgeEntries() {
for (Map.Entry<BlockPos, LivingEntity> entry : this.currentTasks.entrySet()) {
private void purgeEntries() {
for (Iterator<Map.Entry<BlockPos, LivingEntity>> iter = this.currentTasks.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<BlockPos, LivingEntity> entry = iter.next();
if (entry.getValue().isDeadOrDying()) {
this.currentTasks.remove(entry.getKey());
iter.remove();
}
}
}
Expand Down
Loading

0 comments on commit 9624b9a

Please sign in to comment.