Skip to content

Commit

Permalink
Merge pull request #32 from mrquentin/main
Browse files Browse the repository at this point in the history
Susy Facing Blockstate Interface and Gregtech Dryer
  • Loading branch information
BestMod authored Apr 18, 2023
2 parents bef2000 + e876d59 commit 5ef5b39
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package supersymmetry.api.blocks;

import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public interface ISuSyHorizontalOrientable {

PropertyDirection FACING = BlockHorizontal.FACING;

IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer);
int getMetaFromState(IBlockState state);
IBlockState getStateFromMeta(int meta);
BlockStateContainer createBlockState();

default void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}

default IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
}

default IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
}
3 changes: 3 additions & 0 deletions src/main/java/supersymmetry/api/recipes/SuSyRecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class SuSyRecipeMaps {
public static final RecipeMap<SimpleRecipeBuilder> BUBBLE_COLUMN_REACTOR_RECIPES = new RecipeMap<>("bubble_column_reactor", 0, 0, 3, 2, new SimpleRecipeBuilder(), false)
.setSound(GTSoundEvents.CHEMICAL_REACTOR);

public static final RecipeMap<SimpleRecipeBuilder> DRYER = new RecipeMap<>("dryer", 1, 1, 1, 1, new SimpleRecipeBuilder(), false)
.setSound(GTSoundEvents.CHEMICAL_REACTOR);

public static final RecipeMap<SimpleRecipeBuilder> FLUIDIZED_BED_REACTOR_RECIPES = new RecipeMap<>("fluidized_bed_reactor", 1, 0, 3, 2, new SimpleRecipeBuilder(), false)
.setSound(GTSoundEvents.CHEMICAL_REACTOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SusyTextures {
public static OrientedOverlayRenderer TRICKLE_BED_REACTOR_OVERLAY;
public static OrientedOverlayRenderer CRYSTALLIZER_OVERLAY;
public static OrientedOverlayRenderer BUBBLE_COLUMN_REACTOR_OVERLAY;
public static OrientedOverlayRenderer DRYER_OVERLAY;

public SusyTextures(){
}
Expand All @@ -33,5 +34,6 @@ public static void preInit(){
TRICKLE_BED_REACTOR_OVERLAY = new OrientedOverlayRenderer("machines/trickle_bed_reactor");
CRYSTALLIZER_OVERLAY = new OrientedOverlayRenderer("machines/crystallizer");
BUBBLE_COLUMN_REACTOR_OVERLAY = new OrientedOverlayRenderer("machines/bubble_column_reactor");
DRYER_OVERLAY = new OrientedOverlayRenderer("machines/dryer");
}
}
49 changes: 13 additions & 36 deletions src/main/java/supersymmetry/common/blocks/BlockAlternatorCoil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@

import gregtech.api.block.IStateHarvestLevel;
import gregtech.api.block.VariantBlock;
import gregtech.api.util.GTUtility;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import supersymmetry.api.SusyLog;
import supersymmetry.api.blocks.ISuSyHorizontalOrientable;

import javax.annotation.Nonnull;

public class BlockAlternatorCoil extends VariantBlock<BlockAlternatorCoil.AlternatorCoilType> {
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public class BlockAlternatorCoil extends VariantBlock<BlockAlternatorCoil.AlternatorCoilType> implements ISuSyHorizontalOrientable {

public BlockAlternatorCoil(){
super(net.minecraft.block.material.Material.IRON);
Expand All @@ -37,48 +30,32 @@ public BlockAlternatorCoil(){
setDefaultState(getState(AlternatorCoilType.COPPER).withProperty(FACING, EnumFacing.NORTH));
}

public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}

public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
return super.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}

public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
}

public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}

public IBlockState getStateFromMeta(int meta)
{
@Override
public IBlockState getStateFromMeta(int meta) {
int i = meta / 4;
int j = meta % 4 + 2;

EnumFacing enumfacing = EnumFacing.byIndex(j);

if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}
EnumFacing enumfacing = EnumFacing.byHorizontalIndex(j);

return this.getDefaultState().withProperty(FACING, enumfacing).withProperty(this.VARIANT, this.VALUES[i % this.VALUES.length]);
return this.getDefaultState()
.withProperty(FACING, enumfacing)
.withProperty(this.VARIANT, this.VALUES[i % this.VALUES.length]);
}

public int getMetaFromState(IBlockState state)
{
@Override
public int getMetaFromState(IBlockState state) {
int i = ((Enum)state.getValue(this.VARIANT)).ordinal();
int j = ((EnumFacing)state.getValue(FACING)).getIndex();
return j - 2 + i * 4;
}

@Nonnull
protected BlockStateContainer createBlockState() {
@Override
public BlockStateContainer createBlockState() {
super.createBlockState();

return new BlockStateContainer(this, new IProperty[]{this.VARIANT, this.FACING});
Expand Down
39 changes: 11 additions & 28 deletions src/main/java/supersymmetry/common/blocks/BlockTurbineRotor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@

import gregtech.api.block.IStateHarvestLevel;
import gregtech.api.block.VariantBlock;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import supersymmetry.api.SusyLog;
import supersymmetry.api.blocks.ISuSyHorizontalOrientable;

import javax.annotation.Nonnull;

public class BlockTurbineRotor extends VariantBlock<BlockTurbineRotor.BlockTurbineRotorType> {
public static final PropertyDirection FACING = BlockHorizontal.FACING;

public class BlockTurbineRotor extends VariantBlock<BlockTurbineRotor.BlockTurbineRotorType> implements ISuSyHorizontalOrientable {
public BlockTurbineRotor(){
super(net.minecraft.block.material.Material.IRON);
setTranslationKey("turbine_rotor");
Expand All @@ -34,39 +29,26 @@ public BlockTurbineRotor(){
setDefaultState(getState(BlockTurbineRotorType.STEEL).withProperty(FACING, EnumFacing.NORTH));
}

public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}

@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
return super.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}

public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
}

public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}

@Override
public IBlockState getStateFromMeta(int meta)
{
int i = meta / 4;
int j = meta % 4 + 2;

EnumFacing enumfacing = EnumFacing.byIndex(j);

if (enumfacing.getAxis() == EnumFacing.Axis.Y)
{
enumfacing = EnumFacing.NORTH;
}
EnumFacing enumfacing = EnumFacing.byHorizontalIndex(j);

return this.getDefaultState().withProperty(FACING, enumfacing).withProperty(this.VARIANT, this.VALUES[i % this.VALUES.length]);
return this.getDefaultState()
.withProperty(FACING, enumfacing)
.withProperty(this.VARIANT, this.VALUES[i % this.VALUES.length]);
}

@Override
public int getMetaFromState(IBlockState state)
{
int i = ((Enum)state.getValue(this.VARIANT)).ordinal();
Expand All @@ -75,7 +57,8 @@ public int getMetaFromState(IBlockState state)
}

@Nonnull
protected BlockStateContainer createBlockState() {
@Override
public BlockStateContainer createBlockState() {
super.createBlockState();

return new BlockStateContainer(this, new IProperty[]{this.VARIANT, this.FACING});
Expand Down
Loading

0 comments on commit 5ef5b39

Please sign in to comment.