Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
-Added AbstractModContainerBlock, AbstractModTileEntity.
-Added getUpateURL() to IMod.\n-Renamed getVerisionURL to getVersionURL
in IMod.
-Added readFromNBT() and writeToNBT() methods to ICoords/Coords class.
-VersionChecker now first attempts to use the Forge update.json to track
versions.
  • Loading branch information
gottsch committed Jan 7, 2018
1 parent 460fcec commit 5618b41
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 24 deletions.
3 changes: 2 additions & 1 deletion GottschCore1.12.2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ext {
// revision = git.head().abbreviatedId
}

version = "mc${mc_version}-v${mod_version}-${git.head().abbreviatedId}"
//version = "mc${mc_version}-v${mod_version}-${git.head().abbreviatedId}"
version = "mc${mc_version}-f${forge_version}-v${mod_version}"
group = "${package_group}" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "${mod_name}"

Expand Down
4 changes: 2 additions & 2 deletions GottschCore1.12.2/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ org.gradle.jvmargs=-Xmx3G

mod_name=GottschCore
package_group=someguyssoftware.gottschcore
mod_version=1.1.2
mod_version=1.2.0

mc_version=1.12.2
forge_version=14.23.1.2556
forge_version=14.23.1.2555
mappings_version=snapshot_20171003


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class GottschCore extends AbstractMod {
// constants
public static final String MODID = "gottschcore";
protected static final String NAME = "GottschCore";
protected static final String VERSION = "1.1.2";
public static final String UPDATE_JSON_URL = "https://raw.githubusercontent.com/gottsch/gottsch-minecraft-GottschCore/master/GottschCore1.12/update.json";
protected static final String VERSION = "1.2.0";
public static final String UPDATE_JSON_URL = "https://raw.githubusercontent.com/gottsch/gottsch-minecraft-GottschCore/master/GottschCore1.12.2/update.json";

// TODO [back-burner]add a message file (messages.json) to check from.... global message and mod specific messages

Expand Down Expand Up @@ -126,6 +126,11 @@ public IMod getInstance() {
return GottschCore.instance;
}

@Override
public String getUpdateURL() {
return GottschCore.UPDATE_JSON_URL;
}

/* (non-Javadoc)
* @see com.someguyssoftware.gottschcore.IMod#getConfig()
*/
Expand All @@ -146,7 +151,7 @@ public BuildVersion getMinecraftVersion() {
* @see com.someguyssoftware.gottschcore.IMod#getVerisionURL()
*/
@Override
public String getVerisionURL() {
public String getVersionURL() {
return GottschCore.VERSION_URL;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
*
*/
package com.someguyssoftware.gottschcore.block;

import javax.annotation.Nullable;

import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldNameable;
import net.minecraft.world.World;

/**
* This class replaces BlockContainer so that it can extend ModBlock
* @author Mark Gottschling onJan 2, 2018
*
*/
public abstract class AbstractModContainerBlock extends ModBlock implements ITileEntityProvider {

/**
*
* @param modID
* @param name
* @param material
*/
public AbstractModContainerBlock(String modID, String name, Material material) {
this(modID, name, material, material.getMaterialMapColor());
}

/**
*
* @param modID
* @param name
* @param material
* @param mapColor
*/
public AbstractModContainerBlock(String modID, String name, Material material, MapColor mapColor) {
super(modID, name, material, mapColor);
this.hasTileEntity = true;
}

/**
*
* @param worldIn
* @param pos
* @param facing
* @return
*/
protected boolean isInvalidNeighbor(World worldIn, BlockPos pos, EnumFacing facing) {
return worldIn.getBlockState(pos.offset(facing)).getMaterial() == Material.CACTUS;
}

/**
*
* @param worldIn
* @param pos
* @return
*/
protected boolean hasInvalidNeighbor(World worldIn, BlockPos pos) {
return this.isInvalidNeighbor(worldIn, pos, EnumFacing.NORTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.SOUTH) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.WEST) || this.isInvalidNeighbor(worldIn, pos, EnumFacing.EAST);
}

/**
* The type of render function called. MODEL for mixed tesr and static model, MODELBLOCK_ANIMATED for TESR-only,
* LIQUID for vanilla liquids, INVISIBLE to skip all rendering.
* Since this class is abstract, default to no rendering.
*/
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.INVISIBLE;
}

/**
* Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
*/
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}

/**
* Spawns the block's drops in the world. By the time this is called the Block has possibly been set to air via
* Block.removedByPlayer
*/
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
if (te instanceof IWorldNameable && ((IWorldNameable)te).hasCustomName()) {
player.addStat(StatList.getBlockStats(this));
player.addExhaustion(0.005F);

if (worldIn.isRemote) {
return;
}

int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
Item item = this.getItemDropped(state, worldIn.rand, i);

if (item == Items.AIR) {
return;
}

ItemStack itemstack = new ItemStack(item, this.quantityDropped(worldIn.rand));
itemstack.setStackDisplayName(((IWorldNameable)te).getName());
spawnAsEntity(worldIn, pos, itemstack);
}
else {
super.harvestBlock(worldIn, player, pos, state, (TileEntity)null, stack);
}
}

/**
* Called on server when World#addBlockEvent is called. If server returns true, then also called on the client. On
* the Server, this may perform additional changes to the world, like pistons replacing the block with an extended
* base. On the client, the update may involve replacing tile entities or effects such as sounds or particles
*/
@SuppressWarnings("deprecation")
@Override
public boolean eventReceived(IBlockState state, World worldIn, BlockPos pos, int id, int param) {
super.eventReceived(state, worldIn, pos, id, param);
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity == null ? false : tileentity.receiveClientEvent(id, param);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
*/
package com.someguyssoftware.gottschcore.eventhandler;

import net.minecraft.util.text.TextFormatting;

import com.someguyssoftware.gottschcore.GottschCore;
import com.someguyssoftware.gottschcore.config.IConfig;
import com.someguyssoftware.gottschcore.mod.IMod;
import com.someguyssoftware.gottschcore.version.BuildVersion;
import com.someguyssoftware.gottschcore.version.VersionChecker;

import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
Expand Down Expand Up @@ -63,17 +62,31 @@ public void checkVersionOnLogIn(PlayerEvent.PlayerLoggedInEvent event) {

// get the latest version recorded in the config
BuildVersion configVersion = new BuildVersion(mod.getConfig().getLatestVersion());

boolean isCurrent = VersionChecker.checkVersion(mod.getModLatestVersion(), new BuildVersion(mod.getClass().getAnnotation(Mod.class).version()));
boolean isConfigCurrent = VersionChecker.checkVersion(mod.getModLatestVersion(), configVersion);
boolean isReminderOn = mod.getConfig().isLatestVersionReminder();
boolean isCurrent = false;

// update the config to the latest client version if it is not set already
if (!isConfigCurrent) {
// update config
mod.getConfig().setProperty(IConfig.MOD_CATEGORY, "latestVersion", mod.getModLatestVersion().toString());
// turn the reminder back on for the latest version
mod.getConfig().setProperty(IConfig.MOD_CATEGORY, "latestVersionReminder", true);
}

if (mod.getUpdateURL() != null && !mod.getUpdateURL().equals("")) {
// use Forge update method
try {
isCurrent = VersionChecker.checkVersionUsingForge(mod.getModLatestVersion(), new BuildVersion(mod.getClass().getAnnotation(Mod.class).version()));
}
catch(Exception e) {
GottschCore.logger.error("Unable to determine version using Forge:", e);
isCurrent = VersionChecker.checkVersion(mod.getModLatestVersion(), new BuildVersion(mod.getClass().getAnnotation(Mod.class).version()));
}
}
else {
isCurrent = VersionChecker.checkVersion(mod.getModLatestVersion(), new BuildVersion(mod.getClass().getAnnotation(Mod.class).version()));
}

if (!isCurrent && isReminderOn) {
StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ public void postInit(FMLPostInitializationEvent event) {
// check config if version check is enabled
if (getConfig().isEnableVersionChecker()) {
// get the latest version from the website
setModLatestVersion(VersionChecker.getVersion(getVerisionURL(), getMinecraftVersion()));
BuildVersion buildVersion = null;
// check if updateURL is set. if so, use the forge versioning to get the latest version
if (this.getUpdateURL() != null && !this.getUpdateURL().equals("")) {
buildVersion = VersionChecker.getVersionUsingForge(this);
}

if (buildVersion == null || buildVersion == BuildVersion.EMPTY_VERSION) {
buildVersion = VersionChecker.getVersion(getVersionURL(), getMinecraftVersion());
}
setModLatestVersion(buildVersion);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,22 @@ public interface IMod {
*/
public BuildVersion getMinecraftVersion();

public String getVerisionURL();
/**
* By default calls deprecated getVerisionURL() to maintain backwards-compatibility.
* @return
*/
public default String getVersionURL() {
return getVerisionURL();
}

/**
* @deprecated use getVersionURL() instead.
* @return
*/
@Deprecated()
public default String getVerisionURL() {
return null;
}

/**
* Get the instance of the mod
Expand All @@ -60,4 +75,11 @@ public interface IMod {
*/
public String getVersion();


/**
* The Forge update URL of the mod.
*/
public default String getUpdateURL() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
*
*/
package com.someguyssoftware.gottschcore.tileentity;

import javax.annotation.Nullable;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

/**
* @author Mark Gottschling onJan 3, 2018
*
*/
public abstract class AbstractModTileEntity extends TileEntity {

/**
*
*/
@Override
@Nullable
public SPacketUpdateTileEntity getUpdatePacket() {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
writeToNBT(nbtTagCompound);
int metadata = getBlockMetadata();
return new SPacketUpdateTileEntity(this.pos, metadata, nbtTagCompound);
}

/**
*
*/
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
readFromNBT(pkt.getNbtCompound());
}

/* Creates a tag containing the TileEntity information, used by vanilla to transmit from server to client
*/
@Override
public NBTTagCompound getUpdateTag() {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
writeToNBT(nbtTagCompound);
return nbtTagCompound;
}

/* Populates this TileEntity with information from the tag, used by vanilla to transmit from server to client
*/
@Override
public void handleUpdateTag(NBTTagCompound tag) {
this.readFromNBT(tag);
}
}
Loading

0 comments on commit 5618b41

Please sign in to comment.