Skip to content

Commit

Permalink
somewhat working
Browse files Browse the repository at this point in the history
  • Loading branch information
Trnrr committed Mar 24, 2024
1 parent 6d2a88d commit a738154
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 11 deletions.
62 changes: 61 additions & 1 deletion src/main/java/turniplabs/examplemod/ExampleMod.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,71 @@
package turniplabs.examplemod;

import net.fabricmc.api.ModInitializer;
import net.minecraft.client.render.block.color.BlockColor;
import net.minecraft.core.block.Block;
import net.minecraft.core.block.BlockLayerBase;
import net.minecraft.core.block.BlockLeavesBase;
import net.minecraft.core.block.material.Material;
import net.minecraft.core.block.tag.BlockTags;
import net.minecraft.core.data.tag.Tag;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.item.block.ItemBlock;
import net.minecraft.core.item.block.ItemBlockLamp;
import net.minecraft.core.item.block.ItemBlockLayer;
import net.minecraft.core.item.block.ItemBlockLeaves;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import turniplabs.halplibe.helper.BlockBuilder;
import turniplabs.halplibe.helper.RecipeBuilder;
import turniplabs.halplibe.util.GameStartEntrypoint;
import turniplabs.halplibe.util.RecipeEntrypoint;
import net.minecraft.core.item.Item;


public class ExampleMod implements ModInitializer, GameStartEntrypoint, RecipeEntrypoint {
public static final String MOD_ID = "examplemod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static Item[] itemsList = new Item['耀'];
public static final Block[] blocksList = new Block[16384];


public static final Block toggledLampIdle = new BlockBuilder(MOD_ID)
//.addTags(new Tag[2])
.build(new LampBlock("toggledLampIdle",8888, false)
.withHardness(0.5F)
.withDisabledStats()
//.withDisabledNeighborNotifyOnMetadataChange()
.withTags(BlockTags.MINEABLE_BY_PICKAXE));
public static final Block toggledLampActive = new BlockBuilder(MOD_ID)
//.addTags(new Tag[2])
.build(new LampBlock("toggledLampActive",8889, true)
.withLightEmission(0.9375F)
.withHardness(0.5F)
.withDisabledStats()
//.withDisabledNeighborNotifyOnMetadataChange()
.withTags(BlockTags.MINEABLE_BY_PICKAXE));


/* static
{
Item.itemsList[toggleLampIdle.id] = new ItemBlockLamp(toggleLampIdle);
int i;
for(i = 0; i < blocksList.length; ++i) {
}
}*/

//lampActive = (new BlockLamp("lamp.active", 851, true)).withLightEmission(0.9375F).withHardness(0.5F).withDisabledStats().withDisabledNeighborNotifyOnMetadataChange().withTags(BlockTags.NOT_IN_CREATIVE_MENU, BlockTags.MINEABLE_BY_PICKAXE);

@Override
public void onInitialize() {
LOGGER.info("ExampleMod initialized.");
}

@Override
public void beforeGameStart() {

}

@Override
Expand All @@ -29,5 +76,18 @@ public void afterGameStart() {
@Override
public void onRecipesReady() {


RecipeBuilder.Shapeless(MOD_ID)
.addInput(Block.dirt)
.create("toggledLampIdle_", new ItemStack(toggledLampIdle, 1, 10));

for(int i = 0; i <= 15; i++)
{
RecipeBuilder.Shapeless(MOD_ID)
.addInput(Block.leverCobbleStone)
.addInput(Block.lampIdle, i)
.create("toggledLampIdle_"+i, new ItemStack(toggledLampIdle, 1, i));
}

}
}
98 changes: 98 additions & 0 deletions src/main/java/turniplabs/examplemod/LampBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package turniplabs.examplemod;

import net.minecraft.core.Global;
import net.minecraft.core.block.Block;
import net.minecraft.core.block.BlockLamp;
import net.minecraft.core.block.entity.TileEntity;
import net.minecraft.core.block.material.Material;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.enums.EnumDropCause;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.util.helper.Side;
import net.minecraft.core.world.World;
import net.minecraft.core.world.WorldSource;

import java.util.Random;

public class LampBlock extends Block {

private static final int[] texCoordsInactive = new int[16];
private static final int[] texCoordsActive = new int[16];
boolean isActive;

public LampBlock(String key, int id, boolean isActivated) {
super(key, id, Material.stone);
this.isActive = isActivated; //NEED
}
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
world.scheduleBlockUpdate(x, y, z, this.id, this.tickRate());
}

public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player) {
if (world.getBlockId(x,y,z) == 8888)
{
world.setBlockAndMetadataWithNotify(x,y,z,8889,world.getBlockMetadata(x,y,z));
return true;
}
else if (world.getBlockId(x,y,z) == 8889)
{
world.setBlockAndMetadataWithNotify(x,y,z,8888,world.getBlockMetadata(x,y,z));
return true;
}
return false;
}

/*@Override
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
player.addChatMessage("Test");
player.addChatMessage(String.valueOf(world.getBlockId(x,y,z)));
player.addChatMessage(String.valueOf(world.getBlockMetadata(x,y,z)));
//world.getBlockMetadata(x,y,z);
if (world.getBlockId(x,y,z) == 8888)
{
player.addChatMessage("==8888: " + world.getBlockId(x,y,z));
world.setBlockAndMetadataWithNotify(x,y,z,8889,world.getBlockMetadata(x,y,z));
}
else if (world.getBlockId(x,y,z) == 8889)
{
player.addChatMessage("==8889: " + world.getBlockId(x,y,z));
world.setBlockAndMetadataWithNotify(x,y,z,8888,world.getBlockMetadata(x,y,z));
}
}*/

public int getBlockTexture(WorldSource blockAccess, int x, int y, int z, Side side) {
int data = blockAccess.getBlockMetadata(x, y, z);
return this.isActive ? texCoordsActive[data & 15] : texCoordsInactive[data & 15];
}

public int getBlockTextureFromSideAndMetadata(Side side, int data) {
return texCoordsActive[data & 15];
}

public static int getMetadataForColour(int i) {
return ~i & 15;
}

public ItemStack[] getBreakResult(World world, EnumDropCause dropCause, int x, int y, int z, int meta, TileEntity tileEntity) {
return new ItemStack[]{new ItemStack(Block.lampIdle, 1, meta)};
}

static {
texCoordsInactive[0] = Block.texCoordToIndex(17, 31);

int i;
for(i = 1; i < 16; ++i) {
texCoordsInactive[i] = texCoordsInactive[0] - i % 8 * Global.TEXTURE_ATLAS_WIDTH_TILES - i / 8;
}

texCoordsActive[0] = Block.texCoordToIndex(19, 31);

for(i = 1; i < 16; ++i) {
texCoordsActive[i] = texCoordsActive[0] - i % 8 * Global.TEXTURE_ATLAS_WIDTH_TILES - i / 8;
}

}

}
29 changes: 29 additions & 0 deletions src/main/java/turniplabs/examplemod/mixin/BlockLampMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package turniplabs.examplemod.mixin;

import net.minecraft.core.block.Block;
import net.minecraft.core.block.BlockLamp;
import net.minecraft.core.block.material.Material;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(value = BlockLamp.class, remap = false)
public class BlockLampMixin {
/*
@Shadow
private boolean isActive;
public BlockLampMixin(String key, int id, boolean isActivated) {
super(key, id, isActivated);
}
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
player.addChatMessage("tEST");
isActive = true;
world.setBlockAndMetadataWithNotify(x, y, z, Block.lampActive.id, world.getBlockMetadata(x, y, z));
}*/
}

21 changes: 11 additions & 10 deletions src/main/resources/examplemod.mixins.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "turniplabs.examplemod.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
],
"injectors": {
"defaultRequire": 1
"required": true,
"minVersion": "0.8",
"package": "turniplabs.examplemod.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"BlockLampMixin"
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit a738154

Please sign in to comment.