Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.16.x / 1.17.x - Make Screens and Addons support the IGuiEventListener system #92

Draft
wants to merge 5 commits into
base: 1.16
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,30 @@

import com.hrznstudio.titanium._impl.test.TwentyFourTestBlock;
import com.hrznstudio.titanium.annotation.Save;
import com.hrznstudio.titanium.api.IFactory;
import com.hrznstudio.titanium.api.IItemStackQuery;
import com.hrznstudio.titanium.api.client.IScreenAddon;
import com.hrznstudio.titanium.block.tile.PoweredTile;
import com.hrznstudio.titanium.client.screen.addon.BasicScreenAddon;
import com.hrznstudio.titanium.client.screen.addon.EnergyBarScreenAddon;
import com.hrznstudio.titanium.client.screen.addon.WidgetScreenAddon;
import com.hrznstudio.titanium.component.inventory.InventoryComponent;
import com.hrznstudio.titanium.component.progress.ProgressBarComponent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.widget.SoundSlider;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.fml.client.gui.widget.Slider;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;

public class TwentyFourTestTile extends PoweredTile<TwentyFourTestTile> implements ITickableTileEntity {
@Save
Expand All @@ -35,18 +47,22 @@ public class TwentyFourTestTile extends PoweredTile<TwentyFourTestTile> implemen
public TwentyFourTestTile() {
super(TwentyFourTestBlock.TEST);

this.addInventory(first = new InventoryComponent<TwentyFourTestTile>("test", -120, 20, 1)
this.addInventory(first = new InventoryComponent<TwentyFourTestTile>("test", 80, 20, 1)
.setComponentHarness(this)
.setInputFilter(IItemStackQuery.ANYTHING.toSlotFilter()));
this.addInventory(second = new InventoryComponent<TwentyFourTestTile>("test2", 80, 30, 1)
this.addInventory(second = new InventoryComponent<TwentyFourTestTile>("test2", 80, 40, 1)
.setComponentHarness(this)
.setInputFilter(IItemStackQuery.ANYTHING.toSlotFilter()));
this.addProgressBar(bar = new ProgressBarComponent<TwentyFourTestTile>(20, 20, 500)
this.addProgressBar(bar = new ProgressBarComponent<TwentyFourTestTile>(110, 20, 500)
.setCanIncrease(componentHarness -> true)
.setOnFinishWork(() -> System.out.println("WOWOOW")));
this.addInventory(third = new InventoryComponent<TwentyFourTestTile>("test3", 180, 30, 1)
this.addInventory(third = new InventoryComponent<TwentyFourTestTile>("test3", 80, 60, 1)
.setComponentHarness(this)
.setInputFilter(IItemStackQuery.ANYTHING.toSlotFilter()));
this.addGuiAddonFactory(() -> new WidgetScreenAddon(30, 185, new SoundSlider(Minecraft.getInstance(), 0, 0, SoundCategory.HOSTILE, 120)));
TextFieldWidget widget = new TextFieldWidget(Minecraft.getInstance().fontRenderer, 0, 0, 120, 20, new StringTextComponent(""));
widget.setText("This is a Text Widget");
this.addGuiAddonFactory(() -> new WidgetScreenAddon(30, -25, widget));
}

@Override
Expand All @@ -65,6 +81,19 @@ public void tick() {
}
}

@Nonnull
@Override
public List<IFactory<? extends IScreenAddon>> getScreenAddons() {
List<IFactory<? extends IScreenAddon>> addons = super.getScreenAddons();
for (IFactory<? extends IScreenAddon> addon : addons) {
if (addon.create() instanceof EnergyBarScreenAddon) {
addons.remove(addon);
addons.add(() -> new EnergyBarScreenAddon(50, 20, this.getEnergyStorage()));
}
}
return addons;
}

@Override
@Nonnull
public TwentyFourTestTile getSelf() {
Expand Down
Loading