mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 20:09:39 +00:00
Implement initial BlockState API
This commit is contained in:
1 parent
77f1e9b5a2
commit
fff5b2cb01
3 files changed
+63
-1
No files matched your search
@@ -0,0 +1,14 @@
|
||||
package com.gtnewhorizons.angelica.api;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* <p>Modern versions have BlockState, which allows you to query properties in a fairly standardized way. We don't have
|
||||
* that on 1.7.10, so let's roll our own. Blocks can implement this to convert metas to properties.
|
||||
*/
|
||||
public interface BlockState {
|
||||
|
||||
default boolean hasFacing() { return false; }
|
||||
|
||||
default ForgeDirection getFacing(int meta) { return ForgeDirection.UNKNOWN; }
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.gtnewhorizons.angelica.common;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.api.BlockState;
|
||||
import com.gtnewhorizons.angelica.models.json.JsonModel;
|
||||
import com.gtnewhorizons.angelica.models.json.Loader;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
@@ -14,9 +15,11 @@ import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BlockTest extends Block implements QuadProvider {
|
||||
public class BlockTest extends Block implements QuadProvider, BlockState {
|
||||
|
||||
public static final ResourceLocation modelId = new ResourceLocation("blocks/lectern");
|
||||
public static final List<Quad> EMPTY = ObjectImmutableList.of();
|
||||
@@ -43,4 +46,30 @@ public class BlockTest extends Block implements QuadProvider {
|
||||
final JsonModel m = Loader.getModel(modelId);
|
||||
return (m != null) ? m.getQuads(world, pos, block, meta, dir, random, quadPool) : EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
|
||||
*/
|
||||
@Override
|
||||
public int onBlockPlaced(@NotNull World worldIn, int x, int y, int z, int side, float subX, float subY, float subZ, int meta) {
|
||||
|
||||
// Face NORTH if placed up or down
|
||||
final ForgeDirection s = ForgeDirection.values()[side];
|
||||
if (s == ForgeDirection.UP || s == ForgeDirection.DOWN)
|
||||
return 2;
|
||||
|
||||
// Face the placed side
|
||||
return side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFacing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getFacing(int meta) {
|
||||
|
||||
return ForgeDirection.values()[meta];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user