Commit f1a5f40e authored by primetoxinz's avatar primetoxinz

Work on HCStrata

parent fea9a29a
......@@ -38,12 +38,14 @@ repositories {
maven { url 'http://dvs1.progwml6.com/files/maven' }
maven { url "http://maven.amadornes.com/" }
maven { url "http://www.ryanliptak.com/maven/" }
maven { url "http://maven.tterrag.com" }
mavenCentral()
}
dependencies {
deobfCompile "mezz.jei:jei_1.12.2:4.8.3.128"
deobfCompile "applecore:AppleCore:1.12.2-2.2.2:api"
deobfCompile "team.chisel.ctm:CTM:MC1.12-0.2.3.9"
}
jar {
......
/*
* Copyright (c) 2015, 2016, 2017 Adrian Siekierka
*
* This file is part of Charset.
*
* Charset is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Charset is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Charset. If not, see <http://www.gnu.org/licenses/>.
*/
package betterwithmods.client.model.render;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import java.awt.image.BufferedImage;
import java.util.function.Function;
public abstract class PixelOperationSprite extends TextureAtlasSprite {
public static class Multiply extends PixelOperationSprite {
private final int color;
public Multiply(String entry, ResourceLocation location, int color) {
super(entry, location);
this.color = color;
}
@Override
public int apply(int x, int y, int value) {
return RenderUtils.multiplyColor(value, color);
}
}
private final ResourceLocation location;
protected PixelOperationSprite(String entry, ResourceLocation location) {
super(entry);
this.location = location;
}
public abstract int apply(int x, int y, int value);
@Override
public boolean hasCustomLoader(IResourceManager manager, ResourceLocation location) {
return true;
}
@Override
public boolean load(IResourceManager manager, ResourceLocation loc, Function<ResourceLocation, TextureAtlasSprite> getter) {
BufferedImage image = RenderUtils.getTextureImage(location);
if (image == null) {
return false;
}
setIconWidth(image.getWidth());
setIconHeight(image.getHeight());
int[][] pixels = new int[Minecraft.getMinecraft().gameSettings.mipmapLevels + 1][];
pixels[0] = new int[image.getWidth() * image.getHeight()];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels[0], 0, image.getWidth());
for (int i = 0; i < pixels[0].length; i++) {
pixels[0][i] = apply(i % image.getWidth(), i / image.getWidth(), pixels[0][i]);
}
this.clearFramesTextureData();
this.framesTextureData.add(pixels);
return false;
}
}
\ No newline at end of file
......@@ -5,21 +5,28 @@ import betterwithmods.client.model.filters.*;
import betterwithmods.common.BWMBlocks;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.IResource;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.model.ModelLoader;
import org.lwjgl.opengl.GL11;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.function.Function;
public class RenderUtils {
protected static final Minecraft minecraft = Minecraft.getMinecraft();
public static final Function<ResourceLocation, TextureAtlasSprite> textureGetter = ModelLoader.defaultTextureGetter();
private static HashMap<String, ModelWithResource> filterLocations = new HashMap<>();
private static RenderItem renderItem;
......@@ -207,4 +214,34 @@ public class RenderUtils {
String domain = iconLoc.substring(0, iconLoc.indexOf(':')), resource = iconLoc.substring(iconLoc.indexOf(':') + 1, iconLoc.length());
return new ResourceLocation(domain, "textures/" + resource + ".png");
}
public static int multiplyColor(int src, int dst) {
int out = 0;
for (int i = 0; i < 32; i += 8) {
out |= ((((src >> i) & 0xFF) * ((dst >> i) & 0xFF) / 0xFF) & 0xFF) << i;
}
return out;
}
public static BakedQuad recolorQuad(BakedQuad quad, int color) {
int c = DefaultVertexFormats.BLOCK.getColorOffset() / 4;
int v = DefaultVertexFormats.BLOCK.getIntegerSize() / 4;
int[] vertexData = quad.getVertexData();
for (int i = 0; i < 4; i++) {
vertexData[v * i + c] = RenderUtils.multiplyColor(vertexData[v * i + c], color);
}
return quad;
}
public static BufferedImage getTextureImage(ResourceLocation location) {
try {
ResourceLocation pngLocation = new ResourceLocation(location.getResourceDomain(), String.format("%s/%s%s", "textures", location.getResourcePath(), ".png"));
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(pngLocation);
return TextureUtil.readBufferedImage(resource.getInputStream());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
......@@ -161,7 +161,7 @@ public class BWRegistry {
BlockPos pos = source.getBlockPos().offset(facing);
EntityMiningCharge miningCharge = new EntityMiningCharge(worldIn, pos.getX() + 0.5F, pos.getY(),
pos.getZ() + 0.5F, null, facing);
miningCharge.setNoGravity(false);
miningCharge.setNoGravity(facing != EnumFacing.DOWN);
worldIn.spawnEntity(miningCharge);
worldIn.playSound(null, miningCharge.posX, miningCharge.posY, miningCharge.posZ,
SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
......
......@@ -9,6 +9,7 @@ import betterwithmods.module.hardcore.creatures.*;
import betterwithmods.module.hardcore.needs.*;
import betterwithmods.module.hardcore.needs.hunger.HCHunger;
import betterwithmods.module.hardcore.world.*;
import betterwithmods.module.hardcore.world.strata.HCStrata;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
/**
......@@ -66,6 +67,7 @@ public class Hardcore extends CompatModule {
registerFeature(new HCDeadweight());
// registerFeature(new HCSquid());
registerFeature(new HCEnchanting());
registerFeature(new HCStrata());
this.load();
}
......
package betterwithmods.module.hardcore.world.strata;
import betterwithmods.module.Feature;
import betterwithmods.util.item.ToolsManager;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class HCStrata extends Feature {
public static float[] STRATA_SPEEDS;
@Override
public void setupConfig() {
STRATA_SPEEDS = new float[]{(float) loadPropDouble("Light Strata","Speed for Light Strata", 1),
(float) loadPropDouble("Medium Strata","Speed for Medium Strata", 0.5f),
(float) loadPropDouble("Dark Strata","Speed for Dark Strata", 0.05f)
};
}
@Override
public String getFeatureDescription() {
return "Changes how hard stone and ores are based on how deep down they are.";
}
public static boolean shouldStratify(World world, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
return state.getMaterial() == Material.ROCK;
}
public static int getStratification(int y, int topY) {
if(y >= (topY-10))
return 0;
if(y >= (topY-30))
return 1;
return 2;
}
@SubscribeEvent
public void getHarvest(PlayerEvent.BreakSpeed event) {
World world = event.getEntityPlayer().getEntityWorld();
BlockPos pos = event.getPos();
if(shouldStratify(world,pos)) {
float scale = ToolsManager.getSpeed(event.getEntityPlayer().getHeldItemMainhand(), event.getState());
int strata = getStratification(pos.getY(),Math.min(world.getTopSolidOrLiquidBlock(pos).getY(), 70));
event.setNewSpeed(scale * STRATA_SPEEDS[strata] * 0.5f);
System.out.println(strata);
}
}
@Override
public boolean hasSubscriptions() {
return true;
}
@SubscribeEvent(priority = EventPriority.LOWEST)
@SideOnly(Side.CLIENT)
public static void addModels(ModelBakeEvent event) {
}
}
package betterwithmods.module.hardcore.world.strata;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import team.chisel.ctm.client.texture.ctx.OffsetProviderRegistry;
import team.chisel.ctm.client.texture.ctx.TextureContextPosition;
public class TextureContextWorld extends TextureContextPosition {
BlockPos top;
public TextureContextWorld(BlockPos pos, BlockPos top) {
super(pos);
this.top = top;
}
public BlockPos getTop() {
return top;
}
public TextureContextPosition applyOffset() {
this.top = top.add(OffsetProviderRegistry.INSTANCE.getOffset(Minecraft.getMinecraft().world, top));
return super.applyOffset();
}
@Override
public long getCompressedData() {
return 0L;
}
}
package betterwithmods.module.hardcore.world.strata;
import betterwithmods.client.model.render.RenderUtils;
import com.google.common.collect.Lists;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BakedQuadRetextured;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import team.chisel.ctm.api.texture.ITextureContext;
import team.chisel.ctm.api.util.TextureInfo;
import team.chisel.ctm.client.texture.ctx.TextureContextPosition;
import team.chisel.ctm.client.texture.render.AbstractTexture;
import javax.annotation.Nullable;
import java.util.List;
public class TextureStrata extends AbstractTexture<TextureTypeStrata> {
public TextureStrata(TextureTypeStrata type, TextureInfo info) {
super(type, info);
}
@Override
public List<BakedQuad> transformQuad(BakedQuad quad, @Nullable ITextureContext context, int quadGoal) {
if (context instanceof TextureContextPosition) {
TextureContextPosition c = (TextureContextPosition) context;
BlockPos pos = c.getPosition();
int strata = HCStrata.getStratification(pos.getY(), 50);
// if(y >= (topY-10))
// return 0;
// if(y >= (topY-30))
// return 1;
// return 2;
ResourceLocation[] textures = new ResourceLocation[]{new ResourceLocation("minecraft:blocks/cobblestone"), new ResourceLocation("minecraft:blocks/gray_concrete"), new ResourceLocation("minecraft:blocks/obsidian")};
return Lists.newArrayList(new BakedQuadRetextured(quad, RenderUtils.textureGetter.apply(textures[strata])));
}
return Lists.newArrayList(quad);
}
}
package betterwithmods.module.hardcore.world.strata;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import team.chisel.ctm.api.texture.ICTMTexture;
import team.chisel.ctm.api.texture.ITextureContext;
import team.chisel.ctm.api.texture.ITextureType;
import team.chisel.ctm.api.texture.TextureType;
import team.chisel.ctm.api.util.TextureInfo;
import team.chisel.ctm.client.texture.ctx.TextureContextPosition;
@TextureType("bwm_strata")
public class TextureTypeStrata implements ITextureType {
@Override
public TextureStrata makeTexture(TextureInfo info) {
return new TextureStrata(this, info);
}
@Override
public ITextureContext getBlockRenderContext(IBlockState state, IBlockAccess world, BlockPos pos, ICTMTexture<?> tex) {
return new TextureContextPosition(pos);
}
@Override
public ITextureContext getContextFromData(long data) {
return new TextureContextPosition(BlockPos.fromLong(data));
}
}
{
"ctm": {
"ctm_version": 1,
"type": "bwm_strata",
"layer": "SOLID",
"textures": [],
"extra": {
"light": 0
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment