Skip to content

Commit

Permalink
Merge pull request #38 from German-Immersive-Railroading-Community/tu…
Browse files Browse the repository at this point in the history
…rningSystem

Turning system, polished and finished
  • Loading branch information
MrTroble authored Feb 3, 2021
2 parents ed03ed4 + bacf32c commit 4bf986c
Show file tree
Hide file tree
Showing 64 changed files with 205 additions and 1,318 deletions.
105 changes: 70 additions & 35 deletions src/main/java/eu/gir/girsignals/blocks/SignalBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
import eu.gir.girsignals.init.GIRItems;
import eu.gir.girsignals.tileentitys.SignalTileEnity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
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.client.Minecraft;
Expand All @@ -27,6 +26,7 @@
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
Expand All @@ -39,56 +39,90 @@
import net.minecraftforge.common.property.IUnlistedProperty;

public class SignalBlock extends Block implements ITileEntityProvider {


public static enum SignalAngel implements IStringSerializable {
ANGEL0(0.000000, 0.000000), ANGEL22P5(0.000000, 0.382683), ANGEL45(0.000000, 0.707107),
ANGEL67P5(0.000000, 0.923880), ANGEL90(0.000000, 1.000000), ANGEL112P5(0.076120, 1.000000),
ANGEL135(0.292893, 1.000000), ANGEL157P5(0.617317, 1.000000), ANGEL180(1.000000, 1.000000),
ANGEL202P5(0.382683, 0.000000), ANGEL225(0.707107, 0.000000), ANGEL247P5(0.923880, 0.000000),
ANGEL270(1.000000, 0.000000), ANGEL292P5(0.923880, 0.000000), ANGEL315(0.707107, 0.000000),
ANGEL337P5(0.382683, 0.000000);

private final float x;
private final float y;

private SignalAngel(double x, double y) {
this.x = (float) x;
this.y = (float) y;
}

@Override
public String getName() {
return this.name().toLowerCase();
}

public float getAngel() {
return this.ordinal() * 22.5f;
}

public float getX() {
return x;
}

public float getY() {
return y;
}
}

public static final ArrayList<SignalBlock> SIGNALLIST = new ArrayList<SignalBlock>();

public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final SEProperty<Boolean> CUSTOMNAME = SEProperty.of("customname", false, ChangeableStage.AUTOMATICSTAGE);
public static final PropertyEnum<SignalAngel> ANGEL = PropertyEnum.create("angel", SignalAngel.class);
public static final SEProperty<Boolean> CUSTOMNAME = SEProperty.of("customname", false,
ChangeableStage.AUTOMATICSTAGE);

private final int ID;
private final int height;

private final String signalTypeName;

public SignalBlock(String signalTypeName, int height) {
super(Material.ROCK);
this.signalTypeName = signalTypeName;
setDefaultState(getDefaultState().withProperty(FACING, EnumFacing.NORTH));
setDefaultState(getDefaultState().withProperty(ANGEL, SignalAngel.ANGEL0));
ID = SIGNALLIST.size();
SIGNALLIST.add(this);
this.height =height;
this.height = height;
}

@Override
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune)
{
}

public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
}

private static AxisAlignedBB BOUNDING_BOX = FULL_BLOCK_AABB.expand(0, 6, 0);

@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return BOUNDING_BOX;
}

@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) {
return BOUNDING_BOX;
return getBoundingBox(blockState, worldIn, pos);
}

public static ItemStack pickBlock(EntityPlayer player) {
// Compatibility issues with other mods ...
if(!Minecraft.getMinecraft().gameSettings.keyBindPickBlock.isKeyDown()) return ItemStack.EMPTY;
for (int k = 0; k < InventoryPlayer.getHotbarSize(); ++k)
{
if(player.inventory.getStackInSlot(k).getItem().equals(GIRItems.PLACEMENT_TOOL)) {
player.inventory.currentItem = k;
return ItemStack.EMPTY;
}
}
if (!Minecraft.getMinecraft().gameSettings.keyBindPickBlock.isKeyDown())
return ItemStack.EMPTY;
for (int k = 0; k < InventoryPlayer.getHotbarSize(); ++k) {
if (player.inventory.getStackInSlot(k).getItem().equals(GIRItems.PLACEMENT_TOOL)) {
player.inventory.currentItem = k;
return ItemStack.EMPTY;
}
}
return new ItemStack(GIRItems.PLACEMENT_TOOL);
}

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos,
EntityPlayer player) {
Expand All @@ -98,17 +132,18 @@ public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World wo
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
int x = Math.abs((int) (placer.rotationYaw / 22.5f)) % 16;
return getDefaultState().withProperty(ANGEL, SignalAngel.values()[x]);
}

@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
return getDefaultState().withProperty(ANGEL, SignalAngel.values()[meta]);
}

@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(FACING).getHorizontalIndex();
return state.getValue(ANGEL).ordinal();
}

@Override
Expand Down Expand Up @@ -189,15 +224,15 @@ protected BlockStateContainer createBlockState() {
}
}
prop.add(CUSTOMNAME);
return new ExtendedBlockState(this, new IProperty<?>[] { FACING },
return new ExtendedBlockState(this, new IProperty<?>[] { ANGEL },
prop.toArray(new IUnlistedProperty[prop.size()]));
}

@Override
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
return true;
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new SignalTileEnity();
Expand All @@ -210,14 +245,14 @@ public String getSignalTypeName() {
public int getID() {
return ID;
}

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
super.breakBlock(worldIn, pos, state);

GhostBlock.destroyUpperBlock(worldIn, pos);
}

public int getHeight(NBTTagCompound comp) {
return height;
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/eu/gir/girsignals/models/GIRCustomModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

import eu.gir.girsignals.GirsignalsMain;
import eu.gir.girsignals.EnumSignals.HL;
import eu.gir.girsignals.EnumSignals.HL_LIGHTBAR;
import eu.gir.girsignals.EnumSignals.HPVR;
Expand All @@ -14,15 +13,19 @@
import eu.gir.girsignals.EnumSignals.SH_LIGHT;
import eu.gir.girsignals.EnumSignals.TRAM;
import eu.gir.girsignals.EnumSignals.ZS32;
import eu.gir.girsignals.GirsignalsMain;
import eu.gir.girsignals.blocks.SignalBlock;
import eu.gir.girsignals.blocks.SignalBlock.SignalAngel;
import eu.gir.girsignals.blocks.SignalHL;
import eu.gir.girsignals.blocks.SignalHV;
import eu.gir.girsignals.blocks.SignalKS;
import eu.gir.girsignals.blocks.SignalSHLight;
import eu.gir.girsignals.blocks.SignalTram;
import net.minecraft.client.renderer.block.model.BuiltInModel;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ICustomModelLoader;
import net.minecraftforge.client.model.IModel;
Expand Down Expand Up @@ -331,18 +334,20 @@ public void onResourceManagerReload(IResourceManager resourceManager) {
public boolean accepts(ResourceLocation modelLocation) {
if (!modelLocation.getResourceDomain().equals(GirsignalsMain.MODID))
return false;
return registeredModels.containsKey(modelLocation.getResourcePath());
return registeredModels.containsKey(modelLocation.getResourcePath()) || modelLocation.getResourcePath().equals("ghostblock");
}

@Override
public IModel loadModel(ResourceLocation modelLocation) throws Exception {
if(modelLocation.getResourcePath().equals("ghostblock"))
return (state, format, bak) -> new BuiltInModel(ItemCameraTransforms.DEFAULT, ItemOverrideList.NONE);
ModelResourceLocation mrl = (ModelResourceLocation) modelLocation;
String[] strs = mrl.getVariant().split("=");
if(strs.length < 2)
return new SignalCustomModel(registeredModels.get(modelLocation.getResourcePath()),
EnumFacing.NORTH);
SignalAngel.ANGEL0);
return new SignalCustomModel(registeredModels.get(modelLocation.getResourcePath()),
EnumFacing.byName(strs[1]));
SignalAngel.valueOf(strs[1].toUpperCase()));
}

}
Loading

0 comments on commit 4bf986c

Please sign in to comment.