Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Added biome overlay forcing,
Browse files Browse the repository at this point in the history
Also added righthandside tabs.
  • Loading branch information
MrJake222 committed Feb 1, 2021
1 parent f4233c4 commit 42504d7
Show file tree
Hide file tree
Showing 39 changed files with 1,053 additions and 134 deletions.
65 changes: 64 additions & 1 deletion src/main/java/mrjake/aunis/config/AunisConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package mrjake.aunis.config;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import mrjake.aunis.renderer.biomes.BiomeOverlayEnum;
import mrjake.aunis.util.ItemMetaPair;
import net.minecraft.block.state.IBlockState;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.config.Config;
Expand Down Expand Up @@ -101,7 +105,7 @@ public boolean canKawooshDestroyBlock(IBlockState state) {

// ---------------------------------------------------------------------------------------
// Jungle biomes
@Name("Biomes in which blocks should be mossy")
@Name("Biomes in which Stargates should be mossy")
@Comment({
"Format: \"modid:biomename\", for example: ",
"\"minecraft:dark_forest\"",
Expand All @@ -118,6 +122,63 @@ public boolean isJungleBiome(Biome biome) {

return cachedJungleBiomes.contains(biome);
}


// ---------------------------------------------------------------------------------------
// Biome overlay override blocks

@Name("Biome overlay override blocks")
@SuppressWarnings("serial")
@Comment({
"Format: \"modid:blockid[:meta]\", for example: ",
"\"minecraft:wool:7\"",
"\"minecraft:stone\""
})
public Map<String, String[]> biomeOverrideBlocks = new HashMap<String, String[]>() {
{
put(BiomeOverlayEnum.NORMAL.toString(), new String[] {"minecraft:stone"});
put(BiomeOverlayEnum.FROST.toString(), new String[] {"minecraft:ice"});
put(BiomeOverlayEnum.MOSSY.toString(), new String[] {"minecraft:vine"});
put(BiomeOverlayEnum.AGED.toString(), new String[] {"minecraft:cobblestone"});
put(BiomeOverlayEnum.SOOTY.toString(), new String[] {"minecraft:coal_block"});
}
};

private Map<BiomeOverlayEnum, List<ItemMetaPair>> cachedBiomeOverrideBlocks = null;
private Map<ItemMetaPair, BiomeOverlayEnum> cachedBiomeOverrideBlocksReverse = null;

private void genBiomeOverrideCache() {
cachedBiomeOverrideBlocks = new HashMap<>();
cachedBiomeOverrideBlocksReverse = new HashMap<>();

for (Map.Entry<String, String[]> entry : biomeOverrideBlocks.entrySet()) {
List<ItemMetaPair> parsedList = ItemMetaParser.parseConfig(entry.getValue());
BiomeOverlayEnum biomeOverlay = BiomeOverlayEnum.fromString(entry.getKey());

cachedBiomeOverrideBlocks.put(biomeOverlay, parsedList);

for (ItemMetaPair stack : parsedList) {
cachedBiomeOverrideBlocksReverse.put(stack, biomeOverlay);
}
}
}

public Map<BiomeOverlayEnum, List<ItemMetaPair>> getBiomeOverrideBlocks() {
if (cachedBiomeOverrideBlocks == null) {
genBiomeOverrideCache();
}

return cachedBiomeOverrideBlocks;
}

public Map<ItemMetaPair, BiomeOverlayEnum> getBiomeOverrideItemMetaPairs() {
if (cachedBiomeOverrideBlocksReverse == null) {
genBiomeOverrideCache();
}

return cachedBiomeOverrideBlocksReverse;
}

}

public static class PowerConfig {
Expand Down Expand Up @@ -300,5 +361,7 @@ public static class WorldGenConfig {
public static void resetCache() {
stargateConfig.cachedInvincibleBlocks = null;
stargateConfig.cachedJungleBiomes = null;
stargateConfig.cachedBiomeOverrideBlocks = null;
stargateConfig.cachedBiomeOverrideBlocksReverse = null;
}
}
64 changes: 64 additions & 0 deletions src/main/java/mrjake/aunis/config/ItemMetaParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package mrjake.aunis.config;

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

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import mrjake.aunis.util.ItemMetaPair;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;

public class ItemMetaParser {

/**
* Parses array of configured items/blocks. For format see {@link ItemMetaParser#getBlockStateFromString(String)}
*
* @param config Array of single lines
* @return List of {@link IBlockState}s or empty list.
*/
@Nonnull
static List<ItemMetaPair> parseConfig(String[] config) {
List<ItemMetaPair> list = new ArrayList<>();

for (String line : config) {
ItemMetaPair stack = getItemMetaPairFromString(line);

if(stack != null) {
list.add(stack);
}
}

return list;
}

/**
* Parses single line of the config.
*
* @param line Consists of modid:blockid[:meta]
* @return {@link IBlockState} when valid block, {@code null} otherwise.
*/
@Nullable
static ItemMetaPair getItemMetaPairFromString(String line) {
String[] parts = line.trim().split(":", 3);

Item item = Item.REGISTRY.getObject(new ResourceLocation(parts[0], parts[1]));

if (item != null) {
if (parts.length == 2 || parts[2].equals("*"))
return new ItemMetaPair(item, 0);

try {
return new ItemMetaPair(item, Integer.parseInt(parts[2]));
}

catch (NumberFormatException e) {
return null;
}
}

return null;
}
}
19 changes: 16 additions & 3 deletions src/main/java/mrjake/aunis/gui/container/BeamerContainerGui.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package mrjake.aunis.gui.container;

import java.awt.Rectangle;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import mrjake.aunis.Aunis;
import mrjake.aunis.beamer.BeamerModeEnum;
Expand All @@ -13,6 +15,8 @@
import mrjake.aunis.gui.element.FluidTankElement;
import mrjake.aunis.gui.element.Tab;
import mrjake.aunis.gui.element.TabRedstone;
import mrjake.aunis.gui.element.TabSideEnum;
import mrjake.aunis.gui.element.TabbedContainerInterface;
import mrjake.aunis.packet.AunisPacketHandler;
import mrjake.aunis.packet.BeamerChangeRoleToServer;
import mrjake.aunis.stargate.power.StargateAbstractEnergyStorage;
Expand All @@ -25,7 +29,7 @@
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.items.SlotItemHandler;

public class BeamerContainerGui extends GuiContainer {
public class BeamerContainerGui extends GuiContainer implements TabbedContainerInterface {

private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation(Aunis.ModID, "textures/gui/container_beamer.png");

Expand Down Expand Up @@ -183,16 +187,18 @@ public void initGui() {
.setRedstoneModeGetter(() -> container.beamerTile.getRedstoneMode())
.setBeamerModeGetter(() -> container.beamerTile.getMode())
.setBlockPos(container.pos)
.setGuiSize(xSize, ySize)
.setGuiPosition(guiLeft, guiTop)
.setTabPosition(-21, 2)
.setOpenPosition(-128)
.setOpenX(-128)
.setTabSize(128, 80)
.setTabTitle(I18n.format("gui.beamer.activation"))
.setTabSide(TabSideEnum.LEFT)
.setTexture(BACKGROUND_TEXTURE, 256)
.setBackgroundTextureLocation(0, 176)
.setIconRenderPos(1, 7)
.setIconSize(20, 18)
.setIconTextureLocation(128, 0).build();
.setIconTextureLocation(128, 176).build();

updated = false;

Expand Down Expand Up @@ -373,6 +379,13 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
tabRedstone.mouseClicked(mouseX, mouseY, mouseButton);
}

@Override
public List<Rectangle> getGuiExtraAreas() {
return tabs.stream()
.map(tab -> tab.getArea())
.collect(Collectors.toList());
}

private class BeamerSlot extends SlotItemHandler {

public BeamerSlot(SlotItemHandler slot) {
Expand Down
35 changes: 32 additions & 3 deletions src/main/java/mrjake/aunis/gui/container/DHDContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,49 @@
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class DHDContainer extends Container {
public class DHDContainer extends Container implements OpenTabHolderInterface {

public Slot slotCrystal;
public FluidTank tankNaquadah;
public DHDTile dhdTile;

private BlockPos pos;
private int tankLastAmount;
private ReactorStateEnum lastReactorState;
private boolean lastLinked;
private int openTabId = -1;

@Override
public int getOpenTabId() {
return openTabId;
}

@Override
public void setOpenTabId(int tabId) {
openTabId = tabId;
}

public DHDContainer(IInventory playerInventory, World world, int x, int y, int z) {
pos = new BlockPos(x, y, z);
dhdTile = (DHDTile) world.getTileEntity(pos);
IItemHandler itemHandler = dhdTile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

// Crystal slot (index 0)
slotCrystal = new SlotItemHandler(itemHandler, 0, 80, 35);
addSlotToContainer(slotCrystal);

tankNaquadah = (FluidTank) dhdTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);

// Upgrades (index 1-4)
for (int row=0; row<2; row++) {
for (int col=0; col<2; col++) {
addSlotToContainer(new SlotItemHandler(itemHandler, row*2+col+1, 9+18*col, 18+18*row));
}
}

// Biome overlay slot (index 5)
addSlotToContainer(new SlotItemHandler(itemHandler, 5, 0, 0));

for (Slot slot : ContainerHelper.generatePlayerSlots(playerInventory, 86))
addSlotToContainer(slot);
}
Expand All @@ -63,7 +79,7 @@ public ItemStack transferStackInSlot(EntityPlayer player, int index) {
ItemStack stack = getSlot(index).getStack();

// Transfering from DHD to player's inventory
if (index < 5) {
if (index < 6) {
if (!mergeItemStack(stack, 5, inventorySlots.size(), false)) {
return ItemStack.EMPTY;
}
Expand Down Expand Up @@ -99,6 +115,19 @@ else if (DHDTile.SUPPORTED_UPGRADES.contains(stack.getItem()) && dhdTile.upgrade
}
}

// Biome override blocks
else if (openTabId == 0 && getSlot(5).isItemValid(stack)) {
if (!getSlot(5).getHasStack()) {
ItemStack stack1 = stack.copy();
stack1.setCount(1);

putStackInSlot(5, stack1);
stack.shrink(1);

return ItemStack.EMPTY;
}
}

return ItemStack.EMPTY;
}

Expand Down
Loading

0 comments on commit 42504d7

Please sign in to comment.