Skip to content

Commit

Permalink
Fix up some issues with Build.gradle, Clean up code and switch to reg…
Browse files Browse the repository at this point in the history
…istry events for adding blocks and items.
  • Loading branch information
alexbegt committed Jan 8, 2019
1 parent 37b34bf commit 49a0972
Show file tree
Hide file tree
Showing 16 changed files with 311 additions and 278 deletions.
107 changes: 51 additions & 56 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {
name "fileRepo"
dirs "repo"
}
maven {
maven {
name 'DVS1 Maven FS'
url 'http://dvs1.progwml6.com/files/maven'
}
Expand All @@ -49,8 +49,8 @@ minecraft {
// default run configurations.
// these can be tweaked, removed, or duplicated as needed.
runConfig {
name= "Minecraft Client"
main= "net.minecraftforge.userdev.UserdevLauncher"
name = "Minecraft Client"
main = "net.minecraftforge.userdev.UserdevLauncher"
ideaModuleName = "${project.name}_main"
workingDirectory = project.file("run").canonicalPath
environment "target", "fmluserdevclient"
Expand All @@ -63,8 +63,8 @@ minecraft {
}

runConfig {
name= "Minecraft Server"
main= "net.minecraftforge.userdev.UserdevLauncher"
name = "Minecraft Server"
main = "net.minecraftforge.userdev.UserdevLauncher"
ideaModuleName = "${project.name}_main"
workingDirectory = project.file("run").canonicalPath
environment "target", "fmluserdevserver"
Expand All @@ -87,47 +87,43 @@ def versionInfo = getGitVersion()
version = minecraft_version + "-${versionInfo['IronChest.version']}"

// This wrangles the resources for the jar files- stuff like textures and languages
processResources
{
processResources {
// we're omitting the .xcf files - they're development only
exclude '**/*.xcf'
exclude '**/*.xcf'
// we only want to do search/replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'META_INF/mods.toml'
include 'META-INF/mods.toml'

// replace version and mcversion
expand 'version':project.version, 'mcversion':minecraft_version
expand 'version': project.version, 'mcversion': minecraft_version
}

// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'META_INF/mods.toml'
exclude 'META-INF/mods.toml'
}

// generate version.properties file from the git version data earlier
doLast {
def propsFile = new File(destinationDir, 'version.properties')
def properties = new Properties()
properties.putAll(versionInfo)
properties['IronChest.build.mcversion'] = minecraft_version
properties.store(propsFile.newWriter(), null)
}
// generate version.properties file from the git version data earlier
doLast {
def propsFile = new File(destinationDir, 'version.properties')
def properties = new Properties()
properties.putAll(versionInfo)
properties['IronChest.build.mcversion'] = minecraft_version
properties.store(propsFile.newWriter(), null)
}
}

// Configure an upload task. this is setup for uploading to files.minecraftforge.net. There are other examples around
uploadArchives {
repositories.mavenDeployer {

dependsOn 'build'

if (project.hasProperty('forgeMavenPassword'))
{
if (project.hasProperty('forgeMavenPassword')) {
repository(url: "http://files.minecraftforge.net/maven/manage/upload") {
authentication(userName: project.getProperty('forgeMavenUser'), password: project.getProperty('forgeMavenPassword')) // the elvis operator. look it up.
authentication(userName: project.getProperty('forgeMavenUser'), password: project.getProperty('forgeMavenPassword'))
// the elvis operator. look it up.
}
}
else
{
} else {
// local repo folder. Might wanna juset use gradle install if you wanans end it to maven-local
repository(url: 'file://localhost/' + project.file('repo').getAbsolutePath())
}
Expand Down Expand Up @@ -175,32 +171,31 @@ uploadArchives {
}

// This is a special task for pulling the version information from git and the environment (for BUILD_NUMBER)
def getGitVersion()
{
def out = [:]

// call git command.
def outStream = new ByteArrayOutputStream()
def result = exec {
executable = 'git'
args = [ 'describe', '--long', "--match=[^(jenkins)]*"]
standardOutput = outStream
}

def fullVersion = outStream.toString().trim()
def matcher = fullVersion =~ /(\d+).(\d+)-(\d+)-(.*)/

def maj = matcher[0][1]
def min = matcher[0][2]
def rev = matcher[0][3]
def bn = System.getenv("PROMOTED_NUMBER") ?: System.getenv("BUILD_NUMBER") ?: "1"

out['IronChest.build.major.number'] = maj.toString()
out['IronChest.build.minor.number'] = min.toString()
out['IronChest.build.revision.number'] = rev.toString()
out['IronChest.build.githash'] = matcher[0][4].toString()
out['IronChest.build.number' ] = bn.toString()
out['IronChest.version' ] = "${maj}.${min}.${rev}.${bn}".toString()

return out
def getGitVersion() {
def out = [:]

// call git command.
def outStream = new ByteArrayOutputStream()
def result = exec {
executable = 'git'
args = ['describe', '--long', "--match=[^(jenkins)]*"]
standardOutput = outStream
}

def fullVersion = outStream.toString().trim()
def matcher = fullVersion =~ /(\d+).(\d+)-(\d+)-(.*)/

def maj = matcher[0][1]
def min = matcher[0][2]
def rev = matcher[0][3]
def bn = System.getenv("PROMOTED_NUMBER") ?: System.getenv("BUILD_NUMBER") ?: "1"

out['IronChest.build.major.number'] = maj.toString()
out['IronChest.build.minor.number'] = min.toString()
out['IronChest.build.revision.number'] = rev.toString()
out['IronChest.build.githash'] = matcher[0][4].toString()
out['IronChest.build.number'] = bn.toString()
out['IronChest.version'] = "${maj}.${min}.${rev}.${bn}".toString()

return out
}
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G

mod_version=1.0.0

# Minecraft Version Information
minecraft_version=1.13
minecraft_version_toml=13

# Forge Version Information
forge_version=24.0.55-1.13-pre
forge_version=24.0.58-1.13-pre
forge_version_toml=24
forge_group=net.minecraftforge.test

Expand Down
61 changes: 54 additions & 7 deletions src/main/java/cpw/mods/ironchest/IronChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@

import cpw.mods.ironchest.client.ClientProxy;
import cpw.mods.ironchest.common.ServerProxy;
import cpw.mods.ironchest.common.ai.OcelotsSitOnChestsHandler;
import cpw.mods.ironchest.common.blocks.BlockChest;
import cpw.mods.ironchest.common.core.IronChestBlocks;
import cpw.mods.ironchest.common.core.IronChestItems;
import cpw.mods.ironchest.common.tileentity.IronChestEntityType;
import cpw.mods.ironchest.common.util.BlockNames;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
Expand All @@ -25,30 +32,70 @@ public class IronChest
{
public static final String MOD_ID = "ironchest";

private static final boolean DEBUG = false;

public static IronChest instance;

public static ServerProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new);

public IronChestBlocks ironChestBlocks = new IronChestBlocks();

public IronChestItems ironChestItems = new IronChestItems();

public IronChestEntityType ironChestEntityType = new IronChestEntityType();

public IronChest()
{
instance = this;
FMLModLoadingContext.get().getModEventBus().addListener(this::preInit);
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
MinecraftForge.EVENT_BUS.register(new IronChestBlocks());
MinecraftForge.EVENT_BUS.register(new IronChestItems());
MinecraftForge.EVENT_BUS.register(new IronChestEntityType());
}

private void preInit(final FMLPreInitializationEvent event)
{
proxy.preInit();
ironChestBlocks.registerBlocks();
ironChestBlocks.registerItems();
ironChestItems.registerItems();

if (IronChest.DEBUG)
{
debugPrints();
}

ironChestEntityType.registerTileEntities();
ironChestEntityType.createEntries();
}

private void debugPrints()
{
EnumFacing[] e = { EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST };

System.out.println("--------------------------");

for (EnumFacing facing : e)
{
IBlockState iBlockState = Block.func_149684_b(BlockNames.IRON_CHEST).getDefaultState().with(BlockChest.FACING, facing);

System.out.println("iBlockState " + iBlockState);

int stateID = Block.getStateId(iBlockState);

System.out.println("stateID " + stateID);

IBlockState iBlockStateOut = Block.getStateById(stateID);

System.out.println("iBlockStateOut " + iBlockStateOut);

Block blockOut = Block.func_149729_e(stateID);

System.out.println("blockOut " + blockOut);

System.out.println("--------------------------");
}

System.out.println("--------------------------");

for (Object i : Block.BLOCK_STATE_IDS)
{
System.out.println("Test: " + i);
}
System.out.println("--------------------------");
}
}
2 changes: 1 addition & 1 deletion src/main/java/cpw/mods/ironchest/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public ClientProxy()
@SuppressWarnings({ "unchecked", "rawtypes" })
public void preInit()
{
System.out.println("hello");
super.preInit();

for (IronChestType type : IronChestType.values())
{
if (type.clazz != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.google.common.primitives.SignedBytes;
import cpw.mods.ironchest.common.blocks.BlockChest;
import cpw.mods.ironchest.common.blocks.BlockIronChest;
import cpw.mods.ironchest.common.blocks.IronChestType;
import cpw.mods.ironchest.common.core.IronChestBlocks;
import cpw.mods.ironchest.common.tileentity.TileEntityCrystalChest;
Expand Down Expand Up @@ -67,7 +66,7 @@ public void render(T tileEntityIn, double x, double y, double z, float partialTi
GlStateManager.depthMask(true);
IBlockState iblockstate = tileEntityIn.hasWorld() ?
tileEntityIn.getBlockState() :
(IBlockState) IronChestBlocks.ironChestBlock.getDefaultState().with(BlockIronChest.FACING, EnumFacing.SOUTH);
(IBlockState) IronChestBlocks.ironChestBlock.getDefaultState().with(BlockChest.FACING, EnumFacing.NORTH);
IronChestType chesttype = IronChestType.IRON;
IronChestType typeNew = BlockChest.getTypeFromBlock(iblockstate.getBlock());

Expand Down Expand Up @@ -101,7 +100,7 @@ public void render(T tileEntityIn, double x, double y, double z, float partialTi
GlStateManager.translatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
GlStateManager.scalef(1.0F, -1.0F, -1.0F);

float f = iblockstate.get(BlockIronChest.FACING).getHorizontalAngle();
float f = iblockstate.get(BlockChest.FACING).getHorizontalAngle();
if (Math.abs(f) > 1.0E-5D)
{
GlStateManager.translatef(0.5F, 0.5F, 0.5F);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected boolean shouldMoveTo(IWorldReaderBase worldIn, BlockPos pos)
}
else
{
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
IBlockState iBlockState = worldIn.getBlockState(pos);
Block block = iBlockState.getBlock();

if (block instanceof BlockChest)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class OcelotsSitOnChestsHandler
{
@SubscribeEvent
public void changeSittingTaskForOcelots(LivingUpdateEvent evt)
public void changeSittingTaskForOcelots(final LivingUpdateEvent evt)
{
if (evt.getEntityLiving().ticksExisted < 5 && evt.getEntityLiving() instanceof EntityOcelot)
{
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/cpw/mods/ironchest/common/blocks/BlockChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.INameable;
import net.minecraft.util.Mirror;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
Expand All @@ -52,19 +53,25 @@ public abstract class BlockChest extends Block implements ITileEntityProvider

protected static final VoxelShape IRON_CHEST_SHAPE = Block.makeCuboidShape(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);

public IronChestType type;
private final IronChestType type;

public BlockChest(Builder properties, IronChestType type)
public BlockChest(Builder builderIn, IronChestType typeIn)
{
super(properties);
super(builderIn);

this.setDefaultState(((this.stateContainer.getBaseState()).with(FACING, EnumFacing.NORTH)));
this.type = typeIn;

this.type = type;
this.setDefaultState((IBlockState) ((IBlockState) this.stateContainer.getBaseState()).with(FACING, EnumFacing.NORTH));

this.setRegistryName(new ResourceLocation(type.itemName));
}

@Override
public VoxelShape getShape(IBlockState state, IBlockReader worldIn, BlockPos pos)
{
return IRON_CHEST_SHAPE;
}

@Override
public boolean isSolid(IBlockState state)
{
Expand Down Expand Up @@ -98,12 +105,6 @@ public IBlockState getStateForPlacement(BlockItemUseContext context)
return this.getDefaultState().with(FACING, enumfacing);
}

@Override
public VoxelShape getShape(IBlockState state, IBlockReader worldIn, BlockPos pos)
{
return IRON_CHEST_SHAPE;
}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
{
Expand Down Expand Up @@ -216,7 +217,13 @@ public int getComparatorInputOverride(IBlockState blockState, World worldIn, Blo
@Override
public IBlockState rotate(IBlockState state, Rotation rot)
{
return state.with(FACING, rot.rotate(state.get(FACING)));
return (IBlockState) state.with(FACING, rot.rotate((EnumFacing) state.get(FACING)));
}

@Override
public IBlockState mirror(IBlockState state, Mirror mirrorIn)
{
return state.rotate(mirrorIn.toRotation((EnumFacing) state.get(FACING)));
}

@Override
Expand Down Expand Up @@ -251,5 +258,4 @@ public IronChestType getType()
{
return this.type;
}

}
Loading

0 comments on commit 49a0972

Please sign in to comment.