Skip to content

Commit

Permalink
Chisel texture + chisel sound
Browse files Browse the repository at this point in the history
  • Loading branch information
minecreatr committed Aug 20, 2015
1 parent 8887914 commit f10f4df
Show file tree
Hide file tree
Showing 43 changed files with 118 additions and 56 deletions.
10 changes: 8 additions & 2 deletions src/main/java/team/chisel/Chisel.java
@@ -1,5 +1,9 @@
package team.chisel;

import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.ModelLoader;
import team.chisel.client.command.CommandTest;
import team.chisel.client.gui.ChiselGuiHandler;
import team.chisel.common.CarvableBlocks;
Expand Down Expand Up @@ -35,16 +39,17 @@ public class Chisel implements Reference {

public static ItemChisel itemChisel;

private static boolean debug = true;
public static final boolean debug = true;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
Variation.doStuff();
proxy.preInit();
CarvableBlocks.preInitBlocks();
itemChisel = new ItemChisel();
GameRegistry.registerItem(itemChisel, "itemChisel");
GameRegistry.addShapedRecipe(new ItemStack(itemChisel), " x", "s ", 'x', Items.iron_ingot, 's', Items.stick);
NetworkRegistry.INSTANCE.registerGuiHandler(this, new ChiselGuiHandler());
proxy.preInit();

}

Expand All @@ -53,6 +58,7 @@ public void init(FMLInitializationEvent event) {
proxy.init();
CarvableBlocks.initBlocks();
ClientCommandHandler.instance.registerCommand(new CommandTest());

}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/team/chisel/client/ClientProxy.java
@@ -1,5 +1,9 @@
package team.chisel.client;

import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import team.chisel.Chisel;
import team.chisel.client.handler.DebugHandler;
import team.chisel.client.render.NonCTMModelRegistry;
import team.chisel.client.render.ctm.CTMModelRegistry;
Expand All @@ -21,6 +25,7 @@ public class ClientProxy extends CommonProxy {

@Override
public void init() {

}

@Override
Expand All @@ -31,6 +36,8 @@ public boolean isClient() {
@Override
public void preInit() {

ModelLoader.setCustomModelResourceLocation(Chisel.itemChisel, 0, new ModelResourceLocation(MOD_ID + ":itemChisel", "inventory"));
//ModelBakery.addVariantName(Chisel.itemChisel, MOD_ID+":itemChisel");
MinecraftForge.EVENT_BUS.register(new CTMModelRegistry.BakedEventListener());
MinecraftForge.EVENT_BUS.register(new NonCTMModelRegistry.BakedEventListener());
MinecraftForge.EVENT_BUS.register(new TextureStitcher());
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/team/chisel/client/ClientUtil.java
@@ -0,0 +1,18 @@
package team.chisel.client;

import net.minecraft.client.Minecraft;
import net.minecraft.world.World;

import java.util.Random;

/**
* Client Utility stuff
*/
public class ClientUtil {

public static final Random rand = new Random();

public static void playSound(World world, int x, int y, int z, String sound) {
Minecraft.getMinecraft().theWorld.playSound(x + 0.5, y + 0.5, z + 0.5, sound, 0.3f + 0.7f * rand.nextFloat(), 0.6f + 0.4f * rand.nextFloat(), true);
}
}
4 changes: 2 additions & 2 deletions src/main/java/team/chisel/client/gui/GuiChisel.java
Expand Up @@ -104,8 +104,8 @@ protected void drawGuiContainerBackgroundLayer(float f, int mx, int my) {
// protected void actionPerformed(GuiButton button) {
// if (button.id == 0) {
// if (container.chisel != null && container.chisel.getItem() instanceof IAdvancedChisel) {
// IAdvancedChisel item = (IAdvancedChisel) container.chisel.getItem();
// currentMode = item.getNextMode(container.chisel, currentMode);
// IAdvancedChisel items = (IAdvancedChisel) container.chisel.getItem();
// currentMode = items.getNextMode(container.chisel, currentMode);
// PacketHandler.INSTANCE.sendToServer(new MessageChiselMode(currentMode));
// } else {
// currentMode = ChiselMode.next(currentMode);
Expand Down
70 changes: 36 additions & 34 deletions src/main/java/team/chisel/client/handler/DebugHandler.java
@@ -1,5 +1,6 @@
package team.chisel.client.handler;

import team.chisel.Chisel;
import team.chisel.client.render.IBlockResources;
import team.chisel.common.block.BlockCarvable;
import team.chisel.common.util.SubBlockUtil;
Expand Down Expand Up @@ -33,42 +34,43 @@ public class DebugHandler {

@SubscribeEvent
public void onDrawScreen(RenderGameOverlayEvent.Post event) {
if (!Minecraft.getMinecraft().gameSettings.advancedItemTooltips) {
return;
}
IBlockState state = getBlockStateLooking();
if (state == null) {
return;
}
List<String> text = new ArrayList<String>();
text.add(EnumChatFormatting.BLUE + "Block: " + EnumChatFormatting.GREEN + GameRegistry.findUniqueIdentifierFor(state.getBlock()).toString());
text.add(EnumChatFormatting.BLUE + "Meta: " + EnumChatFormatting.GREEN + state.getBlock().getMetaFromState(state));
text.add(EnumChatFormatting.BLUE + "State Class: " + EnumChatFormatting.GREEN + state.getClass().toString());
if (state.getBlock() instanceof BlockCarvable) {
BlockCarvable block = (BlockCarvable) state.getBlock();
PropertyVariation VARIATION = ((BlockCarvable) state.getBlock()).getType().getPropertyVariation();
IBlockResources r = SubBlockUtil.getResources(block, (Variation) state.getValue(VARIATION));
text.add(EnumChatFormatting.BLUE + "Type: " + EnumChatFormatting.GREEN + r.getType());
}
Minecraft mc = Minecraft.getMinecraft();
IBakedModel m = mc.getBlockRendererDispatcher().getModelFromBlockState(state, mc.theWorld, mc.objectMouseOver.getBlockPos());
if (m instanceof IFlexibleBakedModel.Wrapper) {
m = ReflectionHelper.getPrivateValue(IFlexibleBakedModel.Wrapper.class, (IFlexibleBakedModel.Wrapper) m, "parent");
}
text.add(EnumChatFormatting.BLUE + "Model Class: " + m.getClass());
for (IProperty p : (ImmutableSet<IProperty>) state.getProperties().keySet()) {
String s = p.getName() + ": ";
text.add(s + state.getValue(p));
}
if (Chisel.debug) {
if (!Minecraft.getMinecraft().gameSettings.advancedItemTooltips) {
return;
}
IBlockState state = getBlockStateLooking();
if (state == null) {
return;
}
List<String> text = new ArrayList<String>();
text.add(EnumChatFormatting.BLUE + "Block: " + EnumChatFormatting.GREEN + GameRegistry.findUniqueIdentifierFor(state.getBlock()).toString());
text.add(EnumChatFormatting.BLUE + "Meta: " + EnumChatFormatting.GREEN + state.getBlock().getMetaFromState(state));
text.add(EnumChatFormatting.BLUE + "State Class: " + EnumChatFormatting.GREEN + state.getClass().toString());
if (state.getBlock() instanceof BlockCarvable) {
BlockCarvable block = (BlockCarvable) state.getBlock();
PropertyVariation VARIATION = ((BlockCarvable) state.getBlock()).getType().getPropertyVariation();
IBlockResources r = SubBlockUtil.getResources(block, (Variation) state.getValue(VARIATION));
text.add(EnumChatFormatting.BLUE + "Type: " + EnumChatFormatting.GREEN + r.getType());
}
Minecraft mc = Minecraft.getMinecraft();
IBakedModel m = mc.getBlockRendererDispatcher().getModelFromBlockState(state, mc.theWorld, mc.objectMouseOver.getBlockPos());
if (m instanceof IFlexibleBakedModel.Wrapper) {
m = ReflectionHelper.getPrivateValue(IFlexibleBakedModel.Wrapper.class, (IFlexibleBakedModel.Wrapper) m, "parent");
}
text.add(EnumChatFormatting.BLUE + "Model Class: " + m.getClass());
for (IProperty p : (ImmutableSet<IProperty>) state.getProperties().keySet()) {
String s = p.getName() + ": ";
text.add(s + state.getValue(p));
}

int cur = 0;
for (String l : text) {
Minecraft.getMinecraft().fontRendererObj.drawString(l, 10, 10 + (cur * 10), 1);
cur++;
int cur = 0;
for (String l : text) {
Minecraft.getMinecraft().fontRendererObj.drawString(l, 10, 10 + (cur * 10), 1);
cur++;
}
GL11.glColor3f(1f, 1f, 1f);
Minecraft.getMinecraft().getTextureManager().bindTexture(Gui.icons);
}
GL11.glColor3f(1f, 1f, 1f);
Minecraft.getMinecraft().getTextureManager().bindTexture(Gui.icons);

}

private static IBlockState getBlockStateLooking() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/team/chisel/client/render/BlockResources.java
Expand Up @@ -232,17 +232,17 @@ protected static boolean isV4(String blockName, String variation) {
}

protected static boolean isR16(String blockName, String variation) {
String path = "/assets/" + MOD_ID.toLowerCase() + "/textures/blocks/" + blockName + "/" + variation + "-v9.png";
String path = "/assets/" + MOD_ID.toLowerCase() + "/textures/blocks/" + blockName + "/" + variation + "-r16.png";
return Chisel.class.getResource(path) != null;
}

protected static boolean isR9(String blockName, String variation) {
String path = "/assets/" + MOD_ID.toLowerCase() + "/textures/blocks/" + blockName + "/" + variation + "-v9.png";
String path = "/assets/" + MOD_ID.toLowerCase() + "/textures/blocks/" + blockName + "/" + variation + "-r9.png";
return Chisel.class.getResource(path) != null;
}

protected static boolean isR4(String blockName, String variation) {
String path = "/assets/" + MOD_ID.toLowerCase() + "/textures/blocks/" + blockName + "/" + variation + "-v9.png";
String path = "/assets/" + MOD_ID.toLowerCase() + "/textures/blocks/" + blockName + "/" + variation + "-r4.png";
return Chisel.class.getResource(path) != null;
}

Expand Down
Expand Up @@ -70,13 +70,13 @@ public static void registerInventory(CarvableBlocks block, int index) {
// throw new RuntimeException("Null block for index "+index+" and block "+block.getName());
// }
// if (Item.getItemFromBlock(block.getBlock(index))==null){
// throw new RuntimeException("null item");
// throw new RuntimeException("null items");
// }
//// Item item = Item.getItemFromBlock(block.getBlock(index));
//// ModelLoader.setCustomModelResourceLocation(item, -1, location);
//// Item items = Item.getItemFromBlock(block.getBlock(index));
//// ModelLoader.setCustomModelResourceLocation(items, -1, location);
//// int totalMeta = block.getVariants().length-(index*16);
//// for (int i=0;i<totalMeta;i++) {
//// ModelLoader.setCustomModelResourceLocation(item, i, location);
//// ModelLoader.setCustomModelResourceLocation(items, i, location);
//// }
// }

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/team/chisel/common/CarvableBlocks.java
Expand Up @@ -497,6 +497,12 @@ public String getOredictName() {
return "blockGold";
}

},
NULL("null"){
@Override
protected Variation[] createVariations(Variation.VariationCreator c) {
return new Variation[0];
}
};

protected String name;
Expand Down Expand Up @@ -622,6 +628,20 @@ public ItemStack getSmeltedItem(){
return null;
}

public String getSound(){
return MOD_ID+":chisel.fallback";
}

public static CarvableBlocks fromItemStack(ItemStack stack){
if (Block.getBlockFromItem(stack.getItem())!=null){
Block blockIn = Block.getBlockFromItem(stack.getItem());
if (blockIn instanceof BlockCarvable){
return ((BlockCarvable) blockIn).getType();
}
}
return NULL;
}

protected String[] getLore(String v) {
return new String[]{"chisel.lore." + getName() + "." + v + ".1"};
}
Expand All @@ -647,6 +667,9 @@ public String[] getRequiredMods() {

public static void preInitBlocks() {
for (CarvableBlocks b : values()) {
if (b==NULL){
continue;
}
if (!shouldBlockLoad(b)) {
continue;
}
Expand Down Expand Up @@ -680,6 +703,9 @@ public static void preInitBlocks() {
}
}
for (CarvableBlocks b : values()) {
if (b==NULL){
continue;
}
for (BlockCarvable block : b.instances) {
final ModelResourceLocation location;
location = new ModelResourceLocation(MOD_ID.toLowerCase() + ":" + block.getName(), "inventory");
Expand All @@ -696,6 +722,9 @@ public static void preInitBlocks() {

public static void initBlocks() {
for (CarvableBlocks b : values()) {
if (b==NULL){
continue;
}
for (BlockCarvable block : b.instances) {
if (block.getIndex() == 0 && b.getCrafting().length != 0) {
b.recipe = GameRegistry.addShapedRecipe(new ItemStack(block, b.getCraftingAmount(), 0), b.getCrafting());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/team/chisel/common/CommonProxy.java
Expand Up @@ -3,7 +3,7 @@
/**
* The Common Proxy
*/
public class CommonProxy {
public class CommonProxy implements Reference{

public void init() {

Expand Down
Expand Up @@ -15,7 +15,7 @@
import java.util.List;

/**
* Class for the item for the chisel block
* Class for the items for the chisel block
*
* @author minecreatr
*/
Expand Down
Expand Up @@ -4,6 +4,9 @@
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import team.chisel.client.ClientUtil;
import team.chisel.common.CarvableBlocks;

public class SlotChiselSelection extends Slot {

Expand Down Expand Up @@ -52,11 +55,11 @@ public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) {
selInventory.updateItems();


// if (player.worldObj.isRemote) {
// String sound = Carving.chisel.getVariationSound(crafted.getItem(), crafted.getItemDamage());
// GeneralClient.playChiselSound(player.worldObj, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ), sound);
// } else {
// container.playerInventory.player.addStat(Statistics.blocksChiseled, crafted.stackSize);
// }
if (player.worldObj.isRemote) {
String sound = CarvableBlocks.fromItemStack(crafted).getSound();
ClientUtil.playSound(player.worldObj, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ), sound);
} else {
//container.playerInventory.player.addStat(Statistics.blocksChiseled, crafted.stackSize);
}
}
}
Expand Up @@ -22,9 +22,6 @@ public PropertyVariation() {

@Override
public Collection getAllowedValues() {
if (values.size() == 0) {
throw new RuntimeException("0 Values?");
}
return values;
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit f10f4df

Please sign in to comment.