This commit is contained in:
JackCarterSmith 2018-11-09 19:04:31 +01:00
parent 1e36d67c02
commit 2384cc0d6b
26 changed files with 2242 additions and 15 deletions

View File

@ -1,8 +1,5 @@
import groovy.json.JsonOutput
def mainVersion = "0.1"
def buildNumber = "1"
buildscript {
repositories {
jcenter()
@ -16,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
version = "${mainVersion}-${buildNumber}"
version = "0.1.3"
//group = "fr.jackcartersmith.orbsat" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
group = "jackcartersmith"
def archiveGroup = group
@ -123,3 +120,20 @@ processResources {
exclude "mcmod.info"
}
}
task signJar(type: SignJar, dependsOn: reobfJar) {
onlyIf { // Skip the task if our secret data isn't available
project.hasProperty('keyStore')
}
dependsOn reobfJar
if (project.hasProperty('keyStore')) { // This needs to be a path to the keystore file
keyStore = project.keyStore
alias = project.keyStoreAlias
storePass = project.keyStorePass
keyPass = project.keyStoreKeyPass
inputFile = jar.archivePath
outputFile = jar.archivePath
}
}
build.dependsOn signJar

View File

@ -1,20 +1,36 @@
package jackcartersmith.orbsat;
import jackcartersmith.orbsat.common.util.ConfigManager;
import jackcartersmith.orbsat.common.CommonProxy;
import jackcartersmith.orbsat.common.EventHandler;
import jackcartersmith.orbsat.common.OrbsatContents;
import jackcartersmith.orbsat.common.OrbsatSaveData;
import jackcartersmith.orbsat.common.commands.CommandHandler;
import jackcartersmith.orbsat.common.compat.OrbsatCompatModule;
import jackcartersmith.orbsat.common.util.LogHelper;
import jackcartersmith.orbsat.common.util.network.MessageRequestBlockUpdate;
import jackcartersmith.orbsat.common.util.network.MessageTileSync;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent;
import net.minecraftforge.fml.common.event.FMLModIdMappingEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartedEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = OrbitalSatellite.MODID, name = OrbitalSatellite.NAME, version = OrbitalSatellite.VERSION, dependencies = "required-after:forge@[14.23.5.2768,)")
@Mod(modid = OrbitalSatellite.MODID, name = OrbitalSatellite.NAME, version = OrbitalSatellite.VERSION, modLanguage = "java",
certificateFingerprint = "3ce4f2265ef35e83d8d32f87fa6394a56e9b0e49", dependencies = "required-after:forge@[14.23.5.2768,)")
public class OrbitalSatellite {
public static final String MODID = "orbsat";
public static final String NAME = "Orbital Satellite";
@ -27,25 +43,94 @@ public class OrbitalSatellite {
public static final SimpleNetworkWrapper packetHandler = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
@EventHandler
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
LogHelper.logger = event.getModLog();
ConfigManager.preInit(event);
proxy.init();
OrbsatContents.preInit();
//IEAdvancements.preInit();
OrbsatCompatModule.doModulesPreInit();
}
@EventHandler
@Mod.EventHandler
public void init(FMLInitializationEvent event)
{
// some example code
LogHelper.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
proxy.preInitEnd();
OrbsatContents.init();
MinecraftForge.EVENT_BUS.register(new EventHandler());
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
proxy.init();
//IESounds.init();
OrbsatCompatModule.doModulesInit();
proxy.initEnd();
int messageId = 0;
packetHandler.registerMessage(MessageTileSync.HandlerServer.class, MessageTileSync.class, messageId++, Side.SERVER);
packetHandler.registerMessage(MessageTileSync.HandlerClient.class, MessageTileSync.class, messageId++, Side.CLIENT);
packetHandler.registerMessage(MessageRequestBlockUpdate.Handler.class, MessageRequestBlockUpdate.class, messageId++, Side.SERVER);
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event)
{
OrbsatContents.postInit();
proxy.postInit();
OrbsatCompatModule.doModulesPostInit();
proxy.postInitEnd();
}
@Mod.EventHandler
public void loadComplete(FMLLoadCompleteEvent event)
{
OrbsatCompatModule.doModulesLoadComplete();
}
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event)
{
proxy.serverStarting();
event.registerServerCommand(new CommandHandler(false));
}
@Mod.EventHandler
public void serverStarted(FMLServerStartedEvent event)
{
if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)
{
World world = FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld();
if(!world.isRemote)
{
LogHelper.info("WorldData loading");
/*
//Clear out any info from previous worlds
for(int dim : ImmersiveNetHandler.INSTANCE.getRelevantDimensions())
ImmersiveNetHandler.INSTANCE.clearAllConnections(dim);
*/
OrbsatSaveData worldData = (OrbsatSaveData)world.loadData(OrbsatSaveData.class, OrbsatSaveData.dataName);
if(worldData==null)
{
LogHelper.info("WorldData not found");
worldData = new OrbsatSaveData(OrbsatSaveData.dataName);
world.setData(OrbsatSaveData.dataName, worldData);
}
else
LogHelper.info("WorldData retrieved");
OrbsatSaveData.setInstance(world.provider.getDimension(), worldData);
}
}
}
@Mod.EventHandler
public void modIDMapping(FMLModIdMappingEvent event) {}
public static CreativeTabs creativeTab = new CreativeTabs(MODID)
{
@Override
@ -61,4 +146,10 @@ public class OrbitalSatellite {
return new ItemStack(IEContent.blockMetalDecoration0, 1, 0);
}*/
};
@Mod.EventHandler
public void wrongSignature(FMLFingerprintViolationEvent event)
{
System.out.println("[OrbSat/Error] THIS IS NOT AN OFFICIAL BUILD OF ORBITAL SATELLITE! Found these fingerprints: "+event.getFingerprints());
}
}

View File

@ -6,5 +6,5 @@ import net.minecraftforge.fml.relauncher.Side;
@Mod.EventBusSubscriber(Side.CLIENT)
public class ClientProxy extends CommonProxy{
//public static IEItemFontRender itemFont;
}

View File

@ -0,0 +1,181 @@
package jackcartersmith.orbsat.client;
import java.util.ArrayList;
import java.util.HashMap;
import jackcartersmith.orbsat.common.util.Lib;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Timer;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.text.TextFormatting;
public class ClientUtils {
public static final AxisAlignedBB standardBlockAABB = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
static HashMap<String, ResourceLocation> resourceMap = new HashMap<String, ResourceLocation>();
public static TextureAtlasSprite[] destroyBlockIcons = new TextureAtlasSprite[10];
public static Tessellator tes()
{
return Tessellator.getInstance();
}
public static Minecraft mc()
{
return Minecraft.getMinecraft();
}
public static void bindTexture(String path)
{
mc().getTextureManager().bindTexture(getResource(path));
}
public static void bindAtlas()
{
mc().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
}
public static ResourceLocation getResource(String path)
{
ResourceLocation rl = resourceMap.containsKey(path)?resourceMap.get(path): new ResourceLocation(path);
if(!resourceMap.containsKey(path))
resourceMap.put(path, rl);
return rl;
}
public static TextureAtlasSprite getSprite(ResourceLocation rl)
{
return mc().getTextureMapBlocks().getAtlasSprite(rl.toString());
}
public static FontRenderer font()
{
return mc().fontRenderer;
}
public static Timer timer()
{
return mc().timer;
}
public enum TimestampFormat
{
D,
H,
M,
S,
MS,
HMS,
HM,
DHMS,
DHM,
DH;
static TimestampFormat[] coreValues = {TimestampFormat.D, TimestampFormat.H, TimestampFormat.M, TimestampFormat.S};
public boolean containsFormat(TimestampFormat format)
{
return this.toString().contains(format.toString());
}
public long getTickCut()
{
return this==D?1728000L: this==H?72000L: this==M?1200L: this==S?20L: 1;
}
public String getLocalKey()
{
return this==D?"day": this==H?"hour": this==M?"minute": this==S?"second": "";
}
}
public static String fomatTimestamp(long timestamp, TimestampFormat format)
{
String s = "";
for(TimestampFormat core : TimestampFormat.coreValues)
if(format.containsFormat(core)&&timestamp >= core.getTickCut())
{
s += I18n.format(Lib.DESC_INFO+core.getLocalKey(), Long.toString(timestamp/core.getTickCut()));
timestamp %= core.getTickCut();
}
if(s.isEmpty())
for(int i = TimestampFormat.coreValues.length-1; i >= 0; i--)
if(format.containsFormat(TimestampFormat.coreValues[i]))
{
s = I18n.format(Lib.DESC_INFO+TimestampFormat.coreValues[i].getLocalKey(), 0);
break;
}
return s;
}
static int[] chatColours = {
0x000000,//BLACK
0x0000AA,//DARK_BLUE
0x00AA00,//DARK_GREEN
0x00AAAA,//DARK_AQUA
0xAA0000,//DARK_RED
0xAA00AA,//DARK_PURPLE
0xFFAA00,//GOLD
0xAAAAAA,//GRAY
0x555555,//DARK_GRAY
0x5555FF,//BLUE
0x55FF55,//GREEN
0x55FFFF,//AQUA
0xFF5555,//RED
0xFF55FF,//LIGHT_PURPLE
0xFFFF55,//YELLOW
0xFFFFFF//WHITE
};
public static int getFormattingColour(TextFormatting color)
{
return color.ordinal() < 16?chatColours[color.ordinal()]: 0;
}
public static int getDarkenedTextColour(int colour)
{
int r = (colour >> 16&255)/4;
int g = (colour >> 8&255)/4;
int b = (colour&255)/4;
return r<<16|g<<8|b;
}
public static ModelRenderer[] copyModelRenderers(ModelBase model, ModelRenderer... oldRenderers)
{
ModelRenderer[] newRenderers = new ModelRenderer[oldRenderers.length];
for(int i = 0; i < newRenderers.length; i++)
if(oldRenderers[i]!=null)
{
newRenderers[i] = new ModelRenderer(model, oldRenderers[i].boxName);
int toX = oldRenderers[i].textureOffsetX;
int toY = oldRenderers[i].textureOffsetY;
newRenderers[i].setTextureOffset(toX, toY);
newRenderers[i].mirror = oldRenderers[i].mirror;
ArrayList<ModelBox> newCubes = new ArrayList<ModelBox>();
for(ModelBox cube : oldRenderers[i].cubeList)
newCubes.add(new ModelBox(newRenderers[i], toX, toY, cube.posX1, cube.posY1, cube.posZ1, (int)(cube.posX2-cube.posX1), (int)(cube.posY2-cube.posY1), (int)(cube.posZ2-cube.posZ1), 0));
newRenderers[i].cubeList = newCubes;
newRenderers[i].setRotationPoint(oldRenderers[i].rotationPointX, oldRenderers[i].rotationPointY, oldRenderers[i].rotationPointZ);
newRenderers[i].rotateAngleX = oldRenderers[i].rotateAngleX;
newRenderers[i].rotateAngleY = oldRenderers[i].rotateAngleY;
newRenderers[i].rotateAngleZ = oldRenderers[i].rotateAngleZ;
newRenderers[i].offsetX = oldRenderers[i].offsetX;
newRenderers[i].offsetY = oldRenderers[i].offsetY;
newRenderers[i].offsetZ = oldRenderers[i].offsetZ;
}
return newRenderers;
}
}

View File

@ -1,7 +1,13 @@
package jackcartersmith.orbsat.common;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.IGuiHandler;
public class CommonProxy implements IGuiHandler {
@ -187,6 +193,7 @@ public class CommonProxy implements IGuiHandler {
public void drawFluidPumpTop()
{
}
*/
public String[] splitStringOnWidth(String s, int w)
{
@ -227,5 +234,4 @@ public class CommonProxy implements IGuiHandler {
public void clearRenderCaches()
{
}
*/
}

View File

@ -0,0 +1,61 @@
package jackcartersmith.orbsat.common;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
import org.apache.commons.lang3.tuple.Pair;
import jackcartersmith.orbsat.OrbitalSatellite;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent;
public class EventHandler {
//public static final ArrayList<ISpawnInterdiction> interdictionTiles = new ArrayList<ISpawnInterdiction>();
//public static HashSet<IEExplosion> currentExplosions = new HashSet<IEExplosion>();
public static final Queue<Pair<Integer, BlockPos>> requestedBlockUpdates = new LinkedList<>();
public static final Set<TileEntity> REMOVE_FROM_TICKING = new HashSet<>();
@SubscribeEvent
public void onLoad(WorldEvent.Load event)
{
OrbitalSatellite.proxy.onWorldLoad();
}
@SubscribeEvent
public void onSave(WorldEvent.Save event)
{
OrbsatSaveData.setDirty(0);
}
@SubscribeEvent
public void onUnload(WorldEvent.Unload event)
{
OrbsatSaveData.setDirty(0);
}
@SubscribeEvent
public void onWorldTick(WorldTickEvent event)
{
}
@SubscribeEvent(priority = EventPriority.HIGH)
public void onLogin(PlayerLoggedInEvent event)
{
}
@SubscribeEvent(priority = EventPriority.HIGH)
public void onLogout(PlayerLoggedOutEvent event)
{
}
}

View File

@ -0,0 +1,100 @@
package jackcartersmith.orbsat.common;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import jackcartersmith.orbsat.OrbitalSatellite;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings.Mapping;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;
@Mod.EventBusSubscriber
public class OrbsatContents {
public static ArrayList<Block> registeredOrbsatBlocks = new ArrayList<Block>();
public static ArrayList<Item> registeredOrbsatItems = new ArrayList<Item>();
public static List<Class<? extends TileEntity>> registeredOrbsatTiles = new ArrayList<>();
@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event)
{
for(Block block : registeredOrbsatBlocks)
event.getRegistry().register(block.setRegistryName(createRegistryName(block.getTranslationKey())));
}
@SubscribeEvent
public static void registerItems(RegistryEvent.Register<Item> event)
{
for(Item item : registeredOrbsatItems)
event.getRegistry().register(item.setRegistryName(createRegistryName(item.getTranslationKey())));
//registerOres();
}
@SubscribeEvent
public static void missingItems(RegistryEvent.MissingMappings<Item> event)
{
Set<String> knownMissing = ImmutableSet.of(
"fluidethanol",
"fluidconcrete",
"fluidbiodiesel",
"fluidplantoil",
"fluidcreosote"
);
for(Mapping<Item> missing : event.getMappings())
if(knownMissing.contains(missing.key.getPath()))
missing.ignore();
}
@SubscribeEvent
public static void registerRecipes(RegistryEvent.Register<IRecipe> event)
{
}
private static ResourceLocation createRegistryName(String unlocalized)
{
unlocalized = unlocalized.substring(unlocalized.indexOf("orbsat"));
unlocalized = unlocalized.replaceFirst("\\.", ":");
return new ResourceLocation(unlocalized);
}
public static void registerTile(Class<? extends TileEntity> tile)
{
String s = tile.getSimpleName();
s = s.substring(s.indexOf("TileEntity")+"TileEntity".length());
GameRegistry.registerTileEntity(tile, OrbitalSatellite.MODID+":"+s);
//registeredIETiles.add(tile);
}
public static void preInit(){
}
public static void init(){
}
public static void postInit(){
}
}

View File

@ -0,0 +1,45 @@
package jackcartersmith.orbsat.common;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.storage.WorldSavedData;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
public class OrbsatSaveData extends WorldSavedData {
private static OrbsatSaveData INSTANCE;
public static final String dataName = "OrbitalSatellite-SaveData";
public OrbsatSaveData(String name) {
super(name);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
// TODO Auto-generated method stub
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
// TODO Auto-generated method stub
return null;
}
public static void setDirty(int dimension)
{
// if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER && INSTANCE.get(dimension)!=null)
// {
// INSTANCE.get(dimension).markDirty();
// }
if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER&&INSTANCE!=null)
INSTANCE.markDirty();
}
public static void setInstance(int dimension, OrbsatSaveData in)
{
// if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)
// INSTANCE.put(dimension, in);
if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)
INSTANCE = in;
}
}

View File

@ -0,0 +1,236 @@
package jackcartersmith.orbsat.common.blocks;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.Sets;
import jackcartersmith.orbsat.OrbitalSatellite;
import jackcartersmith.orbsat.common.OrbsatContents;
import jackcartersmith.orbsat.common.blocks.OrbsatBlockInterface.IOrbsatMetaBlock;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockOrbsatBase<E extends Enum<E> & BlockOrbsatBase.IBlockEnum> extends Block implements IOrbsatMetaBlock{
public final String name;
public final PropertyEnum<E> property;
protected static IProperty[] tempProperties;
protected static IUnlistedProperty[] tempUnlistedProperties;
public final IProperty[] additionalProperties;
public final IUnlistedProperty[] additionalUnlistedProperties;
public final E[] enumValues;
boolean[] isMetaHidden;
boolean[] hasFlavour;
protected Set<BlockRenderLayer> renderLayers = Sets.newHashSet(BlockRenderLayer.SOLID);
protected Set<BlockRenderLayer>[] metaRenderLayers;
protected Map<Integer, Integer> metaLightOpacities = new HashMap<>();
protected Map<Integer, Float> metaHardness = new HashMap<>();
protected Map<Integer, Integer> metaResistances = new HashMap<>();
//protected EnumPushReaction[] metaMobilityFlags;
//protected boolean[] canHammerHarvest;
protected boolean[] metaNotNormalBlock;
private boolean opaqueCube = false;
public BlockOrbsatBase(String name, Material material, PropertyEnum<E> mainProperty, Class<? extends ItemBlockOrbsatBase> itemBlock, Object... additionalProperties)
{
super(setTempProperties(material, mainProperty, additionalProperties));
this.name = name;
this.property = mainProperty;
this.enumValues = mainProperty.getValueClass().getEnumConstants();
this.isMetaHidden = new boolean[this.enumValues.length];
this.hasFlavour = new boolean[this.enumValues.length];
this.metaRenderLayers = new Set[this.enumValues.length];
//this.canHammerHarvest = new boolean[this.enumValues.length];
//this.metaMobilityFlags = new EnumPushReaction[this.enumValues.length];
ArrayList<IProperty> propList = new ArrayList<IProperty>();
ArrayList<IUnlistedProperty> unlistedPropList = new ArrayList<IUnlistedProperty>();
for(Object o : additionalProperties)
{
if(o instanceof IProperty)
propList.add((IProperty)o);
if(o instanceof IProperty[])
for(IProperty p : ((IProperty[])o))
propList.add(p);
if(o instanceof IUnlistedProperty)
unlistedPropList.add((IUnlistedProperty)o);
if(o instanceof IUnlistedProperty[])
for(IUnlistedProperty p : ((IUnlistedProperty[])o))
unlistedPropList.add(p);
}
this.additionalProperties = propList.toArray(new IProperty[propList.size()]);
this.additionalUnlistedProperties = unlistedPropList.toArray(new IUnlistedProperty[unlistedPropList.size()]);
this.setDefaultState(getInitDefaultState());
String registryName = createRegistryName();
this.setTranslationKey(registryName.replace(':', '.'));
this.setCreativeTab(OrbitalSatellite.creativeTab);
this.adjustSound();
// ImmersiveEngineering.registerBlockByFullName(this, itemBlock, registryName);
OrbsatContents.registeredOrbsatBlocks.add(this);
try
{
OrbsatContents.registeredOrbsatItems.add(itemBlock.getConstructor(Block.class).newInstance(this));
} catch(Exception e)
{
e.printStackTrace();
}
lightOpacity = 255;
}
public interface IBlockEnum extends IStringSerializable
{
int getMeta();
boolean listForCreative();
}
@Override
public String getOrbsatBlockName() {
return this.name;
}
@Override
public Enum[] getMetaEnums() {
return enumValues;
}
@Override
public IBlockState getInventoryState(int meta) {
return getStateFromMeta(meta);
}
@Override
public PropertyEnum<E> getMetaProperty()
{
return this.property;
}
@Override
public boolean useCustomStateMapper()
{
return false;
}
@Override
public String getCustomStateMapping(int meta, boolean itemBlock)
{
return null;
}
@Override
@SideOnly(Side.CLIENT)
public StateMapperBase getCustomMapper()
{
return null;
}
@Override
public boolean appendPropertiesToState()
{
return true;
}
public String getTranslationKey(ItemStack stack)
{
String subName = getStateFromMeta(stack.getItemDamage()).getValue(property).toString().toLowerCase(Locale.US);
return super.getTranslationKey()+"."+subName;
}
void adjustSound()
{
if(this.material==Material.ANVIL)
this.blockSoundType = SoundType.ANVIL;
else if(this.material==Material.CARPET||this.material==Material.CLOTH)
this.blockSoundType = SoundType.CLOTH;
else if(this.material==Material.GLASS||this.material==Material.ICE)
this.blockSoundType = SoundType.GLASS;
else if(this.material==Material.GRASS||this.material==Material.TNT||this.material==Material.PLANTS||this.material==Material.VINE)
this.blockSoundType = SoundType.PLANT;
else if(this.material==Material.GROUND)
this.blockSoundType = SoundType.GROUND;
else if(this.material==Material.IRON)
this.blockSoundType = SoundType.METAL;
else if(this.material==Material.SAND)
this.blockSoundType = SoundType.SAND;
else if(this.material==Material.SNOW)
this.blockSoundType = SoundType.SNOW;
else if(this.material==Material.ROCK)
this.blockSoundType = SoundType.STONE;
else if(this.material==Material.WOOD||this.material==Material.CACTUS)
this.blockSoundType = SoundType.WOOD;
}
protected static Material setTempProperties(Material material, PropertyEnum<?> property, Object... additionalProperties)
{
ArrayList<IProperty> propList = new ArrayList<IProperty>();
ArrayList<IUnlistedProperty> unlistedPropList = new ArrayList<IUnlistedProperty>();
propList.add(property);
for(Object o : additionalProperties)
{
if(o instanceof IProperty)
propList.add((IProperty)o);
if(o instanceof IProperty[])
for(IProperty p : ((IProperty[])o))
propList.add(p);
if(o instanceof IUnlistedProperty)
unlistedPropList.add((IUnlistedProperty)o);
if(o instanceof IUnlistedProperty[])
for(IUnlistedProperty p : ((IUnlistedProperty[])o))
unlistedPropList.add(p);
}
tempProperties = propList.toArray(new IProperty[propList.size()]);
tempUnlistedProperties = unlistedPropList.toArray(new IUnlistedProperty[unlistedPropList.size()]);
return material;
}
protected IBlockState getInitDefaultState()
{
IBlockState state = this.blockState.getBaseState().withProperty(this.property, enumValues[0]);
for(int i = 0; i < this.additionalProperties.length; i++)
if(this.additionalProperties[i]!=null&&!this.additionalProperties[i].getAllowedValues().isEmpty())
state = applyProperty(state, additionalProperties[i], additionalProperties[i].getAllowedValues().iterator().next());
return state;
}
protected <V extends Comparable<V>> IBlockState applyProperty(IBlockState in, IProperty<V> prop, Object val)
{
return in.withProperty(prop, (V)val);
}
public void onOrbsatBlockPlacedBy(World world, BlockPos pos, IBlockState state, EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase placer, ItemStack stack)
{
}
public boolean canOrbsatBlockBePlaced(World world, BlockPos pos, IBlockState newState, EnumFacing side, float hitX, float hitY, float hitZ, EntityPlayer player, ItemStack stack)
{
return true;
}
public String createRegistryName()
{
return OrbitalSatellite.MODID+":"+name;
}
}

View File

@ -0,0 +1,158 @@
package jackcartersmith.orbsat.common.blocks;
import javax.annotation.Nullable;
import jackcartersmith.orbsat.client.ClientProxy;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBlockOrbsatBase extends ItemBlock {
private int[] burnTime;
public ItemBlockOrbsatBase(Block block) {
super(block);
if(((BlockOrbsatBase)block).enumValues.length > 1)
setHasSubtypes(true);
this.burnTime = new int[((BlockOrbsatBase)block).enumValues!=null?((BlockOrbsatBase)block).enumValues.length: 1];
}
@Override
public int getMetadata(int damageValue)
{
return damageValue;
}
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> itemList)
{
if(this.isInCreativeTab(tab))
this.block.getSubBlocks(tab, itemList);
}
@Override
public String getTranslationKey(ItemStack stack)
{
return ((BlockOrbsatBase)this.block).getTranslationKey(stack);
}
public ItemBlockOrbsatBase setBurnTime(int meta, int burnTime)
{
if(meta >= 0&&meta < this.burnTime.length)
this.burnTime[meta] = burnTime;
return this;
}
@Override
public int getItemBurnTime(ItemStack itemStack)
{
return this.burnTime[Math.max(0, Math.min(itemStack.getMetadata(), this.burnTime.length-1))];
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
{
if(!((BlockOrbsatBase)this.block).canOrbsatBlockBePlaced(world, pos, newState, side, hitX, hitY, hitZ, player, stack))
return false;
boolean ret = super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState);
if(ret)
{
((BlockOrbsatBase)this.block).onOrbsatBlockPlacedBy(world, pos, newState, side, hitX, hitY, hitZ, player, stack);
}
return ret;
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
ItemStack stack = player.getHeldItem(hand);
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if(!block.isReplaceable(world, pos))
pos = pos.offset(side);
if(stack.getCount() > 0&&player.canPlayerEdit(pos, side, stack)&&canBlockBePlaced(world, pos, side, stack))
{
int i = this.getMetadata(stack.getMetadata());
IBlockState iblockstate1 = this.block.getStateForPlacement(world, pos, side, hitX, hitY, hitZ, i, player);
if(placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, iblockstate1))
{
SoundType soundtype = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume()+1.0F)/2.0F, soundtype.getPitch()*0.8F);
if(!player.capabilities.isCreativeMode)
stack.shrink(1);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}
@Override
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
{
Block block = worldIn.getBlockState(pos).getBlock();
if(block==Blocks.SNOW_LAYER&&block.isReplaceable(worldIn, pos))
{
side = EnumFacing.UP;
}
else if(!block.isReplaceable(worldIn, pos))
{
pos = pos.offset(side);
}
return canBlockBePlaced(worldIn, pos, side, stack);
}
private boolean canBlockBePlaced(World w, BlockPos pos, EnumFacing side, ItemStack stack)
{
BlockOrbsatBase blockIn = (BlockOrbsatBase)this.block;
Block block = w.getBlockState(pos).getBlock();
AxisAlignedBB axisalignedbb = blockIn.getCollisionBoundingBox(blockIn.getStateFromMeta(stack.getItemDamage()), w, pos);
if(axisalignedbb!=null&&!w.checkNoEntityCollision(axisalignedbb.offset(pos), null)) return false;
return block.isReplaceable(w, pos)&&blockIn.canPlaceBlockOnSide(w, pos, side);
}
public static class ItemBlockIENoInventory extends ItemBlockOrbsatBase
{
public ItemBlockIENoInventory(Block b)
{
super(b);
}
@Nullable
@Override
public NBTTagCompound getNBTShareTag(ItemStack stack)
{
NBTTagCompound ret = super.getNBTShareTag(stack);
if(ret!=null)
{
ret = ret.copy();
ret.removeTag("inventory");
}
return ret;
}
@Override
public boolean getShareTag()
{
return super.getShareTag();
}
}
}

View File

@ -0,0 +1,363 @@
package jackcartersmith.orbsat.common.blocks;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Nullable;
import jackcartersmith.orbsat.common.util.OrbsatEnums;
import jackcartersmith.orbsat.common.util.OrbsatProperties.PropertyBoolInverted;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.model.obj.OBJModel.OBJState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class OrbsatBlockInterface {
public interface IOrbsatMetaBlock
{
String getOrbsatBlockName();
IProperty getMetaProperty();
Enum[] getMetaEnums();
IBlockState getInventoryState(int meta);
boolean useCustomStateMapper();
String getCustomStateMapping(int meta, boolean itemBlock);
@SideOnly(Side.CLIENT)
StateMapperBase getCustomMapper();
boolean appendPropertiesToState();
}
public interface IAttachedIntegerProperies
{
String[] getIntPropertyNames();
PropertyInteger getIntProperty(String name);
int getIntPropertyValue(String name);
default void setValue(String name, int value)
{
}
}
public interface IUsesBooleanProperty
{
PropertyBoolInverted getBoolProperty(Class<? extends IUsesBooleanProperty> inf);
}
public interface IBlockOverlayText
{
String[] getOverlayText(EntityPlayer player, RayTraceResult mop, boolean hammer);
boolean useNixieFont(EntityPlayer player, RayTraceResult mop);
}
public interface ISoundTile
{
boolean shoudlPlaySound(String sound);
}
public interface ISpawnInterdiction
{
double getInterdictionRangeSquared();
}
public interface IComparatorOverride
{
int getComparatorInputOverride();
}
public interface IRedstoneOutput
{
default int getWeakRSOutput(IBlockState state, EnumFacing side)
{
return getStrongRSOutput(state, side);
}
int getStrongRSOutput(IBlockState state, EnumFacing side);
boolean canConnectRedstone(IBlockState state, EnumFacing side);
}
public interface ILightValue
{
int getLightValue();
}
public interface IColouredBlock
{
boolean hasCustomBlockColours();
int getRenderColour(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex);
}
public interface IColouredTile
{
int getRenderColour(int tintIndex);
}
public interface IDirectionalTile
{
EnumFacing getFacing();
void setFacing(EnumFacing facing);
/**
* @return 0 = side clicked, 1=piston behaviour, 2 = horizontal, 3 = vertical, 4 = x/z axis, 5 = horizontal based on quadrant, 6 = horizontal preferring clicked side
*/
int getFacingLimitation();
default EnumFacing getFacingForPlacement(EntityLivingBase placer, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
EnumFacing f = EnumFacing.DOWN;
int limit = getFacingLimitation();
if(limit==0)
f = side;
else if(limit==1)
f = EnumFacing.getDirectionFromEntityLiving(pos, placer);
else if(limit==2)
f = EnumFacing.fromAngle(placer.rotationYaw);
else if(limit==3)
f = (side!=EnumFacing.DOWN&&(side==EnumFacing.UP||hitY <= .5))?EnumFacing.UP: EnumFacing.DOWN;
else if(limit==4)
{
f = EnumFacing.fromAngle(placer.rotationYaw);
if(f==EnumFacing.SOUTH||f==EnumFacing.WEST)
f = f.getOpposite();
}
else if(limit==5)
{
if(side.getAxis()!=Axis.Y)
f = side.getOpposite();
else
{
float xFromMid = hitX-.5f;
float zFromMid = hitZ-.5f;
float max = Math.max(Math.abs(xFromMid), Math.abs(zFromMid));
if(max==Math.abs(xFromMid))
f = xFromMid < 0?EnumFacing.WEST: EnumFacing.EAST;
else
f = zFromMid < 0?EnumFacing.NORTH: EnumFacing.SOUTH;
}
}
else if(limit==6)
f = side.getAxis()!=Axis.Y?side.getOpposite(): placer.getHorizontalFacing();
return mirrorFacingOnPlacement(placer)?f.getOpposite(): f;
}
boolean mirrorFacingOnPlacement(EntityLivingBase placer);
boolean canHammerRotate(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase entity);
boolean canRotate(EnumFacing axis);
default void afterRotation(EnumFacing oldDir, EnumFacing newDir)
{
}
}
public interface IAdvancedDirectionalTile extends IDirectionalTile
{
void onDirectionalPlacement(EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase placer);
}
public interface IConfigurableSides
{
OrbsatEnums.SideConfig getSideConfig(int side);
boolean toggleSide(int side, EntityPlayer p);
}
public interface ITileDrop
{
/**
* Don't call this on generic TE'S, use getTileDrops or getPickBlock
*/
default ItemStack getTileDrop(@Nullable EntityPlayer player, IBlockState state)
{
NonNullList<ItemStack> drops = getTileDrops(player, state);
return drops.size() > 0?drops.get(0): ItemStack.EMPTY;
}
default NonNullList<ItemStack> getTileDrops(@Nullable EntityPlayer player, IBlockState state)
{
return NonNullList.from(ItemStack.EMPTY, getTileDrop(player, state));
}
default ItemStack getPickBlock(@Nullable EntityPlayer player, IBlockState state, RayTraceResult rayRes)
{
return getTileDrop(player, state);
}
void readOnPlacement(@Nullable EntityLivingBase placer, ItemStack stack);
default boolean preventInventoryDrop()
{
return false;
}
}
public interface IAdditionalDrops
{
Collection<ItemStack> getExtraDrops(EntityPlayer player, IBlockState state);
}
public interface IEntityProof
{
boolean canEntityDestroy(Entity entity);
}
public interface IPlayerInteraction
{
boolean interact(EnumFacing side, EntityPlayer player, EnumHand hand, ItemStack heldItem, float hitX, float hitY, float hitZ);
}
public interface IHammerInteraction
{
boolean hammerUseSide(EnumFacing side, EntityPlayer player, float hitX, float hitY, float hitZ);
}
/*
public interface IActiveState extends IUsesBooleanProperty
{
boolean getIsActive();
}
public interface IDualState extends IUsesBooleanProperty
{
boolean getIsSecondState();
}
public interface IMirrorAble extends IUsesBooleanProperty
{
boolean getIsMirrored();
}
*/
public interface IBlockBounds
{
float[] getBlockBounds();
}
public interface IFaceShape
{
BlockFaceShape getFaceShape(EnumFacing side);
}
public interface IAdvancedSelectionBounds extends IBlockBounds
{
List<AxisAlignedBB> getAdvancedSelectionBounds();
boolean isOverrideBox(AxisAlignedBB box, EntityPlayer player, RayTraceResult mop, ArrayList<AxisAlignedBB> list);
}
public interface IAdvancedCollisionBounds extends IBlockBounds
{
List<AxisAlignedBB> getAdvancedColisionBounds();
}
public interface IHasDummyBlocks extends IGeneralMultiblock
{
void placeDummies(BlockPos pos, IBlockState state, EnumFacing side, float hitX, float hitY, float hitZ);
void breakDummies(BlockPos pos, IBlockState state);
boolean isDummy();
@Override
default boolean isLogicDummy()
{
return isDummy();
}
}
/**
* super-interface for {@link TileEntityMultiblockPart} and {@link IHasDummyBlocks}
*/
public interface IGeneralMultiblock
{
boolean isLogicDummy();
}
public interface IHasObjProperty
{
ArrayList<String> compileDisplayList();
}
public interface IAdvancedHasObjProperty
{
OBJState getOBJState();
}
public interface IDynamicTexture
{
@SideOnly(Side.CLIENT)
HashMap<String, String> getTextureReplacements();
}
public interface IGuiTile
{
default boolean canOpenGui(EntityPlayer player)
{
return canOpenGui();
}
boolean canOpenGui();
int getGuiID();
@Nullable
TileEntity getGuiMaster();
default void onGuiOpened(EntityPlayer player, boolean clientside)
{
}
}
public interface IProcessTile
{
int[] getCurrentProcessesStep();
int[] getCurrentProcessesMax();
}
public interface INeighbourChangeTile
{
void onNeighborBlockChange(BlockPos otherPos);
}
public interface IPropertyPassthrough
{
}
public interface ICacheData
{
Object[] getCacheData();
}
}

View File

@ -0,0 +1,177 @@
package jackcartersmith.orbsat.common.blocks;
import javax.annotation.Nullable;
import jackcartersmith.orbsat.OrbitalSatellite;
import jackcartersmith.orbsat.common.blocks.OrbsatBlockInterface.IDirectionalTile;
import jackcartersmith.orbsat.common.util.ConfigManager;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
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;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.energy.CapabilityEnergy;
public abstract class TileEntityOrbsatBase extends TileEntity{
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.readCustomNBT(nbt, false);
}
public abstract void readCustomNBT(NBTTagCompound nbt, boolean descPacket);
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
this.writeCustomNBT(nbt, false);
return nbt;
}
public abstract void writeCustomNBT(NBTTagCompound nbt, boolean descPacket);
@Override
public SPacketUpdateTileEntity getUpdatePacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeCustomNBT(nbttagcompound, true);
return new SPacketUpdateTileEntity(this.pos, 3, nbttagcompound);
}
@Override
public NBTTagCompound getUpdateTag()
{
NBTTagCompound nbt = super.writeToNBT(new NBTTagCompound());
writeCustomNBT(nbt, true);
return nbt;
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
{
this.readCustomNBT(pkt.getNbtCompound(), true);
}
@Override
public void rotate(Rotation rot)
{
if(rot!=Rotation.NONE&&this instanceof IDirectionalTile&&((IDirectionalTile)this).canRotate(EnumFacing.UP))
{
EnumFacing f = ((IDirectionalTile)this).getFacing();
switch(rot)
{
case CLOCKWISE_90:
f = f.rotateY();
break;
case CLOCKWISE_180:
f = f.getOpposite();
break;
case COUNTERCLOCKWISE_90:
f = f.rotateYCCW();
break;
}
((IDirectionalTile)this).setFacing(f);
this.markDirty();
if(this.pos!=null)
this.markBlockForUpdate(this.pos, null);
}
}
@Override
public void mirror(Mirror mirrorIn)
{
if(mirrorIn==Mirror.FRONT_BACK&&this instanceof IDirectionalTile)
{
((IDirectionalTile)this).setFacing(((IDirectionalTile)this).getFacing());
this.markDirty();
if(this.pos!=null)
this.markBlockForUpdate(this.pos, null);
}
}
public void receiveMessageFromClient(NBTTagCompound message) {}
public void receiveMessageFromServer(NBTTagCompound message) {}
public void onEntityCollision(World world, Entity entity) {}
@Override
public boolean receiveClientEvent(int id, int type)
{
if(id==0||id==255)
{
markContainingBlockForUpdate(null);
return true;
}
else if(id==254)
{
IBlockState state = world.getBlockState(pos);
if(state instanceof IExtendedBlockState)
OrbitalSatellite.proxy.removeStateFromSmartModelCache((IExtendedBlockState)state);
world.notifyBlockUpdate(pos, state, state, 3);
return true;
}
return super.receiveClientEvent(id, type);
}
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
{
if(world.isBlockLoaded(pos))
newState = world.getBlockState(pos);
if(oldState.getBlock()!=newState.getBlock()||!(oldState.getBlock() instanceof BlockOrbsatBase)||!(newState.getBlock() instanceof BlockOrbsatBase))
return true;
IProperty type = ((BlockOrbsatBase)oldState.getBlock()).getMetaProperty();
return oldState.getValue(type)!=newState.getValue(type);
}
public void markContainingBlockForUpdate(@Nullable IBlockState newState)
{
markBlockForUpdate(getPos(), newState);
}
public void markBlockForUpdate(BlockPos pos, @Nullable IBlockState newState)
{
IBlockState state = world.getBlockState(pos);
if(newState==null)
newState = state;
world.notifyBlockUpdate(pos, state, newState, 3);
world.notifyNeighborsOfStateChange(pos, newState.getBlock(), true);
}
/*
@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing)
{
if(capability==CapabilityEnergy.ENERGY&&this instanceof EnergyHelper.IIEInternalFluxConnector)
return ((EnergyHelper.IIEInternalFluxConnector)this).getCapabilityWrapper(facing)!=null;
return super.hasCapability(capability, facing);
}
@Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing)
{
if(capability==CapabilityEnergy.ENERGY&&this instanceof EnergyHelper.IIEInternalFluxConnector)
return (T)((EnergyHelper.IIEInternalFluxConnector)this).getCapabilityWrapper(facing);
return super.getCapability(capability, facing);
}
*/
@Override
public double getMaxRenderDistanceSquared()
{
return super.getMaxRenderDistanceSquared()*
ConfigManager.OrbsatConfig.increasedTileRenderdistance*ConfigManager.OrbsatConfig.increasedTileRenderdistance;
}
}

View File

@ -0,0 +1,103 @@
package jackcartersmith.orbsat.common.commands;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.server.command.CommandTreeBase;
import net.minecraftforge.server.command.CommandTreeHelp;
public class CommandHandler extends CommandTreeBase{
private final String name;
private static final String start = "<";
private static final String end = ">";
public CommandHandler(boolean client)
{
if(client)
{
addSubcommand(new CommandResetRenders());
name = "cie";
}
else
{
//addSubcommand(new CommandMineral());
//addSubcommand(new CommandShaders());
name = "ie";
}
addSubcommand(new CommandTreeHelp(this));
}
@Nonnull
@Override
public String getName()
{
return name;
}
@Nonnull
@Override
public String getUsage(@Nonnull ICommandSender sender)
{
return "Use \"/"+name+" help\" for more information";
}
@Override
public int getRequiredPermissionLevel()
{
return name.equals("cie")?0: 4;
}
@Nonnull
@Override
public List<String> getTabCompletions(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, String[] args, @Nullable BlockPos pos)
{
List<String> ret = super.getTabCompletions(server, sender, args, pos);
for(int i = 0; i < ret.size(); i++)
{
String curr = ret.get(i);
if(curr.indexOf(' ') >= 0)
{
ret.set(i, start+curr+end);
}
}
return ret;
}
@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, String[] args) throws CommandException
{
List<String> argsCleaned = new ArrayList<>(args.length);
String currentPart = null;
for(String s : args)
{
if(s.startsWith(start))
{
if(currentPart!=null)
throw new CommandException("String opens twice (once \""+currentPart+"\", once \""+s+"\")");
currentPart = s;
}
else if(currentPart!=null)
currentPart += " "+s;
else
argsCleaned.add(s);
if(s.endsWith(end))
{
if(currentPart==null)
throw new CommandException("String closed without being openeed first! (\""+s+"\")");
if(currentPart.length() >= 2)
argsCleaned.add(currentPart.substring(1, currentPart.length()-1));
currentPart = null;
}
}
if(currentPart!=null)
throw new CommandException("Unclosed string ("+currentPart+")");
super.execute(server, sender, argsCleaned.toArray(new String[0]));
}
}

View File

@ -0,0 +1,36 @@
package jackcartersmith.orbsat.common.commands;
import javax.annotation.Nonnull;
import jackcartersmith.orbsat.OrbitalSatellite;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
public class CommandResetRenders extends CommandBase{
@Nonnull
@Override
public String getName()
{
return "resetrender";
}
@Nonnull
@Override
public String getUsage(@Nonnull ICommandSender sender)
{
return "Reset the render caches of Immersive Engineering and its addons";
}
@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args)
{
OrbitalSatellite.proxy.clearRenderCaches();
}
@Override
public int getRequiredPermissionLevel()
{
return 0;
}
}

View File

@ -0,0 +1,50 @@
package jackcartersmith.orbsat.common.compat;
import elucent.albedo.event.GatherLightsEvent;
import elucent.albedo.lighting.Light;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class AlbedoHelper extends OrbsatCompatModule
{
@Override
public void preInit()
{
}
@Override
public void init()
{
MinecraftForge.EVENT_BUS.register(this);
}
/*
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void gatherLights(GatherLightsEvent event)
{
for(LightningAnimation animation : TileEntityTeslaCoil.effectMap.values())
{
if(animation.shoudlRecalculateLightning())
animation.createLightning(Utils.RAND);
Light.Builder builder = Light.builder();
builder.radius(2.5f);
builder.color(77/255f, 74/255f, 152/255f);
for(Vec3d point : animation.subPoints)
{
builder.pos(point);
event.getLightList().add(builder.build());
}
}
}
*/
@Override
public void postInit()
{
}
}

View File

@ -0,0 +1,107 @@
package jackcartersmith.orbsat.common.compat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
import jackcartersmith.orbsat.common.util.ConfigManager;
import jackcartersmith.orbsat.common.util.LogHelper;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public abstract class OrbsatCompatModule {
public static HashMap<String, Class<? extends OrbsatCompatModule>> moduleClasses = new HashMap<String, Class<? extends OrbsatCompatModule>>();
public static Set<OrbsatCompatModule> modules = new HashSet<OrbsatCompatModule>();
static
{
moduleClasses.put("albedo", AlbedoHelper.class);
//moduleClasses.put("baubles", BaublesHelper.class);
//moduleClasses.put("opencomputers", OCHelper.class);
moduleClasses.put("waila", WailaHelper.class);
}
public static void doModulesPreInit()
{
for(Entry<String, Class<? extends OrbsatCompatModule>> e : moduleClasses.entrySet())
if(Loader.isModLoaded(e.getKey()))
try
{
//IC2 Classic is not supported.
if("ic2".equals(e.getKey())&&Loader.isModLoaded("ic2-classic-spmod"))
continue;
Boolean enabled = ConfigManager.OrbsatConfig.compat.get(e.getKey());
if(enabled==null||!enabled)
continue;
OrbsatCompatModule m = e.getValue().newInstance();
modules.add(m);
m.preInit();
} catch(Exception exception)
{
LogHelper.logger.error("Compat module for "+e.getKey()+" could not be preInitialized. Report this and include the error message below!", exception);
}
}
public static void doModulesInit()
{
for(OrbsatCompatModule compat : OrbsatCompatModule.modules)
try
{
compat.init();
} catch(Exception exception)
{
LogHelper.logger.error("Compat module for "+compat+" could not be initialized. Report this and include the error message below!", exception);
}
}
public static void doModulesPostInit()
{
for(OrbsatCompatModule compat : OrbsatCompatModule.modules)
try
{
compat.postInit();
} catch(Exception exception)
{
LogHelper.logger.error("Compat module for "+compat+" could not be postInitialized. Report this and include the error message below!", exception);
}
}
public static boolean serverStartingDone = false;
public static void doModulesLoadComplete()
{
if(!serverStartingDone)
{
serverStartingDone = true;
for(OrbsatCompatModule compat : OrbsatCompatModule.modules)
try
{
compat.loadComplete();
} catch(Exception exception)
{
LogHelper.logger.error("Compat module for "+compat+" could not be initialized. Report this and include the error message below!", exception);
}
}
}
public abstract void preInit();
public abstract void init();
public abstract void postInit();
public void loadComplete() {}
@SideOnly(Side.CLIENT)
public void clientPreInit() {}
@SideOnly(Side.CLIENT)
public void clientInit() {}
@SideOnly(Side.CLIENT)
public void clientPostInit() {}
}

View File

@ -0,0 +1,7 @@
package jackcartersmith.orbsat.common.compat;
import mcp.mobius.waila.api.IWailaDataProvider;
public class OrbsatWailaDataProvider implements IWailaDataProvider {
//TODO
}

View File

@ -0,0 +1,22 @@
package jackcartersmith.orbsat.common.compat;
import net.minecraftforge.fml.common.event.FMLInterModComms;
public class WailaHelper extends OrbsatCompatModule
{
@Override
public void preInit()
{
}
@Override
public void init()
{
FMLInterModComms.sendMessage("waila", "register", "jackcartersmith.orbsat.common.compat.OrbsatWailaDataProvider.callbackRegister");
}
@Override
public void postInit()
{
}
}

View File

@ -0,0 +1,42 @@
package jackcartersmith.orbsat.common.util;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Maps;
import jackcartersmith.orbsat.OrbitalSatellite;
import jackcartersmith.orbsat.common.compat.OrbsatCompatModule;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@Mod.EventBusSubscriber
public class ConfigManager {
public static HashMap<String, Boolean> manual_bool = new HashMap<String, Boolean>();
public static HashMap<String, Integer> manual_int = new HashMap<String, Integer>();
public static HashMap<String, int[]> manual_intA = new HashMap<String, int[]>();
public static HashMap<String, Double> manual_double = new HashMap<String, Double>();
public static HashMap<String, double[]> manual_doubleA = new HashMap<String, double[]>();
@net.minecraftforge.common.config.Config(modid = OrbitalSatellite.MODID)
public static class OrbsatConfig {
@Comment({"A list of all mods that OrbSat has integrated compatability for", "Setting any of these to false disables the respective compat"})
public static Map<String, Boolean> compat = Maps.newHashMap(Maps.toMap(OrbsatCompatModule.moduleClasses.keySet(), (s) -> Boolean.TRUE));
@Comment({"Increase the distance at which certain TileEntities (specifically windmills) are still visible. This is a modifier, so set it to 1 for default render distance, to 2 for doubled distance and so on."})
public static double increasedTileRenderdistance = 1.5;
}
static Configuration config;
public static void preInit(FMLPreInitializationEvent event)
{
onConfigUpdate();
}
private static void onConfigUpdate()
{
}
}

View File

@ -0,0 +1,41 @@
package jackcartersmith.orbsat.common.util;
import jackcartersmith.orbsat.OrbitalSatellite;
public class Lib {
public static final String MODID = OrbitalSatellite.MODID;
public static final String[] METALS_IE = {"Copper", "Aluminum", "Lead", "Silver", "Nickel", "Uranium", "Constantan", "Electrum", "Steel"};
public static final String[] METALS_ALL = {"Copper", "Aluminum", "Lead", "Silver", "Nickel", "Uranium", "Constantan", "Electrum", "Steel", "Iron", "Gold"};
public static final String TOOL_HAMMER = "IE_HAMMER";
public static final String TOOL_WIRECUTTER = "IE_WIRECUTTER";
public static final String CHAT = "chat."+MODID+".";
public static final String CHAT_WARN = CHAT+"warning.";
public static final String CHAT_INFO = CHAT+"info.";
public static final String CHAT_COMMAND = CHAT+"command.";
public static final String DESC = "desc."+MODID+".";
public static final String DESC_INFO = DESC+"info.";
public static final String DESC_FLAVOUR = DESC+"flavour.";
public static final String GUI = "gui."+MODID+".";
public static final String GUI_CONFIG = "gui."+MODID+".config.";
public static final int COLOUR_I_ImmersiveOrange = 0xfff78034;
public static final float[] COLOUR_F_ImmersiveOrange = {247/255f, 128/255f, 52/255f};
public static final int COLOUR_I_ImmersiveOrangeShadow = 0xff3e200d;
/**
* Gui IDs
*/
//Tiles
public static final int GUIID_Base_Tile = 0;
//Items
public static final int GUIID_Base_Item = 64;
public static final int colour_nixieTubeText = 0xff9900;
}

View File

@ -0,0 +1,37 @@
package jackcartersmith.orbsat.common.util;
import java.util.Locale;
import net.minecraft.util.IStringSerializable;
public class OrbsatEnums {
public enum SideConfig implements IStringSerializable
{
NONE("none"),
INPUT("in"),
OUTPUT("out");
final String texture;
SideConfig(String texture)
{
this.texture = texture;
}
@Override
public String getName()
{
return this.toString().toLowerCase(Locale.ENGLISH);
}
public String getTextureName()
{
return texture;
}
public static SideConfig next(SideConfig current)
{
return current==INPUT?OUTPUT: current==OUTPUT?NONE: INPUT;
}
}
}

View File

@ -0,0 +1,215 @@
package jackcartersmith.orbsat.common.util;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import jackcartersmith.orbsat.common.util.OrbsatEnums.SideConfig;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.PropertyHelper;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.property.IUnlistedProperty;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
public class OrbsatProperties {
public static final PropertyDirection FACING_ALL = PropertyDirection.create("facing");
public static final PropertyDirection FACING_HORIZONTAL = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
public static final PropertyBoolInverted MULTIBLOCKSLAVE = PropertyBoolInverted.create("_0multiblockslave");//Name starts with '_0' to ensure priority when overriding models
public static final PropertyBoolInverted DYNAMICRENDER = PropertyBoolInverted.create("_1dynamicrender");//Name starts with '_1' to ensure priority over anything but the multiblockslave property
public static final PropertySet CONNECTIONS = new PropertySet("conns");
// public static final PropertyEnum[] SIDECONFIG = {
// PropertyEnum.create("sideconfig_down", IEEnums.SideConfig.class),
// PropertyEnum.create("sideconfig_up", IEEnums.SideConfig.class),
// PropertyEnum.create("sideconfig_north", IEEnums.SideConfig.class),
// PropertyEnum.create("sideconfig_south", IEEnums.SideConfig.class),
// PropertyEnum.create("sideconfig_west", IEEnums.SideConfig.class),
// PropertyEnum.create("sideconfig_east", IEEnums.SideConfig.class)
// };
public static final ProperySideConfig[] SIDECONFIG = {
new ProperySideConfig("sideconfig_down"),
new ProperySideConfig("sideconfig_up"),
new ProperySideConfig("sideconfig_north"),
new ProperySideConfig("sideconfig_south"),
new ProperySideConfig("sideconfig_west"),
new ProperySideConfig("sideconfig_east")
};
public static final PropertyBoolInverted[] SIDECONNECTION = {
PropertyBoolInverted.create("sideconnection_down"),
PropertyBoolInverted.create("sideconnection_up"),
PropertyBoolInverted.create("sideconnection_north"),
PropertyBoolInverted.create("sideconnection_south"),
PropertyBoolInverted.create("sideconnection_west"),
PropertyBoolInverted.create("sideconnection_east")
};
//An array of non-descript booleans for mirroring, active textures, etc.
public static final PropertyBoolInverted[] BOOLEANS = {
PropertyBoolInverted.create("boolean0"),
PropertyBoolInverted.create("boolean1"),
PropertyBoolInverted.create("boolean2")
};
public static final PropertyInteger INT_4 = PropertyInteger.create("int_4", 0, 3);
public static final PropertyInteger INT_16 = PropertyInteger.create("int_16", 0, 15);
public static class ProperySideConfig implements IUnlistedProperty<SideConfig>
{
final String name;
public ProperySideConfig(String name)
{
this.name = name;
}
@Override
public String getName()
{
return name;
}
@Override
public boolean isValid(SideConfig value)
{
return true;
}
@Override
public Class<SideConfig> getType()
{
return OrbsatEnums.SideConfig.class;
}
@Override
public String valueToString(SideConfig value)
{
return value.toString();
}
}
public static final IUnlistedProperty<HashMap> OBJ_TEXTURE_REMAP = new IUnlistedProperty<HashMap>()
{
@Override
public String getName()
{
return "obj_texture_remap";
}
@Override
public boolean isValid(HashMap value)
{
return true;
}
@Override
public Class<HashMap> getType()
{
return HashMap.class;
}
@Override
public String valueToString(HashMap value)
{
return value.toString();
}
};
public static class PropertyBoolInverted extends PropertyHelper<Boolean>
{
private static final ImmutableList<Boolean> ALLOWED_VALUES = ImmutableList.of(false, true);
protected PropertyBoolInverted(String name)
{
super(name, Boolean.class);
}
@Override
public Collection<Boolean> getAllowedValues()
{
return ALLOWED_VALUES;
}
@Override
public Optional<Boolean> parseValue(String value)
{
return Optional.of(Boolean.parseBoolean(value));
}
public static PropertyBoolInverted create(String name)
{
return new PropertyBoolInverted(name);
}
@Override
public String getName(Boolean value)
{
return value.toString();
}
}
@SuppressWarnings("rawtypes")
public static class PropertySet implements IUnlistedProperty<Set>
{
String name;
public PropertySet(String n)
{
name = n;
}
@Override
public String getName()
{
return name;
}
@Override
public boolean isValid(Set value)
{
return value!=null;
}
@Override
public Class<Set> getType()
{
return Set.class;
}
@Override
public String valueToString(Set value)
{
return value.toString();
}
}
public static final IUnlistedProperty<TileEntity> TILEENTITY_PASSTHROUGH = new IUnlistedProperty<TileEntity>()
{
@Override
public String getName()
{
return "tileentity_passthrough";
}
@Override
public boolean isValid(TileEntity value)
{
return true;
}
@Override
public Class<TileEntity> getType()
{
return TileEntity.class;
}
@Override
public String valueToString(TileEntity value)
{
return value.toString();
}
};
}

View File

@ -0,0 +1,53 @@
package jackcartersmith.orbsat.common.util.network;
import org.apache.commons.lang3.tuple.ImmutablePair;
import io.netty.buffer.ByteBuf;
import jackcartersmith.orbsat.common.EventHandler;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class MessageRequestBlockUpdate implements IMessage{
BlockPos pos;
public MessageRequestBlockUpdate(BlockPos pos)
{
this.pos = pos;
}
public MessageRequestBlockUpdate()
{
}
@Override
public void fromBytes(ByteBuf buf)
{
pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeInt(pos.getX()).writeInt(pos.getY()).writeInt(pos.getZ());
}
public static class Handler implements IMessageHandler<MessageRequestBlockUpdate, IMessage>
{
@Override
public IMessage onMessage(MessageRequestBlockUpdate message, MessageContext ctx)
{
WorldServer world = ctx.getServerHandler().player.getServerWorld();
world.addScheduledTask(() -> {
if(world.isBlockLoaded(message.pos))
{
int dim = world.provider.getDimension();
EventHandler.requestedBlockUpdates.offer(new ImmutablePair<>(dim, message.pos));
}
});
return null;
}
}
}

View File

@ -0,0 +1,78 @@
package jackcartersmith.orbsat.common.util.network;
import io.netty.buffer.ByteBuf;
import jackcartersmith.orbsat.OrbitalSatellite;
import jackcartersmith.orbsat.common.blocks.TileEntityOrbsatBase;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class MessageTileSync implements IMessage {
BlockPos pos;
NBTTagCompound nbt;
public MessageTileSync(TileEntityOrbsatBase tile, NBTTagCompound nbt)
{
this.pos = tile.getPos();
this.nbt = nbt;
}
public MessageTileSync()
{
}
@Override
public void fromBytes(ByteBuf buf) {
this.pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
this.nbt = ByteBufUtils.readTag(buf);
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(pos.getX()).writeInt(pos.getY()).writeInt(pos.getZ());
ByteBufUtils.writeTag(buf, this.nbt);
}
public static class HandlerServer implements IMessageHandler<MessageTileSync, IMessage>
{
@Override
public IMessage onMessage(MessageTileSync message, MessageContext ctx)
{
WorldServer world = ctx.getServerHandler().player.getServerWorld();
world.addScheduledTask(() -> {
if(world.isBlockLoaded(message.pos))
{
TileEntity tile = world.getTileEntity(message.pos);
if(tile instanceof TileEntityOrbsatBase)
((TileEntityOrbsatBase)tile).receiveMessageFromClient(message.nbt);
}
});
return null;
}
}
public static class HandlerClient implements IMessageHandler<MessageTileSync, IMessage>
{
@Override
public IMessage onMessage(MessageTileSync message, MessageContext ctx)
{
Minecraft.getMinecraft().addScheduledTask(() -> {
World world = OrbitalSatellite.proxy.getClientWorld();
if (world!=null) // This can happen if the task is scheduled right before leaving the world
{
TileEntity tile = world.getTileEntity(message.pos);
if(tile instanceof TileEntityOrbsatBase)
((TileEntityOrbsatBase)tile).receiveMessageFromServer(message.nbt);
}
});
return null;
}
}
}

View File

@ -0,0 +1,4 @@
public net.minecraft.client.model.ModelRenderer field_78803_o #textureOffsetX
public net.minecraft.client.model.ModelRenderer field_78813_p #textureOffsetY
public net.minecraft.client.Minecraft field_71428_T #timer
protected net.minecraft.world.Explosion * # all Explosion fields

View File

@ -3,7 +3,7 @@
"modid": "orbsat",
"name": "Orbital Satellite",
"description": "Multi-usage satellite with control center and launch bay.",
"version": "${version}",
"version": "0.1.3",
"mcversion": "${mcversion}",
"url": "",
"authorList": ["JackCarterSmith"],