Skip to content

Commit

Permalink
Merge remote-tracking branch 'disastermoo/sluicedev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/resources/assets
  • Loading branch information
alcatrazEscapee committed Aug 19, 2019
2 parents e34f1ee + 23a7de5 commit b287eca
Show file tree
Hide file tree
Showing 19 changed files with 909 additions and 62 deletions.
34 changes: 34 additions & 0 deletions src/main/java/net/dries007/tfc/ConfigTFC.java
Expand Up @@ -201,6 +201,40 @@ public static class GeneralCFG
@Config.RangeInt(min = 1, max = 10_000)
public int richOreMetalAmount = 35;

@Config.Comment("The amount of times a chunk can be worked. Note: While sluices increase work by 1, Goldpan increase by 6.")
@Config.LangKey("config." + MOD_ID + ".general.maxWorkChunk")
@Config.RangeInt(min = 1, max = 10_000)
public int maxWorkChunk = 300;

@Config.Comment("The radius sluice works on chunks.")
@Config.LangKey("config." + MOD_ID + ".general.sluiceRadius")
@Config.RangeInt(min = 0, max = 10)
public int sluiceRadius = 1;

@Config.Comment("The amount of ticks a sluice uses to work.")
@Config.LangKey("config." + MOD_ID + ".general.sluiceTicks")
@Config.RangeInt(min = 20)
public int sluiceTicks = 100;

@Config.Comment("Chance that a sluice operation produce small ore.")
@Config.RangeDouble(min = 0, max = 1)
@Config.LangKey("config." + MOD_ID + ".general.sluiceOreChance")
public double sluiceOreChance = 0.05;

@Config.Comment("Chance that a sluice operation produce gems.")
@Config.RangeDouble(min = 0, max = 1)
@Config.LangKey("config." + MOD_ID + ".general.sluiceGemChance")
public double sluiceGemChance = 0.05;

@Config.Comment("Chance that a diamond is dropped when sluice produce gems.")
@Config.RangeDouble(min = 0, max = 1)
@Config.LangKey("config." + MOD_ID + ".general.sluiceDiamondGemChance")
public double sluiceDiamondGemChance = 0.01;

@Config.Comment("If true, limits for gold pan and sluice are ignored.")
@Config.LangKey("config." + MOD_ID + ".general.overworkChunk")
public boolean overworkChunk = false;

@Config.Comment({"If true, this will force the gamerule naturalRegeneration to be false. ", "Note: this DOES NOT AFFECT TFC's natural regeneration. If you set naturalRegeneration to true, then you will have both TFC regeneration and normal vanilla regeneration (which is much faster)"})
@Config.LangKey("config." + MOD_ID + ".general.forceNoVanillaNaturalRegeneration")
public boolean forceNoVanillaNaturalRegeneration = true;
Expand Down
40 changes: 35 additions & 5 deletions src/main/java/net/dries007/tfc/api/types/Ore.java
Expand Up @@ -23,43 +23,73 @@ public class Ore extends IForgeRegistryEntry.Impl<Ore>
private final boolean graded;
private final Metal metal;
private final boolean canMelt;
private final double chunkChance, panChance;

/**
* Creates a registry object for an ore type
*
* @param name The registry name of the ore
* @param metal The metal, or null if it's a non-metal ore
* @param canMelt If the metal can be melted directly from the ore
* @param chunkChance the chance a chunk contains this ore when gold panning.
* @param panChance the chance to drop this ore when gold panning
*/
public Ore(ResourceLocation name, @Nullable Metal metal, boolean canMelt)
public Ore(ResourceLocation name, @Nullable Metal metal, boolean canMelt, double chunkChance, double panChance)
{
this.graded = (metal != null);
this.metal = metal;
this.canMelt = canMelt;
this.chunkChance = chunkChance;
this.panChance = panChance;

setRegistryName(name);
}

public Ore(ResourceLocation name, @Nonnull ResourceLocation metal, boolean canMelt)
public Ore(ResourceLocation name, @Nonnull ResourceLocation metal, boolean canMelt, double chunkChance, double panChance)
{
this(name, TFCRegistries.METALS.getValue(metal), canMelt);
this(name, TFCRegistries.METALS.getValue(metal), canMelt, chunkChance, panChance);
}

public Ore(ResourceLocation name, @Nonnull ResourceLocation metal)
{
this(name, TFCRegistries.METALS.getValue(metal), true);
this(name, TFCRegistries.METALS.getValue(metal), true, 0, 0);
}

public Ore(ResourceLocation name, @Nonnull ResourceLocation metal, boolean canMelt)
{
this(name, TFCRegistries.METALS.getValue(metal), canMelt, 0, 0);
}

public Ore(ResourceLocation name, @Nonnull ResourceLocation metal, double chunkChance, double panChance)
{
this(name, TFCRegistries.METALS.getValue(metal), true, chunkChance, panChance);
}

public Ore(ResourceLocation name)
{
this(name, (Metal) null, false);
this(name, (Metal) null, false, 0, 0);
}

public boolean isGraded()
{
return graded;
}

public boolean canPan()
{
return chunkChance > 0;
}

public double getPanChance()
{
return panChance;
}

public double getChunkChance()
{
return chunkChance;
}

@Nullable
public Metal getMetal()
{
Expand Down
Expand Up @@ -236,6 +236,7 @@ public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack)
ClientRegistry.bindTileEntitySpecialRenderer(TEAnvilTFC.class, new TESRAnvil());
ClientRegistry.bindTileEntitySpecialRenderer(TELoom.class, new TESRLoom());
ClientRegistry.bindTileEntitySpecialRenderer(TECrucible.class, new TESRCrucible());
ClientRegistry.bindTileEntitySpecialRenderer(TESluice.class, new TESRSluice());
}

@SubscribeEvent
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/net/dries007/tfc/client/FluidSpriteCache.java
Expand Up @@ -14,23 +14,38 @@

public class FluidSpriteCache
{
private static final Map<Fluid, TextureAtlasSprite> CACHE = new HashMap<>();
private static final Map<Fluid, TextureAtlasSprite> CACHESTILL = new HashMap<>();
private static final Map<Fluid, TextureAtlasSprite> CACHEFLOWING = new HashMap<>();

public static TextureAtlasSprite getSprite(Fluid fluid)
public static TextureAtlasSprite getStillSprite(Fluid fluid)
{
TextureAtlasSprite sprite = CACHE.get(fluid);
TextureAtlasSprite sprite = CACHESTILL.get(fluid);

if (sprite == null)
{
sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluid.getStill().toString());
CACHE.put(fluid, sprite);
CACHESTILL.put(fluid, sprite);
}

return sprite;
}

public static TextureAtlasSprite getFlowingSprite(Fluid fluid)
{
TextureAtlasSprite sprite = CACHEFLOWING.get(fluid);

if (sprite == null)
{
sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluid.getFlowing().toString());
CACHEFLOWING.put(fluid, sprite);
}

return sprite;
}

public static void clear()
{
CACHE.clear();
CACHEFLOWING.clear();
CACHESTILL.clear();
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/dries007/tfc/client/gui/GuiBarrel.java
Expand Up @@ -158,7 +158,7 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
if (fillHeightPixels > 0)
{
Fluid fluid = fs.getFluid();
TextureAtlasSprite sprite = FluidSpriteCache.getSprite(fluid);
TextureAtlasSprite sprite = FluidSpriteCache.getStillSprite(fluid);

int positionX = guiLeft + 8;
int positionY = guiTop + 54;
Expand Down
Expand Up @@ -68,7 +68,7 @@ public void render(TEBarrel te, double x, double y, double z, float partialTicks
{
Fluid fluid = fluidStack.getFluid();

TextureAtlasSprite sprite = FluidSpriteCache.getSprite(fluid);
TextureAtlasSprite sprite = FluidSpriteCache.getStillSprite(fluid);

GlStateManager.enableAlpha();
GlStateManager.enableBlend();
Expand Down
Expand Up @@ -39,7 +39,7 @@ public void render(TECrucible te, double x, double y, double z, float partialTic
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);

TextureAtlasSprite sprite = FluidSpriteCache.getSprite(metalFluid);
TextureAtlasSprite sprite = FluidSpriteCache.getStillSprite(metalFluid);

GlStateManager.enableAlpha();
GlStateManager.enableBlend();
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/net/dries007/tfc/client/render/TESRSluice.java
@@ -0,0 +1,114 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.client.render;

import org.lwjgl.opengl.GL11;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.Fluid;

import net.dries007.tfc.client.FluidSpriteCache;
import net.dries007.tfc.objects.te.TESluice;

public class TESRSluice extends TileEntitySpecialRenderer<TESluice>
{
@Override
public void render(TESluice te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
{
Fluid flowing = te.getFlowingFluid();
if (flowing == null) return;

GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);

EnumFacing facing = te.getBlockFacing();
//noinspection ConstantConditions
switch (facing)
{
case WEST:
GlStateManager.translate(0, 0, 1);
GlStateManager.rotate(90F, 0, 1, 0);
break;
case SOUTH:
GlStateManager.translate(1, 0, 1);
GlStateManager.rotate(180F, 0, 1, 0);
break;
case EAST:
GlStateManager.translate(1, 0, 0);
GlStateManager.rotate(270F, 0, 1, 0);
break;
default:
}


TextureAtlasSprite sprite = FluidSpriteCache.getFlowingSprite(flowing);

GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);

int color = flowing.getColor();

float r = ((color >> 16) & 0xFF) / 255F;
float g = ((color >> 8) & 0xFF) / 255F;
float b = (color & 0xFF) / 255F;
float a = ((color >> 24) & 0xFF) / 255F;

GlStateManager.color(r, g, b, a);

rendererDispatcher.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);

BufferBuilder buffer = Tessellator.getInstance().getBuffer();

//Top
buffer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION_TEX_NORMAL);

buffer.pos(0.05D, 1.033D, 0).tex(sprite.getMinU(), sprite.getMinV()).normal(0, 0, 1).endVertex();
buffer.pos(0.05D, -0.15D, 2.45D).tex(sprite.getMinU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();
buffer.pos(0.95D, -0.15D, 2.45D).tex(sprite.getMaxU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();
buffer.pos(0.95D, 1.033D, 0).tex(sprite.getMaxU(), sprite.getMinV()).normal(0, 0, 1).endVertex();

Tessellator.getInstance().draw();

//Bottom
buffer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION_TEX_NORMAL);

buffer.pos(0.05D, 0.833D, 0).tex(sprite.getMinU(), sprite.getMinV()).normal(0, 0, 1).endVertex();
buffer.pos(0.05D, -0.3D, 2.45D).tex(sprite.getMinU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();
buffer.pos(0.95D, -0.3D, 2.45D).tex(sprite.getMaxU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();
buffer.pos(0.95D, 0.833D, 0).tex(sprite.getMaxU(), sprite.getMinV()).normal(0, 0, 1).endVertex();

Tessellator.getInstance().draw();

//Left
buffer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION_TEX_NORMAL);

buffer.pos(0.05D, -0.15D, 2.45D).tex(sprite.getMinU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();
buffer.pos(0.05D, 1.033D, 0).tex(sprite.getMinU(), sprite.getMinV()).normal(0, 0, 1).endVertex();
buffer.pos(0.05D, 0.833D, 0).tex(sprite.getMaxU(), sprite.getMinV()).normal(0, 0, 1).endVertex();
buffer.pos(0.05D, -0.3D, 2.45D).tex(sprite.getMaxU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();

Tessellator.getInstance().draw();

//Right
buffer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION_TEX_NORMAL);

buffer.pos(0.95D, 1.033D, 0).tex(sprite.getMinU(), sprite.getMinV()).normal(0, 0, 1).endVertex();
buffer.pos(0.95D, -0.15D, 2.45D).tex(sprite.getMinU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();
buffer.pos(0.95D, -0.3D, 2.45D).tex(sprite.getMaxU(), sprite.getMaxV()).normal(0, 0, 1).endVertex();
buffer.pos(0.95D, 0.833D, 0).tex(sprite.getMaxU(), sprite.getMinV()).normal(0, 0, 1).endVertex();

Tessellator.getInstance().draw();

GlStateManager.popMatrix();
}
}
10 changes: 9 additions & 1 deletion src/main/java/net/dries007/tfc/command/CommandFindVeins.java
Expand Up @@ -7,18 +7,24 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import com.google.common.collect.ImmutableSet;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.text.TextComponentString;

import net.dries007.tfc.api.types.Ore;
import net.dries007.tfc.util.Helpers;
import net.dries007.tfc.world.classic.worldgen.WorldGenOreVeins;
import net.dries007.tfc.world.classic.worldgen.vein.Vein;
import net.dries007.tfc.world.classic.worldgen.vein.VeinRegistry;
Expand All @@ -38,7 +44,7 @@ public String getName()
@Nonnull
public String getUsage(ICommandSender sender)
{
return "/findveins [all|<vein name>] <radius> -> Finds all instances of a specific vein, or all veins within a certian chunk radius";
return "/findveins [all|<vein name>] <radius> -> Finds all instances of a specific vein, or all veins within a certain chunk radius";
}

@Override
Expand All @@ -51,6 +57,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args

final int radius = parseInt(args[1], 1, 1000);
final List<Vein> veins = WorldGenOreVeins.getNearbyVeins(sender.getCommandSenderEntity().chunkCoordX, sender.getCommandSenderEntity().chunkCoordZ, sender.getEntityWorld().getSeed(), radius);
final Map<ChunkPos, Set<Ore>> map = Helpers.getChunkOres(sender.getEntityWorld(), sender.getCommandSenderEntity().chunkCoordX, sender.getCommandSenderEntity().chunkCoordZ, radius);
if (!args[0].equals("all"))
{
final VeinType type = VeinRegistry.INSTANCE.getVein(args[0]);
Expand All @@ -61,6 +68,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
// Search for veins matching type
veins.removeIf(x -> x.type != type);
}
veins.removeIf(x -> !map.getOrDefault(new ChunkPos(x.pos), ImmutableSet.of()).contains(x.type.ore)); //Check if the vein generated
veins.forEach(x -> sender.sendMessage(new TextComponentString("> Vein: " + x.type + " at " + x.pos)));
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/dries007/tfc/objects/blocks/BlocksTFC.java
Expand Up @@ -286,6 +286,7 @@ public static void registerBlocks(RegistryEvent.Register<Block> event)
inventoryItemBlocks.add(new ItemBlockTFC(register(r, "bellows", new BlockBellows(), CT_MISC)));
inventoryItemBlocks.add(new ItemBlockTFC(register(r, "bloomery", new BlockBloomery(), CT_MISC)));
inventoryItemBlocks.add(new ItemBlockTFC(register(r, "nest_box", new BlockNestBox(), CT_MISC)));
inventoryItemBlocks.add(new ItemBlockSluice(register(r, "sluice", new BlockSluice(), CT_MISC)));

normalItemBlocks.add(new ItemBlockTFC(register(r, "sea_ice", new BlockIceTFC(FluidsTFC.SALT_WATER.get()), CT_MISC)));

Expand Down Expand Up @@ -632,6 +633,7 @@ public static void registerBlocks(RegistryEvent.Register<Block> event)
register(TEMetalSheet.class, "metal_sheet");
register(TEQuern.class, "quern");
register(TELargeVessel.class, "large_vessel");
register(TESluice.class, "sluice");
}

public static boolean isWater(IBlockState current)
Expand Down

0 comments on commit b287eca

Please sign in to comment.