Compare commits

..

5 commits

Author SHA1 Message Date
malte0811 e500ba0a7c Build 1.4-19 2017-08-14 18:52:33 +02:00
malte0811 baa091b9a4 Don't interact with other TE's in onChunkUnload, closes #12 2017-08-13 22:14:56 +02:00
malte0811 a42a662a06 Build 15-17 2017-08-04 19:18:12 +02:00
malte0811 9b9d3edc40 Added documentation on the key ring and fixed some bugs with it
Backported other fixes from 1.12
2017-08-04 18:18:50 +02:00
malte0811 f8f53d2434 One more fix for connecting panels using connectors after the panel and the controller have been placed 2017-08-04 18:00:28 +02:00
350 changed files with 4296 additions and 27302 deletions

View file

@ -18,7 +18,7 @@ Some mods are not officially supported by IndustrialWires. They will probably wo
- **Fastcraft**: same as Optifine.
- **Sponge(Forge)** and similar server software: While the source code of some of these is available on GitHub or similar platforms, it would require a lot of extra work to test everything with every server software.
- **(K)Cauldron** and similar server software: While the source code of some of these is available on GitHub or similar platforms, it would require a lot of extra work to test everything with every server software.
- **Any version of IndustrialCraft2 that is not made by the official IC2 team** (more specifically, any IC2 version not available for download [here](http://jenkins.ic2.player.to/) or [here](https://minecraft.curseforge.com/projects/industrial-craft))

View file

@ -1,15 +1,11 @@
#Industrial Wires
![](Screenshot.png)
An addon for Immersive Engineering. Some features, like the EU-transmitting IE-style wires the mod is named after, will only be enabled if IC2 is installed. All devices added by IndustrialWires can run of IC2 EU as well as ForgeEnergy/RF.
![An example of what Industrial Wires can do](Screenshot.png)
The features can be split into to groups: IC2 compat and HV/electronics stuff
- IC2 compat:
- IE style wires that transmit EU. Check the manual for recipes
- Lossy converters between IE's rotational energy (windmills, watermills) and IC2's kinetic energy
- HV/electronics:
- [Control panels](https://www.youtube.com/watch?v=hV0cN20vCMY)
- Jacob's ladders. They don't do anything useful apart from looking nice (Shown in the control panel video)
- Marx generators. Ore processing using lightning/high voltage. You need to do a little bit of math to use it for that, but you can still use it to kill things/people without doing any!
An addon for Immersive Engineering and IndustrialCraft2. It adds IE-style wires that are able to transmit IC2 energy (EU). This is different from the IC2 compatibility IE had in MC 1.7.10 as it is not possible to convert IC2 power to RF/IF/Tesla/forge energy/etc.
The textures and models are partially modified IE resources and partially made by C8H8O4 or me.
Recipes for the relays, connectors and wires can be found in the Engineer's Manual.
All textures for the connectors are modified versions of the textures Immersive Engineering uses and the models are loaded out of IE, so all art for the wires is at least based on art Mr. Damien Hazard made.
The textures for the mechanical converters and the Rotational Motor were made by C8H8O4.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 KiB

After

Width:  |  Height:  |  Size: 320 KiB

View file

@ -1,251 +1,98 @@
import groovy.json.JsonOutput
def mainVersion = "1.7"
def buildNumber = "38"
// For those who want the bleeding edge
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'idea'
/*
// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
plugins {
id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
version = "${mainVersion}-${buildNumber}"
group= "malte0811"
archivesBaseName = "IndustrialWires"
sourceCompatibility = 1.8
targetCompatibility = 1.8
minecraft {
version = "1.12.2-14.23.5.2847"
runDir = "run"
replace '${version}', project.version
mappings = "stable_39"
}
repositories {
maven {
name 'ic2'
url 'http://maven.ic2.player.to/'
}
maven {
name 'tr'
url 'http://maven.modmuss50.me'
}
maven {
name 'jared maven'
url 'http://blamejared.com/maven'
}
maven { // Albedo/Mirage Lights
url 'https://repo.elytradev.com/'
}
maven { // JEI & Tinkers
name 'DVS1 Maven FS'
url 'http://dvs1.progwml6.com/files/maven'
}
// dependencies of TR...
maven {
url 'http://maven.mcmoddev.com'
}
maven {
// HWYLA
name "TehNut"
url "http://tehnut.info/maven/"
}
repositories {//Curseforge maven for project red
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
}
maven {
name = "chickenbones"
url = "http://chickenbones.net/maven"
}
}
dependencies {
compile 'net.industrial-craft:industrialcraft-2:2.8.+'
deobfCompile "blusunrize:ImmersiveEngineering:0.12-+"
compileOnly "pl.asie.charset:charset:0.5.6.4.19:full"
//Project red and runtime dependencies
compileOnly "project-red-base:ProjectRed-1.12.2:4.9.1.92:Base"
//runtime "project-red-integration:ProjectRed-1.12.2:4.9.1.92:integration"
//runtime "forge-multipart-cbe:ForgeMultipart-1.12.2:2.5.0.69:universal"
//runtime "codechicken:CodeChickenLib:1.12.2-3.2.1.349:universal"
//runtime "codechicken:ChickenASM:1.12-1.0.2.7"
//runtime "mrtjpcore:MrTJPCore-1.12.2:2.1.3.35:universal"
//Tech Reborn
compileOnly "TechReborn:TechReborn-1.12:2.6.9.7:universal"
compileOnly "RebornCore:RebornCore-1.12:3.2.+:universal"
//Others
//TODO do something about this
// compileOnly 'com.elytradev:mirage:2.0.1-SNAPSHOT'
compileOnly "mezz.jei:jei_1.12:4.+"
compileOnly "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.8.460"
compile 'com.elytradev:mirage:2.0.3-rc3-SNAPSHOT'
compile "gregtechce:gregtech:1.12.2:1.9.0.481"
compile "magneticraft:Magneticraft_1.12:2.8.2:dev"
}
jar {
from 'LICENSE'
manifest {
attributes 'Maven-Artifact': group+':'+archivesBaseName+':'+version
attributes "FMLAT": "industrialwires_at.cfg"
}
}
task signMain(type: SignJar) {
onlyIf {
project.hasProperty('keyStore')
}
dependsOn reobfJar
if (project.hasProperty('keyStore')) {
keyStore = project.keyStore
alias = project.storeAlias
storePass = project.storePass
keyPass = project.storePass
inputFile = jar.archivePath
outputFile = jar.archivePath
}
}
build.dependsOn signMain
processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
//Code for automatic update JSON generation
class GenerateUpdateJSON extends DefaultTask {
static def IW_VERSION_PREFIX = "####Version "
static def MC_VERSION_PREFIX = "###Minecraft "
static def UNFINISHED_SUFFIX = " - UNFINISHED"
static def RECOMMENDED = "-recommended"
static def LATEST = "-latest"
static def CF_URL = "https://minecraft.curseforge.com/projects/industrial-wires"
int compareVersions(String vA, String vB) {
String[] vPartsA = vA.split("[\\D]")
String[] vPartsB = vB.split("[\\D]")
if (vPartsA.length==0&&vPartsB.length==0)
return vA <=> vB
else if (vPartsA.length==0)
return -1
else if (vPartsB.length==0)
return 1
int length = Math.min(vPartsA.length, vPartsB.length)
for (int i = 0;i<length;i++) {
int pA = Integer.parseInt(vPartsA[i])
int pB = Integer.parseInt(vPartsB[i])
if (pA!=pB) {
return pA<=>pB
}
}
if (vPartsA.length != vPartsB.length)
return vPartsA.length <=> vPartsB.length
return vA <=> vB
}
def addChangelog(Map<String, Map<String, String>> changelogForVersions, Map<String, String> promos,
String currentMCVersion, String currentVersion, String currentChangelog) {
if (!changelogForVersions.containsKey(currentMCVersion)) {
promos.put(currentMCVersion+RECOMMENDED, currentVersion)
promos.put(currentMCVersion+LATEST, currentVersion)
changelogForVersions[currentMCVersion] = new TreeMap<>({String s1, String s2->
compareVersions(s1, s2)})
}
changelogForVersions[currentMCVersion][currentVersion] = currentChangelog
}
@TaskAction
def generate() {
File changelog = new File("changelog.md")
if (!changelog.exists())
println "Changelog does not exist! Aborting!"
else {
String currentMCVersion = "";
Map<String, Map<String, String>> changelogForVersions = new HashMap<>()
Map<String, String> promos = new TreeMap<>({String s1, String s2->
compareVersions(s1, s2)})
String currentVersion = null
String currentChangelog = ""
changelog.eachLine {line ->
if (line.startsWith(IW_VERSION_PREFIX)) {
if (currentVersion!=null) {
addChangelog(changelogForVersions, promos, currentMCVersion, currentVersion, currentChangelog)
}
if (!line.endsWith(UNFINISHED_SUFFIX)) {
currentVersion = line.substring(IW_VERSION_PREFIX.length())
} else {
currentVersion = (String) null
}
currentChangelog = ""
} else if (line.startsWith(MC_VERSION_PREFIX)) {
if (currentVersion!=null) {
addChangelog(changelogForVersions, promos, currentMCVersion, currentVersion, currentChangelog)
}
currentChangelog = ""
currentVersion = (String) null
currentMCVersion = line.substring(MC_VERSION_PREFIX.length())
} else if (!line.isEmpty()) {
if (currentChangelog.length()==0)
currentChangelog += line
else
currentChangelog += "\n"+line
}
}
Map<String, Object> mainMap = new TreeMap<>({String s1, String s2->
compareVersions(s1, s2)})
mainMap.putAll(changelogForVersions)
mainMap["homepage"] = CF_URL
mainMap["promos"] = promos
def outJson = JsonOutput.toJson(mainMap)
outJson = JsonOutput.prettyPrint(outJson)
File outF = new File("changelog.json")
outF.delete()
outF << outJson
}
}
}
task updateJson(type: GenerateUpdateJSON)
build.finalizedBy updateJson
def mainVersion = "1.5"
def buildNumber = "19"
// For those who want the bleeding edge
buildscript {
repositories {
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
/*
// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot
plugins {
id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
version = "${mainVersion}-${buildNumber}"
group= "malte0811"
archivesBaseName = "IndustrialWires"
sourceCompatibility = 1.8
targetCompatibility = 1.8
minecraft {
version = "13.20.1.2393"
runDir = "run"
replace '${version}', project.version
mappings = "snapshot_20170612"
}
repositories {
maven {
name 'ic2'
url 'http://maven.ic2.player.to/'
}
maven {
name 'jared maven'
url 'http://blamejared.com/maven'
}
}
dependencies {
compile "net.industrial-craft:industrialcraft-2:2.7.+"
deobfCompile "blusunrize:ImmersiveEngineering:0.11-+:deobf"
}
jar {
from 'LICENSE'
manifest {
}
}
task signMain(type: SignJar) {
onlyIf {
project.hasProperty('keyStore')
}
dependsOn reobfJar
if (project.hasProperty('keyStore')) {
keyStore = project.keyStore
alias = project.storeAlias
storePass = project.storePass
keyPass = project.storePass
inputFile = jar.archivePath
outputFile = jar.archivePath
}
}
build.dependsOn signMain
processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}

View file

@ -1,51 +0,0 @@
{
"homepage": "https://minecraft.curseforge.com/projects/industrial-wires",
"promos": {
"1.10.2-latest": "1.4-18",
"1.10.2-recommended": "1.4-18",
"1.11.2-latest": "1.5-19",
"1.11.2-recommended": "1.5-19",
"1.12.2-latest": "1.7-36",
"1.12.2-recommended": "1.7-36"
},
"1.10.2": {
"1.1-3": " - fixed incompatibility with IE build 48\n - reduced the amount of calls to core IE classes to make such incompatibilities less likely\n - fixed localization of the creative tab",
"1.1-4": " - fixed an insane amount of log-spam in an edgecase (probably a Vanilla or Forge bug)\n - added config values for wire length per connection and per coil item\n ",
"1.2-5 (10,000 download celebratory release)": " - added mechanical converters and the rotational motor\n - they convert between IE rotational energy (windmill, dynamo etc) and IC2 kinetic energy\n - Rotational motor: produces IE rotational energy from IF\n - No lossless conversion\n - Can be disabled in the config\n - wire coils show when they are out of range (to match the behavior of IE coils in the latest dev version)",
"1.2-6": " - reduced the discrepancies between IC2 cables and Industrial Wires\n - machines don't explode when they shouldn't except in some corner cases\n - potentially fixed missing textures on the mechanical converters\n - added Chinese translations (thanks SihenZhang)",
"1.3-7": " - added Jacob's Ladders/High voltage travelling arcs\n - they don't have a particular purpose aside from looking nice",
"1.3-8": " - the converters and the motor don't have missing textures any more when using Chisel",
"1.4-9": " - added Control Panels\n - They can be used to control and monitor a lot of redstone signals from a few blocks",
"1.4-10": " - added lock switches for control panels (backport from 1.11)\n - Can only be turned on by someone with the correct key to prevent unauthorized access\n - up to 10 keys can be added to a keyring to reduce inventory spam\n - IC2 items can be added to the appropriate sections of the engineers toolbox (backport from 1.11)\n - Components (lighted button, indicator light, etc.) on panels now actually light up (backport from 1.11)\n - Fixed power loss when no energy is being transmitted",
"1.4-16": " - Backported a lot of fixes from 1.11 and 1.12",
"1.4-18": " - Fixed a crash with SpongeForge, chunk loading issues without\n - Fixed some components resetting on chunk unload"
},
"1.11.2": {
"1.5-11": " - Updated to Minecraft 1.11.2\n - Added Panel Meters to monitor a redstone signal with reasonable accuracy\n - Multiple components on the same panel network can modify the same signal now without causing undefined behavior\n - Lock Switches no longer break the model cache",
"1.5-12": " - Added tilted control panels\n - Panels are no longer created from machine casings, there is a dedicated item for that now, the Unfinished Control Panel\n - Angle and height can be configured in the Engineer's Workbench\n - Fixed a CME when multi-threaded chunk rendering is enabled\n - Fixed control panels not connecting or disconnecting properly when a panel connector between the panel and the RS controller is broken/placed\n - Improved the performance of the control panel hitbox rendering",
"1.5-13": " - Labels no longer break the model cache and cause lag\n - Labels don't break on dedicated servers any more",
"1.5-17": " - Backported some fixes from 1.12",
"1.5-19": " - Fixed a crash with SpongeForge, chunk loading issues without\n - Fixed some components resetting on chunk unload"
},
"1.12.2": {
"1.5-14": " - Updated to Minecraft 1.12\n - Added a recipe for the key ring. Kind of forgot about adding one when I added the ring itself...\n - Fixed wire length crafting leaving wrong coils when the output has maximum length\n - Fixed some more connection issues with control panels",
"1.5-15": " - Components can be placed in the world now to use the as conventional levers/etc.\n - Added documentation on the key ring. It also shows all attached keys on the tooltip now\n - Fixed some bugs with key ring crafting\n - Fixed control panels causing disconnects on servers",
"1.6-20": " - Added the Marx Generator, an alternative ore processing method\n - Hearing protection absolutely required!\n - You may need to do some math and measurements for ore processing to work. It will kill entites just fine without any science\n - IC2 is no longer a hard dependency. The wires and converters will obviously be disabled without it\n - Vastly improved snapping in the panel creator\n - Added some Mirage (Albedo) compat\n - IW is signed now!\n - Analog panel components can interact with 2 channels now, rough and fine control\n - Fixed GUI background and item tooltips\n - Fixed some components resetting when the chunk is unloaded\n - Chunks with control panels properly unload now",
"1.6-21": " - Added shaders for the Marx generator and Jacob's ladder\n - Fixed wires connected to a Marx generator on a server being invisible\n - The Marx generator actually gives output when processing ores now. Oops...\n - The \"safe distance\" formulas for the Marx generator in the manual now match the real safe distance\n - Improved rendering of the Marx generator in the manual. Some of this is only enabled with maven build 275+ or official build 75+ (not released yet)",
"1.6-22": " - Added a Seven-Segment display for control panels\n - Panel components update their values as soon as they are changed in the GUI\n - Fixed a crash when breaking a panel with buttons, locks or toggle switches on it under special circumstances\n - Fixed server crashes when using panel components with a second controller id, but no channel set\n - Fixed various NPE crashes with control panel models under heavy load\n - Fixed wrong panel component ordering with raytracing",
"1.6-23": " - Added a command to allow taking screenshots of Marx generator discharges (/ciw triggermarxscreenshot)\n - Panel components have to be shift-clicked to place them in the world\n - Fixed wire coil crafting\n - Added a recipe for the Seven-Segment displays",
"1.6-24": " - Fixed an infinite energy bug\n - Changed the default value for maximum energy conversion",
"1.6-25": " - Updated to IE build 77\n - IC2 wires cause damage\n - Added insulated versions of gold, copper and tin wires. Due to heat sensitive insulation the transfer capacity is half of the normal capacity\n - Added feedthrough insulators for all IC2 wire types\n - Wire coils now automatically \"merge\" when picked up\n - Config values are applied to the game directly now",
"1.7-26": " - Added Mechanical Multiblocks (energy storage and EU<->FE conversion)\n - There will be an explanation video for these once I have time to make one\n - Fixed the small mechanical converter blowing up tin wires\n - Fixed wires not joining their outputs correctly\n - Fixed wire connectors not breaking when the block they're on is broken",
"1.7-27": " - Fixed panel components causing issues on dedicated servers\n - Added an automatic update checker (Using the Forge update JSON)",
"1.7-28": " - Added the Redstone Controller: Others, it allows control panels to interface with Project:Red and Charset wires\n - Rewrote the control panel redstone code\n - Added localization for IW's multiblocks\n - Fixed issues with zero-length mechanical multiblocks",
"1.7-29": " - The wires can now transmit FE as well as EU, but not both at once\n - Fixed the Marx generator not charging beyond a quite low voltage",
"1.7-30": " - Fixed crashes when IC2 isn't installed\n - Fixed connectors allowing too much power output\n - Added a config option for some of the wires' properties\n - Updated chinese translation (thanks @DepletedPrism)",
"1.7-31": " - Fixed accidental conversion from FE to EU\n - Fixed connectors not blowing up as intended\n ",
"1.7-32": " - Fixed connectors not rendering properly without IC2\n - Fixed parts of the mechanical multiblocks not rendering when Optifine is installed\n - Changed some values for the mechanical multiblock sound",
"1.7-33": " - Fixed the Marx generator not processing ores\n - Fixed control panels and the Marx generator not working when connected directly\n - Added Russian translation (thanks @StolenSoda)",
"1.7-34": " - Control panels can use the texture of any block now\n - Added a recipe to copy the settings of an unfinished control panel\n - The Marx generator now returns the wires used in its construction when disassembled\n - Fixed the RS controller for non-IE wires not keeping its IO state on world reload\n - Fixed control panels not working correctly with multiple controllers",
"1.7-35": " - Fixed a crash when placing certain items in the crafting grid",
"1.7-36": " - Added an RGB indicator light, controlled by 3 (independent) RS signals\n - Fixed a bug allowing for unfinished control panels to be duplicated\n - Fixed insulated and uninsulated wire producing the same wire coils\n - Fixed some issues (including a crash) with the IE RS controller on dedicated servers"
}
}

View file

@ -1,134 +1,15 @@
###Minecraft 1.12.2
####Version 1.7-36
- Added an RGB indicator light, controlled by 3 (independent) RS signals
- Fixed a bug allowing for unfinished control panels to be duplicated
- Fixed insulated and uninsulated wire producing the same wire coils
- Fixed some issues (including a crash) with the IE RS controller on dedicated servers
####Version 1.7-35
- Fixed a crash when placing certain items in the crafting grid
####Version 1.7-34
- Control panels can use the texture of any block now
- Added a recipe to copy the settings of an unfinished control panel
- The Marx generator now returns the wires used in its construction when disassembled
- Fixed the RS controller for non-IE wires not keeping its IO state on world reload
- Fixed control panels not working correctly with multiple controllers
####Version 1.7-33
- Fixed the Marx generator not processing ores
- Fixed control panels and the Marx generator not working when connected directly
- Added Russian translation (thanks @StolenSoda)
####Version 1.7-32
- Fixed connectors not rendering properly without IC2
- Fixed parts of the mechanical multiblocks not rendering when Optifine is installed
- Changed some values for the mechanical multiblock sound
####Version 1.7-31
- Fixed accidental conversion from FE to EU
- Fixed connectors not blowing up as intended
####Version 1.7-30
- Fixed crashes when IC2 isn't installed
- Fixed connectors allowing too much power output
- Added a config option for some of the wires' properties
- Updated chinese translation (thanks @DepletedPrism)
####Version 1.7-29
- The wires can now transmit FE as well as EU, but not both at once
- Fixed the Marx generator not charging beyond a quite low voltage
####Version 1.7-28
- Added the Redstone Controller: Others, it allows control panels to interface with Project:Red and Charset wires
- Rewrote the control panel redstone code
- Added localization for IW's multiblocks
- Fixed issues with zero-length mechanical multiblocks
####Version 1.7-27
- Fixed panel components causing issues on dedicated servers
- Added an automatic update checker (Using the Forge update JSON)
####Version 1.7-26
- Added Mechanical Multiblocks (energy storage and EU<->FE conversion)
- There will be an explanation video for these once I have time to make one
- Fixed the small mechanical converter blowing up tin wires
- Fixed wires not joining their outputs correctly
- Fixed wire connectors not breaking when the block they're on is broken
####Version 1.6-25
- Updated to IE build 77
- IC2 wires cause damage
- Added insulated versions of gold, copper and tin wires. Due to heat sensitive insulation the transfer capacity is half of the normal capacity
- Added feedthrough insulators for all IC2 wire types
- Wire coils now automatically "merge" when picked up
- Config values are applied to the game directly now
####Version 1.6-24
- Fixed an infinite energy bug
- Changed the default value for maximum energy conversion
####Version 1.6-23
- Added a command to allow taking screenshots of Marx generator discharges (/ciw triggermarxscreenshot)
- Panel components have to be shift-clicked to place them in the world
- Fixed wire coil crafting
- Added a recipe for the Seven-Segment displays
####Version 1.6-22
- Added a Seven-Segment display for control panels
- Panel components update their values as soon as they are changed in the GUI
- Fixed a crash when breaking a panel with buttons, locks or toggle switches on it under special circumstances
- Fixed server crashes when using panel components with a second controller id, but no channel set
- Fixed various NPE crashes with control panel models under heavy load
- Fixed wrong panel component ordering with raytracing
####Version 1.6-21
- Added shaders for the Marx generator and Jacob's ladder
- Fixed wires connected to a Marx generator on a server being invisible
- The Marx generator actually gives output when processing ores now. Oops...
- The "safe distance" formulas for the Marx generator in the manual now match the real safe distance
- Improved rendering of the Marx generator in the manual. Some of this is only enabled with maven build 275+ or official build 75+ (not released yet)
####Version 1.6-20
- Added the Marx Generator, an alternative ore processing method
- Hearing protection absolutely required!
- You may need to do some math and measurements for ore processing to work. It will kill entites just fine without any science
- IC2 is no longer a hard dependency. The wires and converters will obviously be disabled without it
- Vastly improved snapping in the panel creator
- Added some Mirage (Albedo) compat
- IW is signed now!
- Analog panel components can interact with 2 channels now, rough and fine control
- Fixed GUI background and item tooltips
- Fixed some components resetting when the chunk is unloaded
- Chunks with control panels properly unload now
####Version 1.5-15
- Components can be placed in the world now to use the as conventional levers/etc.
- Added documentation on the key ring. It also shows all attached keys on the tooltip now
- Fixed some bugs with key ring crafting
- Fixed control panels causing disconnects on servers
####Version 1.5-14
- Updated to Minecraft 1.12
- Added a recipe for the key ring. Kind of forgot about adding one when I added the ring itself...
- Fixed wire length crafting leaving wrong coils when the output has maximum length
- Fixed some more connection issues with control panels
###Minecraft 1.11.2
####Version 1.5-19
#####Version 1.4-19
- Fixed a crash with SpongeForge, chunk loading issues without
- Fixed some components resetting on chunk unload
- Fixed some components resetting on chunk unload
####Version 1.5-17
#####Version 1.5-17
- Backported some fixes from 1.12
####Version 1.5-13
#####Version 1.5-13
- Labels no longer break the model cache and cause lag
- Labels don't break on dedicated servers any more
####Version 1.5-12
#####Version 1.5-12
- Added tilted control panels
- Panels are no longer created from machine casings, there is a dedicated item for that now, the Unfinished Control Panel
- Angle and height can be configured in the Engineer's Workbench
@ -136,48 +17,36 @@
- Fixed control panels not connecting or disconnecting properly when a panel connector between the panel and the RS controller is broken/placed
- Improved the performance of the control panel hitbox rendering
####Version 1.5-11
#####Version 1.5-11
- Updated to Minecraft 1.11.2
- Added Panel Meters to monitor a redstone signal with reasonable accuracy
- Multiple components on the same panel network can modify the same signal now without causing undefined behavior
- Lock Switches no longer break the model cache
###Minecraft 1.10.2
####Version 1.4-18
- Fixed a crash with SpongeForge, chunk loading issues without
- Fixed some components resetting on chunk unload
####Version 1.4-16
- Backported a lot of fixes from 1.11 and 1.12
####Version 1.4-10
#####Version 1.4-10
- added lock switches for control panels (backport from 1.11)
- Can only be turned on by someone with the correct key to prevent unauthorized access
- up to 10 keys can be added to a keyring to reduce inventory spam
- IC2 items can be added to the appropriate sections of the engineers toolbox (backport from 1.11)
- Components (lighted button, indicator light, etc.) on panels now actually light up (backport from 1.11)
- Fixed power loss when no energy is being transmitted
####Version 1.4-9
#####Version 1.4-9
- added Control Panels
- They can be used to control and monitor a lot of redstone signals from a few blocks
####Version 1.3-8
#####Version 1.3-8
- the converters and the motor don't have missing textures any more when using Chisel
####Version 1.3-7
#####Version 1.3-7
- added Jacob's Ladders/High voltage travelling arcs
- they don't have a particular purpose aside from looking nice
####Version 1.2-6
#####Version 1.2-6
- reduced the discrepancies between IC2 cables and Industrial Wires
- machines don't explode when they shouldn't except in some corner cases
- potentially fixed missing textures on the mechanical converters
- added Chinese translations (thanks SihenZhang)
####Version 1.2-5 (10,000 download celebratory release)
#####Version 1.2-5 (10,000 download celebratory release)
- added mechanical converters and the rotational motor
- they convert between IE rotational energy (windmill, dynamo etc) and IC2 kinetic energy
- Rotational motor: produces IE rotational energy from IF
@ -185,18 +54,18 @@
- Can be disabled in the config
- wire coils show when they are out of range (to match the behavior of IE coils in the latest dev version)
####Version 1.1-4
#####Version 1.1-4
- fixed an insane amount of log-spam in an edgecase (probably a Vanilla or Forge bug)
- added config values for wire length per connection and per coil item
####Version 1.1-3
#####Version 1.1-3
- fixed incompatibility with IE build 48
- reduced the amount of calls to core IE classes to make such incompatibilities less likely
- fixed localization of the creative tab
####Version 1.1-2
#####Version 1.1-2
- wire coils now use a different amount of wire depending on how long the connection is
- wire coils are crafted by placing any amount of IC2 cables and/or the corresponding wire coils in a crafting table now
- added Glass Fiber Wire
- changed license to GPL3
- changed the amount of connectors/relays the recipes yield
- changed the amount of connectors/relays the recipes yield

View file

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip

View file

@ -1,32 +1,31 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires;
package malte0811.industrialWires;
import malte0811.industrialwires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialwires.blocks.controlpanel.TileEntityRSPanel;
import malte0811.industrialwires.blocks.converter.TileEntityMechMB;
import malte0811.industrialwires.blocks.hv.TileEntityJacobsLadder;
import malte0811.industrialwires.blocks.hv.TileEntityMarx;
import malte0811.industrialwires.containers.ContainerPanelComponent;
import malte0811.industrialwires.containers.ContainerPanelCreator;
import malte0811.industrialwires.containers.ContainerRSPanelConn;
import malte0811.industrialwires.containers.ContainerRenameKey;
import malte0811.industrialwires.mech_mb.MechEnergy;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.containers.ContainerPanelCreator;
import malte0811.industrialWires.containers.ContainerRSPanelConn;
import malte0811.industrialWires.containers.ContainerRenameKey;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
@ -35,8 +34,6 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
import java.util.Set;
public class CommonProxy implements IGuiHandler {
public void preInit() {
}
@ -50,8 +47,6 @@ public class CommonProxy implements IGuiHandler {
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
}
public void startTinnitus() {
}
@Override
public Container getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@ -60,8 +55,8 @@ public class CommonProxy implements IGuiHandler {
if (te instanceof TileEntityPanelCreator) {
return new ContainerPanelCreator(player.inventory, (TileEntityPanelCreator) te);
}
if (te instanceof TileEntityRSPanel) {
return new ContainerRSPanelConn((TileEntityRSPanel) te);
if (te instanceof TileEntityRSPanelConn) {
return new ContainerRSPanelConn((TileEntityRSPanelConn) te);
}
} else if (ID == 1) {//ITEM GUI
EnumHand h = z == 1 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
@ -81,18 +76,4 @@ public class CommonProxy implements IGuiHandler {
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
public void playMarxBang(TileEntityMarx tileEntityMarx, Vec3d vec3d, float energy) {}
public void updateMechMBTurningSound(TileEntityMechMB te, MechEnergy energy) {}
public void stopAllSoundsExcept(BlockPos pos, Set<?> excluded) {}
public boolean isSingleplayer() {
return false;
}
public boolean isValidTextureSource(ItemStack stack) {
return stack.getItem() instanceof ItemBlock;
}
}

View file

@ -0,0 +1,25 @@
package malte0811.industrialWires;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.tool.ToolboxHandler;
import ic2.api.item.IBoxable;
import ic2.api.item.IC2Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ExtraIC2Compat {
public static void addToolConmpat() {
Item tinnedFood = IC2Items.getItem("filled_tin_can").getItem();
ItemStack emptyMug = IC2Items.getItem("mug", "empty");
ToolboxHandler.addFoodType((s)->s.getItem()==tinnedFood);
ToolboxHandler.addFoodType((s)->
s.getItem()==emptyMug.getItem()&&!ItemStack.areItemStacksEqual(emptyMug, ApiUtils.copyStackWithAmount(s, 1))
);
Item cable = IC2Items.getItem("cable", "type:copper,insulation:0").getItem();
ToolboxHandler.addWiringType((s, w)->s.getItem()==cable);
ToolboxHandler.addToolType((s)-> {
Item a = s.getItem();
return a instanceof IBoxable && ((IBoxable) a).canBeStoredInToolbox(s);
});
}
}

View file

@ -1,26 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires;
package malte0811.industrialwires.hv;
import malte0811.industrialwires.blocks.hv.TileEntityMarx;
public interface IMarxTarget {
public interface IIC2Connector {
/**
* called when the block with this TE is hit by a Marx discharge.
* Return true to prevent the block from being destroyed.
* @return leftover energy.
*/
boolean onHit(double energy, TileEntityMarx master);
double insertEnergy(double eu, boolean simulate);
}

View file

@ -1,45 +1,33 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires;
package malte0811.industrialWires;
import blusunrize.immersiveengineering.common.Config.IEConfig;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.Config.Comment;
import net.minecraftforge.common.config.Config.RequiresMcRestart;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Config(modid = IndustrialWires.MODID)
@Mod.EventBusSubscriber
public class IWConfig {
@Comment({"The maximum length of a single connection.", "Order: Tin, Copper, Gold, HV, Glass Fiber"})
public static int[] maxLengthPerConn = {16, 16, 16, 32, 32};
@Comment({"The maximum length of wire a coil item.", "Order: Tin, Copper, Gold, HV, Glass Fiber (as above)"})
public static int[] maxLengthOnCoil = {1024, 1024, 1024, 2048, 2048};
@Comment({"The factor between the IF transfer rate of the wires and the IF transfer rate corresponding to the EU transfer rate.",
"The default value results in the same transfer rates as the standard IE wires"})
public static double wireRatio = .5;
@Comment({"The EU IO rates of the wires. Order is Tin, Copper, Gold, HV, Glass Fiber"})
public static double[] ioRatesEU = {32, 128, 512, 2048, 8192};
@Comment({"The EU loss rates of the wires (EU per block). Order is Tin, Copper, Gold, HV, Glass Fiber"})
public static double[] euLossPerBlock = {.2, .2, .4, .8, .025};
@Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"})
@RequiresMcRestart
public static boolean enableConversion = true;
public static MechConversion mech;
@ -53,57 +41,27 @@ public class IWConfig {
public static double kinPerEu = 4;
@Comment({"The maximum amount of IF that can be converted to rotational energy", "by one motor in one tick (default: 100)"})
@Config.RequiresWorldRestart
public static int maxIfToMech = 100;
@Comment({"The efficiency of the IF motor. The default value of 0.9 means that 10% of the energy are lost in the conversion."})
public static double ifMotorEfficiency = .9;
@Comment({"The maximum amount of IE rotational energy that can be converted into IC2 kinetic energy", "by one converter in one tick"})
@Config.RequiresWorldRestart
public static double maxRotToKin = 200;
public static double maxRotToKin = 50;
@Comment({"The efficiency of the conversion from IE rotational energy to IC2 kinetic energy"})
public static double rotToKinEfficiency = .7;
@Comment({"The maximum amount of IC2 kinetic energy that can be converted into IE rotational energy", "by one converter in one tick"})
@Config.RequiresWorldRestart
public static int maxKinToRot = 600;
public static int maxKinToRot = 2400;
@Comment({"The efficiency of the conversion from IC2 kinetic energy to IE rotational energy"})
public static double kinToRotEfficiency = .8;
@Comment({"The conversion factor between Joules (the SI unit) and RF. Used for the Marx generator and the rotary converters",
"With the default value the IE diesel generator produces 200kW"})
public static double joulesPerRF = 200e3 / (20 * IEConfig.Machines.dieselGen_output);
@Comment({"What energy types can be used with the mechanical multiblock. 0: None (Probably useless),",
"1: EU (Currently useless), 2: FE, 3:EU and FE (allows conversion, default)"})
public static int multiblockEnergyType = 3;
public static boolean allowMBFE() {
return (multiblockEnergyType & 2) != 0;
}
public static boolean allowMBEU() {
return (multiblockEnergyType & 1) != 0 && IndustrialWires.hasIC2;
}
}
public static HVStuff hv;
public static class HVStuff {
@Comment({"The amount of EU a Jacobs Ladder uses per tick, sorted by size of the ladder"})
public static double[] jacobsUsageWatt = {40, 300, 2000};
public static double[] jacobsUsageEU = {20, 50, 100};
@Comment({"The damage dealt by a small Jacobs Ladder. Normal Ladders deal twice this damage, huge ones 3 times as much"})
public static float jacobsBaseDmg = 5;
@Comment({"The effect of standing somewhat close to a Marx generator discharge.",
"0: Tinnitus, 1: Nausea, 2: normal damage"})
public static int marxSoundDamage = 0;
@Comment({"Set to false to disable shaders. They are used for rendering the Marx generator and the Jacob's ladder."})
public static boolean enableShaders = true;
}
@SubscribeEvent
public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent ev) {
if (ev.getModID().equals(IndustrialWires.MODID)) {
ConfigManager.sync(IndustrialWires.MODID, Config.Type.INSTANCE);
}
}
}
}

View file

@ -0,0 +1,147 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires;
import malte0811.industrialWires.blocks.BlockJacobsLadder;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.controlpanel.*;
import malte0811.industrialWires.blocks.converter.BlockMechanicalConverter;
import malte0811.industrialWires.blocks.converter.TileEntityIEMotor;
import malte0811.industrialWires.blocks.converter.TileEntityMechICtoIE;
import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC;
import malte0811.industrialWires.blocks.wire.*;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.network.MessageGUIInteract;
import malte0811.industrialWires.network.MessageItemSync;
import malte0811.industrialWires.network.MessagePanelInteract;
import malte0811.industrialWires.network.MessageTileSyncIW;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = IndustrialWires.MODID, version = IndustrialWires.VERSION, dependencies = "required-after:immersiveengineering@[0.10-58,);required-after:ic2",
certificateFingerprint = "7e11c175d1e24007afec7498a1616bef0000027d")
public class IndustrialWires {
public static final String MODID = "industrialwires";
public static final String VERSION = "${version}";
public static BlockIC2Connector ic2conn;
public static BlockMechanicalConverter mechConv;
public static BlockJacobsLadder jacobsLadder;
public static BlockPanel panel;
public static ItemIC2Coil coil;
public static ItemPanelComponent panelComponent;
public static ItemKey key;
public static final SimpleNetworkWrapper packetHandler = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
@Mod.Instance(MODID)
public static IndustrialWires instance = new IndustrialWires();
public static CreativeTabs creativeTab = new CreativeTabs(MODID) {
@Override
public ItemStack getTabIconItem() {
return new ItemStack(coil, 1, 2);
}
};
@SidedProxy(clientSide = "malte0811.industrialWires.client.ClientProxy", serverSide = "malte0811.industrialWires.CommonProxy")
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent e) {
new IWConfig();
ic2conn = new BlockIC2Connector();
if (IWConfig.enableConversion)
mechConv = new BlockMechanicalConverter();
jacobsLadder = new BlockJacobsLadder();
panel = new BlockPanel();
coil = new ItemIC2Coil();
panelComponent = new ItemPanelComponent();
key = new ItemKey();
GameRegistry.registerTileEntity(TileEntityIC2ConnectorTin.class, MODID + "ic2ConnectorTin");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorCopper.class, MODID + "ic2ConnectorCopper");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorGold.class, MODID + "ic2ConnectorGold");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorHV.class, MODID + "ic2ConnectorHV");
GameRegistry.registerTileEntity(TileEntityIC2ConnectorGlass.class, MODID + "ic2ConnectorGlass");
GameRegistry.registerTileEntity(TileEntityJacobsLadder.class, MODID + ":jacobsLadder");
GameRegistry.registerTileEntity(TileEntityPanel.class, MODID + ":control_panel");
GameRegistry.registerTileEntity(TileEntityRSPanelConn.class, MODID + ":control_panel_rs");
GameRegistry.registerTileEntity(TileEntityPanelCreator.class, MODID + ":panel_creator");
GameRegistry.registerTileEntity(TileEntityUnfinishedPanel.class, MODID + ":unfinished_panel");
if (mechConv != null) {
GameRegistry.registerTileEntity(TileEntityIEMotor.class, MODID + ":ieMotor");
GameRegistry.registerTileEntity(TileEntityMechICtoIE.class, MODID + ":mechIcToIe");
GameRegistry.registerTileEntity(TileEntityMechIEtoIC.class, MODID + ":mechIeToIc");
}
if (IC2Wiretype.IC2_TYPES == null) {
throw new IllegalStateException("No IC2 wires registered");
}
proxy.preInit();
}
@EventHandler
public void init(FMLInitializationEvent e) {
Recipes.addRecipes();
ExtraIC2Compat.addToolConmpat();
packetHandler.registerMessage(MessageTileSyncIW.HandlerClient.class, MessageTileSyncIW.class, 0, Side.CLIENT);
packetHandler.registerMessage(MessagePanelInteract.HandlerServer.class, MessagePanelInteract.class, 1, Side.SERVER);
packetHandler.registerMessage(MessageGUIInteract.HandlerServer.class, MessageGUIInteract.class, 2, Side.SERVER);
packetHandler.registerMessage(MessageItemSync.HandlerServer.class, MessageItemSync.class, 3, Side.SERVER);
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
}
@EventHandler
public void postInit(FMLPostInitializationEvent e) {
proxy.postInit();
}
@EventHandler
public void remap(FMLMissingMappingsEvent ev) {
for (FMLMissingMappingsEvent.MissingMapping miss : ev.get()) {
String name = miss.resourceLocation.getResourcePath();
switch (name) {
case "ic2connector":
if (miss.type == GameRegistry.Type.ITEM) {
miss.remap(Item.getItemFromBlock(IndustrialWires.ic2conn));
} else {
miss.remap(IndustrialWires.ic2conn);
}
break;
case "ic2wirecoil":
miss.remap(IndustrialWires.coil);
break;
}
}
}
}

View file

@ -0,0 +1,182 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires;
import blusunrize.immersiveengineering.api.tool.AssemblerHandler;
import blusunrize.immersiveengineering.common.IEContent;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Connector;
import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration0;
import blusunrize.immersiveengineering.common.blocks.stone.BlockTypes_StoneDecoration;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.crafting.*;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialWires.IndustrialWires.*;
public class Recipes {
public static void addRecipes() {
addCustomRecipes();
addConnectors();
if (mechConv != null) {
addMechConverters();
}
addJacobs();
registerPanels();
}
private static void addConnectors() {
ItemStack glassCable = IC2Items.getItem("cable", "type:glass,insulation:0");
//CONNECTORS
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 0), " t ", "rtr", "rtr", 't', "ingotTin", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 2), " c ", "rcr", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 4), " g ", "rgr", "rgr", 'g', "ingotGold", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 6), " i ", "rir", "rir", 'i', "ingotIron", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 8), " c ", "rcr", "rcr", 'c', glassCable, 'r', "itemRubber"));
//RELAYS
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 1), " t ", "rtr", 't', "ingotTin", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 3), " c ", "rcr", 'c', "ingotCopper", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 5), " g ", "rgr", 'g', "ingotGold", 'r', "itemRubber"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 4, 7), " i ", "gig", "gig", 'i', "ingotIron", 'g', new ItemStack(IEContent.blockStoneDecoration, 1, BlockTypes_StoneDecoration.INSULATING_GLASS.getMeta())));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ic2conn, 2, 9), " c ", "grg", "grg", 'r', "itemRubber", 'c', glassCable, 'g', new ItemStack(IEContent.blockStoneDecoration, 1, BlockTypes_StoneDecoration.INSULATING_GLASS.getMeta())));
}
private static void addMechConverters() {
ItemStack shaftIron = IC2Items.getItem("crafting", "iron_shaft");
ItemStack shaftSteel = IC2Items.getItem("crafting", "steel_shaft");
ItemStack ironMechComponent = new ItemStack(IEContent.itemMaterial, 1, 8);
ItemStack steelMechComponent = new ItemStack(IEContent.itemMaterial, 1, 9);
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 0), " s ", "ici", "mum", 's', "stickIron",
'i', "ingotIron", 'c', new ItemStack(IEContent.blockMetalDecoration0, 1, BlockTypes_MetalDecoration0.COIL_LV.getMeta()),
'u', "ingotCopper", 'm', ironMechComponent));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 2), "iIi", "sbS", "mrm", 's', "blockSheetmetalIron",
'i', "plateIron", 'I', shaftIron,
'b', "ingotBronze", 'm', steelMechComponent,
'S', "blockSheetmetalSteel", 'r', "stickSteel"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(mechConv, 1, 1), "mrm", "sbS", "iIi", 's', "blockSheetmetalIron",
'i', "plateSteel", 'I', shaftSteel,
'b', "ingotBronze", 'm', ironMechComponent,
'S', "blockSheetmetalSteel", 'r', "stickIron"));
}
private static void addCustomRecipes() {
RecipeSorter.register("industrialwires:key_ring", RecipeKeyRing.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:key_lock", RecipeKeyLock.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:cmp_copy", RecipeComponentCopy.class, RecipeSorter.Category.SHAPED, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:coilLength", RecipeCoilLength.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:init_pc", RecipeInitPC.class, RecipeSorter.Category.SHAPED, "after:forge:shapedore");
GameRegistry.addRecipe(new RecipeKeyLock());
GameRegistry.addRecipe(new RecipeKeyRing(true));
GameRegistry.addRecipe(new RecipeKeyRing(false));
GameRegistry.addRecipe(new RecipeComponentCopy());
for (int i = 0; i < IC2Wiretype.IC2_TYPES.length; i++) {
GameRegistry.addRecipe(new RecipeCoilLength(i));
}
AssemblerHandler.registerRecipeAdapter(RecipeCoilLength.class, new AllRecipeAdapter<>());
AssemblerHandler.registerRecipeAdapter(RecipeComponentCopy.class, new AllRecipeAdapter<>());
AssemblerHandler.registerRecipeAdapter(RecipeKeyLock.class, new AllRecipeAdapter<>());
AssemblerHandler.registerRecipeAdapter(RecipeKeyRing.class, new AllRecipeAdapter<>());
}
private static void registerPanels() {
// CONTROL PANELS
ItemStack drillHeadIron = new ItemStack(IEContent.itemDrillhead, 1, 1);
ItemStack motor = IC2Items.getItem("crafting", "electric_motor");
ItemStack advAlloy = IC2Items.getItem("crafting", "alloy");
ItemStack coil = IC2Items.getItem("crafting", "coil");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 1, BlockTypes_Panel.CREATOR.ordinal()),
"rmr", "rdr", "rar", 'r', "stickSteel", 'm', motor, 'd', drillHeadIron, 'a', advAlloy));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 4, BlockTypes_Panel.DUMMY.ordinal()),
" r ", "rmr", " r ", 'r', "dustRedstone", 'm', PanelUtils.getPanelBase()));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 1, BlockTypes_Panel.RS_WIRE.ordinal()),
"c", "d", 'd', new ItemStack(panel, 1, BlockTypes_Panel.DUMMY.ordinal()), 'c',
new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.CONNECTOR_REDSTONE.ordinal())));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panel, 1, BlockTypes_Panel.UNFINISHED.ordinal()),
"ppp", "www", "ppp", 'p', "plateIron", 'w', "wireCopper"));
// PANEL COMPONENTS
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 0),
"dustGlowstone", Blocks.STONE_BUTTON, "wireCopper"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 4, 1),
"paper", "plateIron"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 2),
"dustGlowstone", "dustRedstone", "wireCopper"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 3),
Blocks.STONE_BUTTON, new ItemStack(IEContent.itemWireCoil, 1, 2), "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panelComponent, 1, 4),
"r", "g", "c", 'r', "itemRubber", 'g', "ingotHOPGraphite", 'c', coil));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 5),
"stickIron", Blocks.LEVER, "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panelComponent, 1, 6),
"aaa", "asa", 'a', "plateAluminum", 's', new ItemStack(panelComponent, 2, 5)));
GameRegistry.addRecipe(new RecipeInitPC(new ItemStack(panelComponent, 1, 7),
"rdr", " w ", 'r', "stickSteel", 'd', Items.IRON_DOOR, 'w', "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(key, 1, 0),
"rrp", 'r', "stickSteel", 'p', "plateSteel"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 8),
"wireCopper", new ItemStack(IEContent.itemTool, 1, 2)));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(key, 1, 2), " r ", "r r", " r ", 'r', "stickSteel"));
}
private static void addJacobs() {
ItemStack mvTransformer = IC2Items.getItem("te", "mv_transformer");
ItemStack copperCable = IC2Items.getItem("cable", "type:copper,insulation:0");
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 0), "c c", " h ", "sts", 'c', copperCable, 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', mvTransformer));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 1), "c c", "h h", "sts", 'c', "ingotCopper", 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.TRANSFORMER.ordinal())));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(jacobsLadder, 1, 2), "c c", "hhh", "sts", 'c', "blockCopper", 'h', Blocks.HARDENED_CLAY,
's', "ingotSteel", 't', new ItemStack(IEContent.blockConnectors, 1, BlockTypes_Connector.TRANSFORMER_HV.ordinal())));
}
private static class AllRecipeAdapter<T extends IRecipe> implements AssemblerHandler.IRecipeAdapter<T> {
@Override
public AssemblerHandler.RecipeQuery[] getQueriedInputs(T recipe, NonNullList<ItemStack> in) {
List<AssemblerHandler.RecipeQuery> ret = new ArrayList<>();
for (int i = 0; i < in.size() - 1; i++) {
boolean added = false;
for (AssemblerHandler.RecipeQuery aRet : ret) {
if (ItemStack.areItemStacksEqual((ItemStack) aRet.query, in.get(i))) {
aRet.querySize++;
added = true;
break;
}
}
if (!added) {
ret.add(new AssemblerHandler.RecipeQuery(in.get(i), 1));
}
}
return ret.toArray(new AssemblerHandler.RecipeQuery[ret.size()]);
}
@Override
public AssemblerHandler.RecipeQuery[] getQueriedInputs(T arg0) {
return new AssemblerHandler.RecipeQuery[0];
}
}
}

View file

@ -1,51 +1,52 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.api.IEProperties;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction;
import blusunrize.immersiveengineering.common.util.Utils;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.util.MiscUtils;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.util.MiscUtils;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
public abstract class BlockIWBase extends Block {
@ -55,13 +56,13 @@ public abstract class BlockIWBase extends Block {
super(mat);
setHardness(3.0F);
setResistance(15.0F);
setTranslationKey(IndustrialWires.MODID + "." + name);
setRegistryName(IndustrialWires.MODID, name);
GameRegistry.register(this, new ResourceLocation(IndustrialWires.MODID, name));
GameRegistry.register(createItemBlock(), new ResourceLocation(IndustrialWires.MODID, name));
setUnlocalizedName(IndustrialWires.MODID + "." + name);
setCreativeTab(IndustrialWires.creativeTab);
IndustrialWires.blocks.add(this);
}
public ItemBlock createItemBlock() {
protected ItemBlock createItemBlock() {
return new ItemBlockIW(this);
}
@ -142,15 +143,6 @@ public abstract class BlockIWBase extends Block {
return super.getBoundingBox(state, source, pos);
}
@Override
public void addCollisionBoxToList(IBlockState state, @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull AxisAlignedBB entityBox,
@Nonnull List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_) {
AxisAlignedBB aabb = getBoundingBox(state, worldIn, pos).offset(pos);
if (entityBox.intersects(aabb)) {
collidingBoxes.add(aabb);
}
}
//mostly copied from IE
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
@ -179,9 +171,8 @@ public abstract class BlockIWBase extends Block {
}
return true;
}
}
if (te instanceof IPlayerInteraction) {
if (((IPlayerInteraction) te).interact(side, player, hand, heldItem, hitX, hitY, hitZ)) {
} else if (te instanceof IEBlockInterfaces.IPlayerInteraction) {
if (((IEBlockInterfaces.IPlayerInteraction) te).interact(side, player, hand, heldItem, hitX, hitY, hitZ)) {
return true;
}
}
@ -221,34 +212,5 @@ public abstract class BlockIWBase extends Block {
return getMetaFromState(state);
}
@Override
public int getStrongPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof IEBlockInterfaces.IRedstoneOutput) {
return ((IEBlockInterfaces.IRedstoneOutput) te).getStrongRSOutput(state, side);
}
return 0;
}
@Override
public int getWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof IEBlockInterfaces.IRedstoneOutput) {
return ((IEBlockInterfaces.IRedstoneOutput) te).getWeakRSOutput(state, side);
}
return 0;
}
@Override
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable EnumFacing side) {
if (side!=null) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof IEBlockInterfaces.IRedstoneOutput) {
return ((IEBlockInterfaces.IRedstoneOutput) te).canConnectRedstone(state, side);
}
}
return false;
}
protected abstract IProperty[] getProperties();
}

View file

@ -1,25 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.hv;
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialwires.blocks.BlockIWBase;
import malte0811.industrialwires.blocks.IMetaEnum;
import malte0811.industrialwires.blocks.IPlacementCheck;
import malte0811.industrialwires.blocks.hv.TileEntityJacobsLadder.LadderSize;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder.LadderSize;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@ -28,6 +28,7 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
@ -42,11 +43,10 @@ import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class BlockJacobsLadder extends BlockIWBase implements IMetaEnum, IPlacementCheck {
public static final String NAME = "jacobs_ladder";
private static PropertyEnum<LadderSize> size_property = PropertyEnum.create("size", LadderSize.class);
public BlockJacobsLadder() {
super(Material.IRON, NAME);
super(Material.IRON, "jacobs_ladder");
}
@Nonnull
@ -75,11 +75,11 @@ public class BlockJacobsLadder extends BlockIWBase implements IMetaEnum, IPlacem
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
return super.getStateFromMeta(meta).withProperty(size_property, TileEntityJacobsLadder.LadderSize.values()[meta]);
return super.getStateFromMeta(meta).withProperty(size_property, LadderSize.values()[meta]);
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
for (int i = 0; i < LadderSize.values().length; i++) {
list.add(new ItemStack(this, 1, i));
}
@ -143,16 +143,24 @@ public class BlockJacobsLadder extends BlockIWBase implements IMetaEnum, IPlacem
return new ItemStack(this, 1, getMetaFromState(state));
}
@Override
public void onEntityCollision(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
super.onEntityCollision(worldIn, pos, state, entityIn);
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
super.onEntityCollidedWithBlock(worldIn, pos, state, entityIn);
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof TileEntityJacobsLadder) {
((TileEntityJacobsLadder) te).onEntityTouch(entityIn);
}
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof TileEntityJacobsLadder) {
return ((TileEntityJacobsLadder) te).onActivated(playerIn, hand);
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
public boolean canPlaceBlockAt(World w, BlockPos pos, ItemStack stack) {
int dummyCount = LadderSize.values()[stack.getMetadata()].dummyCount;
@ -167,6 +175,6 @@ public class BlockJacobsLadder extends BlockIWBase implements IMetaEnum, IPlacem
@Override
public boolean rotateBlock(World world, @Nonnull BlockPos pos, @Nonnull EnumFacing axis) {
TileEntity te = world.getTileEntity(pos);
return te instanceof TileEntityJacobsLadder && ((TileEntityJacobsLadder) te).rotate(world, pos);
return te instanceof TileEntityJacobsLadder && ((TileEntityJacobsLadder) te).rotate(world, pos, axis);
}
}

View file

@ -1,18 +1,21 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxConnection;
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxProvider;

View file

@ -1,23 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.compat;
package malte0811.industrialWires.blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.util.math.AxisAlignedBB;
public interface IBlockAction<P, R> {
R run(World w, BlockPos pos, P f);
public interface IBlockBoundsIW {
AxisAlignedBB getBoundingBox();
}

View file

@ -1,31 +1,29 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGeneralMultiblock;
import net.minecraft.block.state.IBlockState;
public interface IHasDummyBlocksIW extends IGeneralMultiblock {
public interface IHasDummyBlocksIW {
void placeDummies(IBlockState state);
void breakDummies();
boolean isDummy();
default boolean isLogicDummy() {
return isDummy();
}
}

View file

@ -1,18 +1,21 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
public interface IMetaEnum {
Object[] getValues();

View file

@ -1,19 +1,22 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;

View file

@ -1,19 +1,22 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;

View file

@ -1,25 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface ISyncReceiver {
@SideOnly(Side.CLIENT)
void onSync(NBTTagCompound nbt);
}

View file

@ -1,21 +1,23 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import malte0811.industrialwires.IndustrialWires;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@ -39,18 +41,16 @@ public class ItemBlockIW extends ItemBlock {
values = null;
}
hasSubtypes = true;
setRegistryName(b.getRegistryName());
setCreativeTab(IndustrialWires.creativeTab);
}
@Nonnull
@Override
public String getTranslationKey(ItemStack stack) {
public String getUnlocalizedName(ItemStack stack) {
int meta = stack.getMetadata();
if (values != null) {
return block.getTranslationKey() + "." + values[meta].toString().toLowerCase();
return block.getUnlocalizedName() + "." + values[meta].toString().toLowerCase();
} else {
return block.getTranslationKey();
return block.getUnlocalizedName();
}
}

View file

@ -1,32 +1,33 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks;
package malte0811.industrialWires.blocks;
import com.google.common.collect.ImmutableSet;
import malte0811.industrialwires.IndustrialWires;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
public abstract class TileEntityIWBase extends TileEntity {
protected static final String ENERGY_TAG = "energy";
protected static final String BUFFER_TAG = "buffer";
protected static final String DIR_TAG = "dir";
@Nonnull
@Override
@ -56,36 +57,11 @@ public abstract class TileEntityIWBase extends TileEntity {
}
@Override
@SideOnly(Side.CLIENT)
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
readNBT(pkt.getNbtCompound(), true);
}
public void triggerRenderUpdate() {
if (world!=null) {
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
world.addBlockEvent(pos, state.getBlock(), 255, 0);
}
}
@Override
public void invalidate() {
super.invalidate();
if (world.isRemote) {
IndustrialWires.proxy.stopAllSoundsExcept(pos, ImmutableSet.of());
}
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
if (world.isRemote) {
IndustrialWires.proxy.stopAllSoundsExcept(pos, ImmutableSet.of());
}
}
public abstract void writeNBT(NBTTagCompound out, boolean updatePacket);
public abstract void readNBT(NBTTagCompound in, boolean updatePacket);

View file

@ -1,39 +1,35 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.hv;
package malte0811.industrialWires.blocks;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import blusunrize.immersiveengineering.common.blocks.TileEntityIEBase;
import com.elytradev.mirage.lighting.IColoredLight;
import com.elytradev.mirage.lighting.Light;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import malte0811.industrialwires.IWConfig;
import malte0811.industrialwires.IWDamageSources;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.IBlockBoundsIW;
import malte0811.industrialwires.blocks.IHasDummyBlocksIW;
import malte0811.industrialwires.blocks.ISyncReceiver;
import malte0811.industrialwires.compat.Compat;
import malte0811.industrialwires.network.MessageTileSyncIW;
import malte0811.industrialwires.util.Beziers;
import malte0811.industrialwires.util.ConversionUtil;
import malte0811.industrialwires.util.JouleEnergyStorage;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.network.MessageTileSyncIW;
import malte0811.industrialWires.util.Beziers;
import malte0811.industrialWires.util.DualEnergyStorage;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@ -44,51 +40,40 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ITickable;
import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static malte0811.industrialwires.IndustrialWires.hasIC2;
import static malte0811.industrialwires.util.MiscUtils.interpolate;
@Optional.InterfaceList({
@Optional.Interface(modid = "ic2", iface = "ic2.api.energy.tile.IEnergySink"),
@Optional.Interface(modid = "mirage", iface = "com.elytradev.mirage.lighting.IColoredLight")
})
public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickable, IHasDummyBlocksIW, ISyncReceiver,
IEnergySink, IBlockBoundsIW, IDirectionalTile, IColoredLight, IEBlockInterfaces.IPlayerInteraction {
public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickable, IHasDummyBlocksIW, ISyncReceiver, IEnergySink, IBlockBoundsIW, IDirectionalTile {
public EnumFacing facing = EnumFacing.NORTH;
private JouleEnergyStorage energy;
private DualEnergyStorage energy;
public LadderSize size;
public Vec3d[] controls;
//first and last move along the "rails", only the middle points move in bezier curves
private Vec3d[][] controlControls;
public Vec3d[][] controlControls;
// movement of the controls in blocks/tick
public Vec3d[] controlMovement;
private double t = 0;
private int dummy = 0;
public int dummy = 0;
public int timeTillActive = -1;
private double tStep = 0;
private double consumtionJoule;
private double consumtionEU;
private boolean addedToIC2Net = false;
private int soundPhase;
private Vec3d soundPos;
public double salt;
TileEntityJacobsLadder(LadderSize s) {
public TileEntityJacobsLadder(LadderSize s) {
size = s;
initControl();
}
@ -103,26 +88,21 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
controlControls = new Vec3d[size.arcPoints - 2][size.movementPoints];
controlMovement = new Vec3d[size.arcPoints];
int sizeId = size.ordinal();
consumtionJoule = IWConfig.HVStuff.jacobsUsageWatt[sizeId];
energy = new JouleEnergyStorage(20 * consumtionJoule,
40 * consumtionJoule);
}
@Override
public void onLoad() {
super.onLoad();
Compat.loadIC2Tile.accept(this);
consumtionEU = IWConfig.HVStuff.jacobsUsageEU[sizeId];
energy = new DualEnergyStorage(20 * consumtionEU, 2 * consumtionEU);
}
@Override
public void update() {
ApiUtils.checkForNeedlessTicking(this);
if (isDummy()) {
return;
}
if (!world.isRemote) {
if ((controlControls[0][0] == null || timeTillActive == -1 || t >= 1)
&& energy.getEnergyStoredJ() >= 2 * consumtionJoule) {
if (!addedToIC2Net) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToIC2Net = true;
}
if ((controlControls[0][0] == null || timeTillActive == -1 || t >= 1) && energy.getEnergyStoredEU() >= 2 * consumtionEU) {
for (int j = 0; j < size.movementPoints; j++) {
double y = j * (size.height + size.extraHeight) / (double) (size.movementPoints - 1) + size.innerPointOffset;
double width = widthFromHeight(y);
@ -139,9 +119,9 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
tStep = 1D / (int) (.875 * size.tickToTop + world.rand.nextInt(size.tickToTop / 4));
IndustrialWires.packetHandler.sendToAll(new MessageTileSyncIW(this, writeArcStarter()));
} else if (timeTillActive == 0 && t < 1) {
double extracted = energy.extract(consumtionJoule, 1, true);
if (extracted >= consumtionJoule) {
energy.extract(consumtionJoule, 1, false);
double extracted = energy.extractEU(consumtionEU, false);
if (extracted >= consumtionEU) {
energy.extractEU(consumtionEU, true);
} else {
timeTillActive = -1 - size.delay;
NBTTagCompound nbt = new NBTTagCompound();
@ -220,7 +200,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
initControl();
}
dummy = nbt.getInteger("dummy");
energy.readFromNBT(nbt.getCompoundTag("energy"));
energy = DualEnergyStorage.readFromNBT(nbt.getCompoundTag("energy"));
facing = EnumFacing.HORIZONTALS[nbt.getInteger("facing")];
salt = nbt.getDouble("salt");
}
@ -244,7 +224,6 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
return nbt;
}
@SideOnly(Side.CLIENT)
private void readArcStarter(NBTTagCompound nbt) {
controlControls = read2DVecArray(nbt.getTagList("ctrlCtrl", 9));
tStep = nbt.getDouble("tStep");
@ -317,7 +296,6 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
}
@Override
@SideOnly(Side.CLIENT)
public void onSync(NBTTagCompound nbt) {
if (nbt.hasKey("salt")) {
salt = nbt.getDouble("salt");
@ -330,7 +308,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
}
}
private boolean isActive() {
public boolean isActive() {
if (isDummy()) {
TileEntity master = world.getTileEntity(pos.down(dummy));
return master instanceof TileEntityJacobsLadder && ((TileEntityJacobsLadder) master).isActive();
@ -348,12 +326,11 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
}
private void hurtEntity(Entity e) {
e.attackEntityFrom(IWDamageSources.dmg_jacobs, IWConfig.HVStuff.jacobsBaseDmg * (size.ordinal() + 1));
e.attackEntityFrom(new DamageSource("industrialwires.jacobs_ladder"), IWConfig.HVStuff.jacobsBaseDmg * (size.ordinal() + 1));
}
@Override
public boolean interact(@Nonnull EnumFacing side, @Nonnull EntityPlayer player,@Nonnull EnumHand hand,
@Nonnull ItemStack heldItem, float hitX, float hitY, float hitZ) {
public boolean onActivated(EntityPlayer player, EnumHand hand) {
ItemStack heldItem = player.getHeldItem(hand);
TileEntity masterTE = dummy == 0 ? this : world.getTileEntity(pos.down(dummy));
if (masterTE instanceof TileEntityJacobsLadder) {
TileEntityJacobsLadder master = (TileEntityJacobsLadder) masterTE;
@ -389,7 +366,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
return false;
}
public boolean rotate(World world, BlockPos pos) {
public boolean rotate(World world, BlockPos pos, EnumFacing axis) {
if (isActive()) {
return false;
}
@ -415,25 +392,21 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
//ENERGY
@Override
@Optional.Method(modid = "ic2")
public double getDemandedEnergy() {
return energy.getRequested(ConversionUtil.euPerJoule());
return energy.getEURequested();
}
@Override
@Optional.Method(modid = "ic2")
public int getSinkTier() {
return 4;
}
@Override
@Optional.Method(modid = "ic2")
public double injectEnergy(EnumFacing dir, double amount, double voltage) {
return amount - energy.insert(amount, ConversionUtil.joulesPerEu(), true);
return amount - energy.insertEU(amount, true);
}
@Override
@Optional.Method(modid = "ic2")
public boolean acceptsEnergyFrom(IEnergyEmitter iEnergyEmitter, EnumFacing enumFacing) {
return !isDummy() && enumFacing == facing;
}
@ -448,7 +421,7 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (hasCapability(capability, facing)) {
if (capability == CapabilityEnergy.ENERGY) {
return CapabilityEnergy.ENERGY.cast(energy);
return (T) new EnergyCap();
}
}
return null;
@ -456,24 +429,24 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
@Override
public void onChunkUnload() {
if (hasIC2) {
Compat.unloadIC2Tile.accept(this);
}
if (!world.isRemote && addedToIC2Net)
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToIC2Net = false;
super.onChunkUnload();
}
@Override
public void invalidate() {
if (hasIC2)
Compat.unloadIC2Tile.accept(this);
if (world.isRemote) {
if (!world.isRemote && addedToIC2Net) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
} else if (world.isRemote) {
//stop sound
IndustrialWires.proxy.playJacobsLadderSound(this, -1, soundPos);
}
addedToIC2Net = false;
super.invalidate();
}
@Nonnull
@Override
public AxisAlignedBB getRenderBoundingBox() {
@ -533,47 +506,6 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
return false;
}
private static final float[] saltColor = {1, 190 / 255F, 50 / 255F};
private static final float[] airColor = {1, .85F, 1};
private static final int factor = 20;
private static final double smallMin = Math.exp(-.5);
private static final double normalMin = Math.exp(-.25 * factor);
private static final double hugeMin = Math.exp(-.75 * factor);
public static float[] getColor(double t, double salt, LadderSize size) {
salt = Math.min(salt, 1);
double saltyness = 0;
double t2 = t - .5;
switch (size) {
case SMALL:
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(t2)) - smallMin));
break;
case NORMAL:
saltyness = salt * (1 - .9 * (Math.exp(-factor * t2 * t2) - normalMin));
break;
case HUGE:
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(factor * t2 * t2 * t2)) - hugeMin));
break;
}
return interpolate(saltyness, saltColor, 1 - saltyness, airColor);
}
@Nullable
@Override
@SideOnly(Side.CLIENT)
@Optional.Method(modid = "mirage")
public Light getColoredLight() {
if (timeTillActive == 0) {
float[] color = getColor(0, salt, size);
return Light.builder().pos(pos.getX()+.5,
Beziers.getPoint(.5, controls).y+pos.getY()+size.bottomDistance+1,
pos.getZ()+.5)
.color(color[0], color[1], color[2], 1)
.radius(size.soundVolume/3)
.build();
}
return null;
}
public enum LadderSize implements IStringSerializable {
/*
@ -634,4 +566,37 @@ public class TileEntityJacobsLadder extends TileEntityIEBase implements ITickabl
return name().toLowerCase();
}
}
public class EnergyCap implements IEnergyStorage {
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
return (int) energy.insertIF(maxReceive, !simulate);
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return 0;
}
@Override
public int getEnergyStored() {
return (int) energy.getEnergyStoredIF();
}
@Override
public int getMaxEnergyStored() {
return (int) energy.getMaxStoredIF();
}
@Override
public boolean canExtract() {
return false;
}
@Override
public boolean canReceive() {
return true;
}
}
}

View file

@ -1,28 +1,30 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.controlpanel;
package malte0811.industrialWires.blocks.controlpanel;
import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.BlockIWBase;
import malte0811.industrialwires.blocks.IMetaEnum;
import malte0811.industrialwires.controlpanel.PanelComponent;
import malte0811.industrialwires.controlpanel.PropertyComponents;
import malte0811.industrialwires.util.MiscUtils;
import net.minecraft.block.Block;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.controlpanel.PropertyComponents;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@ -30,6 +32,7 @@ import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -46,19 +49,18 @@ import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class BlockPanel extends BlockIWBase implements IMetaEnum {
public static final PropertyEnum<BlockTypes_Panel> type = PropertyEnum.create("type", BlockTypes_Panel.class);
public static final String NAME = "control_panel";
public BlockPanel() {
super(Material.IRON, NAME);
super(Material.IRON, "control_panel");
lightOpacity = 0;
}
@Override
public ItemBlock createItemBlock() {
protected ItemBlock createItemBlock() {
return new ItemBlockPanel(this);
}
@ -66,7 +68,6 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer) {
switch (state.getValue(type)) {
case TOP:
case SINGLE_COMP:
return layer == BlockRenderLayer.CUTOUT;
case RS_WIRE:
return layer == BlockRenderLayer.TRANSLUCENT || layer == BlockRenderLayer.SOLID;
@ -78,22 +79,16 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
@Override
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
switch (state.getValue(type)) {
case TOP:
return new TileEntityPanel();
case RS_WIRE:
return new TileEntityRSPanelIE();
case CREATOR:
return new TileEntityPanelCreator();
case TOP:
return new TileEntityPanel();
case RS_WIRE:
return new TileEntityRSPanelConn();
case CREATOR:
return new TileEntityPanelCreator();
case UNFINISHED:
return new TileEntityUnfinishedPanel();
case SINGLE_COMP:
return new TileEntityComponentPanel();
case DUMMY:
return new TileEntityGeneralCP();
case OTHER_RS_WIRES:
return new TileEntityRSPanelOthers();
default:
return null;
default:
return null;
}
}
@ -121,11 +116,10 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
public IBlockState getActualState(@Nonnull IBlockState state, IBlockAccess worldIn, BlockPos pos) {
state = super.getActualState(state, worldIn, pos);
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof TileEntityComponentPanel) {
state.withProperty(type, BlockTypes_Panel.SINGLE_COMP);
} else if (te instanceof TileEntityPanel) {
if (te instanceof TileEntityPanel) {
state.withProperty(type, BlockTypes_Panel.TOP);
} else if (te instanceof TileEntityRSPanelIE) {
}
if (te instanceof TileEntityRSPanelConn) {
state.withProperty(type, BlockTypes_Panel.RS_WIRE);
}
return state;
@ -149,7 +143,6 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
return state.getValue(type).ordinal();
}
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
return super.getStateFromMeta(meta).withProperty(type, BlockTypes_Panel.values()[meta]);
@ -161,12 +154,9 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
BlockTypes_Panel[] values = BlockTypes_Panel.values();
for (int i = 0; i < values.length; i++) {
if (values[i].showInCreative()) {
list.add(new ItemStack(this, 1, i));
}
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
for (int i = 0; i < BlockTypes_Panel.values().length; i++) {
list.add(new ItemStack(itemIn, 1, i));
}
}
@ -194,7 +184,7 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ) && hand == EnumHand.MAIN_HAND) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityRSPanel) {
if (te instanceof TileEntityRSPanelConn) {
if (!world.isRemote) {
player.openGui(IndustrialWires.instance, 0, te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
}
@ -208,7 +198,7 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
}
return false;
}
return state.getValue(type) == BlockTypes_Panel.TOP||state.getValue(type) == BlockTypes_Panel.SINGLE_COMP;
return state.getValue(type) == BlockTypes_Panel.TOP;
}
@Override
@ -226,53 +216,36 @@ public class BlockPanel extends BlockIWBase implements IMetaEnum {
super.harvestBlock(worldIn, player, pos, state, te, stack);
if (te instanceof TileEntityPanel) {
for (PanelComponent pc:((TileEntityPanel) te).getComponents()) {
pc.dropItems();
pc.dropItems((TileEntityPanel)te);
}
}
}
@Override
public boolean canProvidePower(IBlockState state) {
return state.getValue(type)==BlockTypes_Panel.SINGLE_COMP;
}
@Override
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable EnumFacing side) {
return state.getValue(type)==BlockTypes_Panel.SINGLE_COMP;
}
@Override
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
if (blockState.getValue(type)==BlockTypes_Panel.SINGLE_COMP) {
TileEntity te = blockAccess.getTileEntity(pos);
if (te instanceof TileEntityComponentPanel&&side==((TileEntityComponentPanel) te).getComponents().getTop()) {
return ((TileEntityComponentPanel)te).getRSOutput();
public void breakBlock(@Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
super.breakBlock(worldIn, pos, state);
//break connections
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
for (BlockPos p : panels) {
if (!p.equals(pos)) {
TileEntity panelPart = worldIn.getTileEntity(p);
if (panelPart instanceof TileEntityPanel) {
((TileEntityPanel) panelPart).removeAllRSCons();
}
}
}
return 0;
}
@Override
public int getWeakPower(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
if (state.getValue(type)==BlockTypes_Panel.SINGLE_COMP) {
TileEntity te = blockAccess.getTileEntity(pos);
if (te instanceof TileEntityComponentPanel) {
return ((TileEntityComponentPanel)te).getRSOutput();
}
}
return 0;
}
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
if (!worldIn.isRemote) {
TileEntityGeneralCP panel = MiscUtils.getLoadedTE(worldIn, pos, TileEntityGeneralCP.class);
if (panel instanceof TileEntityComponentPanel) {
((TileEntityComponentPanel) panel).updateRSInput();
} else if (panel instanceof TileEntityRSPanelOthers) {
((TileEntityRSPanelOthers)panel).updateInput();
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
super.onBlockAdded(worldIn, pos, state);
List<BlockPos> panels = PanelUtils.discoverPanelParts(worldIn, pos, 11 * 11 * 11);
for (BlockPos p : panels) {
if (!p.equals(pos)) {
TileEntity panelPart = worldIn.getTileEntity(p);
if (panelPart instanceof TileEntityPanel) {
((TileEntityPanel) panelPart).firstTick = true;
}
}
}
}

View file

@ -1,21 +1,23 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.controlpanel;
package malte0811.industrialWires.blocks.controlpanel;
import malte0811.industrialwires.compat.Compat;
import net.minecraft.util.IStringSerializable;
import java.util.Locale;
@ -25,19 +27,14 @@ public enum BlockTypes_Panel implements IStringSerializable {
RS_WIRE,
DUMMY,
CREATOR,
UNFINISHED,
SINGLE_COMP,
OTHER_RS_WIRES;
UNFINISHED;
@Override
public String getName() {
return toString().toLowerCase(Locale.ENGLISH);
}
public boolean showInCreative() {
if (this==OTHER_RS_WIRES) {
return Compat.enableOtherRS;
}
return this != SINGLE_COMP;
public boolean isPanelConnector() {
return this != CREATOR && this != UNFINISHED;
}
}

View file

@ -1,32 +1,34 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.controlpanel;
package malte0811.industrialWires.blocks.controlpanel;
import blusunrize.immersiveengineering.api.tool.IConfigurableTool;
import malte0811.industrialwires.blocks.ItemBlockIW;
import malte0811.industrialWires.blocks.ItemBlockIW;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.MathHelper;
import static malte0811.industrialwires.util.NBTKeys.ANGLE;
import static malte0811.industrialwires.util.NBTKeys.HEIGHT;
public class ItemBlockPanel extends ItemBlockIW implements IConfigurableTool {
private static final String HEIGHT = "height";
private static final String ANGLE = "angle";
public ItemBlockPanel(Block b) {
super(b);

View file

@ -1,36 +1,41 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.controlpanel;
package malte0811.industrialWires.blocks.controlpanel;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.IBlockBoundsIW;
import malte0811.industrialwires.controlpanel.*;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialwires.network.MessagePanelInteract;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.TileEntityIWBase;
import malte0811.industrialWires.controlpanel.*;
import malte0811.industrialWires.network.MessagePanelInteract;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable;
@ -38,29 +43,27 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.util.Constants;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static malte0811.industrialwires.util.MiscUtils.apply;
public class TileEntityPanel extends TileEntityGeneralCP implements IDirectionalTile, IBlockBoundsIW, IPlayerInteraction,
ITickable, IEBlockInterfaces.ITileDrop {
protected PropertyComponents.PanelRenderProperties components = new PropertyComponents.PanelRenderProperties();
public class TileEntityPanel extends TileEntityIWBase implements IDirectionalTile, IBlockBoundsIW, IPlayerInteraction, ITickable, IEBlockInterfaces.ITileDrop {
private PropertyComponents.PanelRenderProperties components = new PropertyComponents.PanelRenderProperties();
public boolean firstTick = true;
// non-rendered properties
private Set<TileEntityRSPanelConn> rsPorts = new HashSet<>();
private boolean renderUpdate;
{
int[] colors = {
16383998, 16351261, 13061821, 3847130, 16701501, 8439583, 15961002,
4673362, 10329495, 1481884, 8991416, 3949738, 8606770, 6192150
};
for (int i = 2; i < 14; i++) {
int color = colors[i-2];
IndicatorLight ind = new IndicatorLight(new RSChannel(0, (byte) (i - 2)), color);
LightedButton btn = new LightedButton(color, false, true,
new RSChannel(0, (byte)(i-2)));
int color = EnumDyeColor.byMetadata(i - 2).getMapColor().colorValue;
IndicatorLight ind = new IndicatorLight(0, (byte) (i - 2), color);
LightedButton btn = new LightedButton(color, false, true, 1, i - 2);
Label lbl = new Label("->", color);
ind.setX(0);
ind.setY(i / 16F);
@ -75,25 +78,31 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
components.add(lbl);
components.add(btn);
}
for (PanelComponent pc:components) {
pc.setPanel(this);
}
}
@Override
public void update() {
if (!world.isRemote) {
for (PanelComponent pc : components) {
pc.update();
}
}
}
@Override
public void setNetworkAndInit(ControlPanelNetwork newNet) {
super.setNetworkAndInit(newNet);
for (PanelComponent pc : components) {
pc.setNetwork(newNet);
pc.update(this);
}
if (!world.isRemote) {
if (firstTick) {
List<BlockPos> parts = PanelUtils.discoverPanelParts(world, pos, 100);
for (BlockPos bp : parts) {
TileEntity te = world.getTileEntity(bp);
if (te instanceof TileEntityRSPanelConn && !rsPorts.contains(te)) {
((TileEntityRSPanelConn) te).registerPanel(this);
}
}
firstTick = false;
}
if (renderUpdate) {
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
world.addBlockEvent(pos, state.getBlock(), 255, 0);
markDirty();
renderUpdate = false;
}
}
}
@ -107,13 +116,13 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
readFromItemNBT(in);
components.setFacing(EnumFacing.byHorizontalIndex(in.getInteger("facing")));
components.setTop(EnumFacing.byIndex(in.getInteger("top")));
components.setFacing(EnumFacing.getHorizontal(in.getInteger("facing")));
components.setTop(EnumFacing.getFront(in.getInteger("top")));
}
@Override
@Nonnull
public ItemStack getTileDrop(@Nullable EntityPlayer player, @Nonnull IBlockState state) {
public ItemStack getTileDrop(@Nonnull EntityPlayer player, @Nonnull IBlockState state) {
NBTTagCompound ret = new NBTTagCompound();
writeToItemNBT(ret, true);
ItemStack retStack = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
@ -132,17 +141,7 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
if (nbt != null) {
NBTTagList l = nbt.getTagList("components", 10);
PanelUtils.readListFromNBT(l, components);
panelNetwork.removeIOFor(this);
for (PanelComponent pc : components) {
pc.setPanel(this);
if (world == null || !world.isRemote) {
pc.setNetwork(panelNetwork);
}
}
components.setHeight(nbt.getFloat("height"));
if (nbt.hasKey("texture", Constants.NBT.TAG_COMPOUND)) {
components.setTextureSource(new ItemStack(nbt.getCompoundTag("texture")));
}
components.setAngle(nbt.getFloat("angle"));
}
defAABB = null;
@ -158,7 +157,6 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
nbt.setTag("components", comps);
nbt.setFloat("height", components.getHeight());
nbt.setFloat("angle", components.getAngle());
nbt.setTag("texture", components.getTextureSource().serializeNBT());
}
@Nonnull
@ -212,7 +210,7 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
return false;
}
protected AxisAlignedBB defAABB;
private AxisAlignedBB defAABB;
@Override
public AxisAlignedBB getBoundingBox() {
@ -226,50 +224,46 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
return components;
}
public AxisAlignedBB apply(Matrix4 mat, AxisAlignedBB in) {
Vec3d min = new Vec3d(in.minX, in.minY, in.minZ);
Vec3d max = new Vec3d(in.maxX, in.maxY, in.maxZ);
min = mat.apply(min);
max = mat.apply(max);
return new AxisAlignedBB(min.x, min.y, min.z, max.x, max.y, max.z);
}
@Nullable
public Pair<PanelComponent, RayTraceResult> getSelectedComponent(EntityPlayer player, Vec3d hitVec, boolean hitAbs) {
public Pair<PanelComponent, RayTraceResult> getSelectedComponent(EntityPlayer player, Vec3d hit, boolean hitAbs) {
//TODO prevent clicking through the back of the panel
Matrix4 mat = components.getPanelTopTransformInverse();
PanelComponent retPc = null;
RayTraceResult retRay = null;
Vec3d playerPosRelative = player.getPositionVector().add(-pos.getX(), player.getEyeHeight() - pos.getY(), -pos.getZ());
Vec3d playerPosRelative = player.getPositionVector().addVector(-pos.getX(), player.getEyeHeight() - pos.getY(), -pos.getZ());
Vec3d playerPosTransformed = mat.apply(playerPosRelative);
Vec3d hitRel = hitAbs ? hitVec.add(-pos.getX(), -pos.getY(), -pos.getZ()) : hitVec;
RayTraceResult r = getBoundingBox().calculateIntercept(playerPosRelative, playerPosRelative.add(player.getLookVec().scale(200)));
if (r != null && r.hitVec != null) {
hitRel = r.hitVec;
}
Vec3d ray = hitRel.subtract(playerPosRelative.subtract(hitRel).scale(10));
Vec3d rayTransformed = mat.apply(ray);
{
//Check whether the player is clicking on the back of the panel
Vec3d hitTransformed = mat.apply(new Vec3d(hitRel.x, hitRel.y, hitRel.z));
if (hitTransformed.y < 0) {
return null;
}
}
for (PanelComponent pc : components) {
AxisAlignedBB box = pc.getBlockRelativeAABB();
if (box.maxY > box.minY) {
box = box.grow(.002);
RayTraceResult hit = box.calculateIntercept(playerPosTransformed, rayTransformed);
if (hit != null) {
Vec3d hitVec = hitAbs ? hit.addVector(-pos.getX(), -pos.getY(), -pos.getZ()) : hit;
hitVec = hitVec.subtract(playerPosRelative.subtract(hitVec).scale(10));
RayTraceResult ray = box.calculateIntercept(playerPosTransformed, mat.apply(hitVec));
if (ray != null) {
if (retPc == null) {
ray.hitVec = ray.hitVec.subtract(pc.getX(), 0, pc.getY());
retPc = pc;
retRay = hit;
retRay = ray;
} else {
double oldDist = retRay.hitVec.subtract(playerPosRelative).lengthSquared();
double newDist = hit.hitVec.subtract(playerPosRelative).lengthSquared();
double newDist = ray.hitVec.subtract(playerPosRelative).lengthSquared();
if (newDist < oldDist) {
ray.hitVec = ray.hitVec.subtract(pc.getX(), 0, pc.getY());
retPc = pc;
retRay = hit;
retRay = ray;
}
}
}
}
}
if (retRay != null) {
retRay.hitVec = retRay.hitVec.subtract(retPc.getX(), 0, retPc.getY());
}
return retPc != null ? new ImmutablePair<>(retPc, retRay) : null;
}
@ -286,7 +280,47 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
public void interactServer(Vec3d hitRelative, int pcId, EntityPlayerMP player) {
if (pcId >= 0 && pcId < components.size()) {
components.get(pcId).interactWith(hitRelative, player);
components.get(pcId).interactWith(hitRelative, this, player);
}
}
public void triggerRenderUpdate() {
renderUpdate = true;
}
public void registerRS(TileEntityRSPanelConn te) {
rsPorts.add(te);
}
public void unregisterRS(TileEntityRSPanelConn te) {
if (!tileEntityInvalid) {
rsPorts.remove(te);
}
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
for (PanelComponent pc : components) {
pc.invalidate(this);
}
removeAllRSCons();
}
public void removeAllRSCons() {
for (TileEntityRSPanelConn rs : rsPorts) {
rs.unregisterPanel(this, true, false);
}
rsPorts.clear();
firstTick = true;
}
@Override
public void invalidate() {
super.invalidate();
for (PanelComponent pc : components) {
pc.invalidate(this);
}
removeAllRSCons();
}
}

View file

@ -1,28 +1,32 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.controlpanel;
package malte0811.industrialWires.blocks.controlpanel;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.IBlockBoundsIW;
import malte0811.industrialwires.blocks.INetGUI;
import malte0811.industrialwires.blocks.TileEntityIWBase;
import malte0811.industrialwires.controlpanel.MessageType;
import malte0811.industrialwires.controlpanel.PanelComponent;
import malte0811.industrialwires.controlpanel.PanelUtils;
import malte0811.industrialwires.items.ItemPanelComponent;
import blusunrize.immersiveengineering.common.util.IELogger;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.INetGUI;
import malte0811.industrialWires.blocks.TileEntityIWBase;
import malte0811.industrialWires.controlpanel.MessageType;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -90,7 +94,7 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI,
p.inventory.markDirty();
}
} else {
IndustrialWires.logger.info("(IndustrialWires) Failed to load panel component send by " + p.getDisplayNameString());
IELogger.info("(IndustrialWires) Failed to load panel component send by " + p.getDisplayNameString());
}
break;
case REMOVE:
@ -115,12 +119,7 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements INetGUI,
}
}
if (valid) {
NBTTagCompound panelNBT;
if (inv.hasTagCompound()) {
panelNBT = inv.getTagCompound().copy();
} else {
panelNBT = new NBTTagCompound();
}
NBTTagCompound panelNBT = new NBTTagCompound();
writeToItemNBT(panelNBT, true);
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
panel.setTagCompound(panelNBT);

View file

@ -0,0 +1,392 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.blocks.controlpanel;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import blusunrize.immersiveengineering.api.energy.wires.redstone.IRedstoneConnector;
import blusunrize.immersiveengineering.api.energy.wires.redstone.RedstoneWireNetwork;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.blocks.INetGUI;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.controlpanel.PropertyComponents;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.function.Consumer;
public class TileEntityRSPanelConn extends TileEntityImmersiveConnectable implements IRedstoneConnector, ITickable, INetGUI, IEBlockInterfaces.IDirectionalTile, IBlockBoundsIW {
private byte[] out = new byte[16];
private boolean dirty = true;
private byte[] oldInput = new byte[16];
private Set<Consumer<byte[]>> changeListeners = new HashSet<>();
private Set<TileEntityPanel> connectedPanels = new HashSet<>();
private EnumFacing facing = EnumFacing.NORTH;
@Nonnull
private RedstoneWireNetwork network = new RedstoneWireNetwork().add(this);
private boolean hasConn = false;
private int id;
{
for (int i = 0; i < 16; i++) {
oldInput[i] = -1;
}
}
private boolean loaded = false;
@Override
public void update() {
if (hasWorld() && !world.isRemote) {
if (!loaded) {
loaded = true;
// completely reload the network
network.removeFromNetwork(null);
List<BlockPos> parts = PanelUtils.discoverPanelParts(world, pos, 100);
for (BlockPos bp : parts) {
TileEntity te = world.getTileEntity(bp);
if (te instanceof TileEntityPanel) {
registerPanel(((TileEntityPanel) te));
}
}
}
if (dirty) {
network.updateValues();
dirty = false;
}
}
}
@Override
public void writeCustomNBT(NBTTagCompound out, boolean updatePacket) {
super.writeCustomNBT(out, updatePacket);
out.setByteArray("out", this.out);
out.setBoolean("hasConn", hasConn);
out.setInteger("rsId", id);
out.setInteger("facing", facing.getIndex());
}
@Override
public void readCustomNBT(NBTTagCompound in, boolean updatePacket) {
super.readCustomNBT(in, updatePacket);
out = in.getByteArray("out");
hasConn = in.getBoolean("hasConn");
id = in.getInteger("rsId");
facing = EnumFacing.VALUES[in.getInteger("facing")];
aabb = null;
}
private final Map<PCWrapper, byte[]> outputs = new HashMap<>();
private TriConsumer<Integer, Byte, PanelComponent> rsOut = (channel, value, pc) -> {
PCWrapper wrapper = new PCWrapper(pc);
if (!outputs.containsKey(wrapper)) {
outputs.put(wrapper, new byte[16]);
}
if (outputs.get(wrapper)[channel] != value) {
outputs.get(wrapper)[channel] = value;
byte max = 0;
Iterator<Map.Entry<PCWrapper, byte[]>> it = outputs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<PCWrapper, byte[]> curr = it.next();
if (curr.getKey().pc.get() == null) {
it.remove();
continue;
}
if (curr.getValue()[channel] > max) {
max = curr.getValue()[channel];
}
}
dirty = true;
out[channel] = max;
}
};
private class PCWrapper {
@Nonnull
private final WeakReference<PanelComponent> pc;
public PCWrapper(@Nonnull PanelComponent pc) {
this.pc = new WeakReference<>(pc);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PCWrapper pcWrapper = (PCWrapper) o;
return pcWrapper.pc.get() == pc.get();
}
@Override
public int hashCode() {
return System.identityHashCode(pc.get());
}
}
public void registerPanel(TileEntityPanel panel) {
PropertyComponents.PanelRenderProperties p = panel.getComponents();
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener != null) {
changeListeners.add(listener);
listener.accept(network.channelValues);
}
pc.registerRSOutput(id, rsOut);
}
panel.registerRS(this);
connectedPanels.add(panel);
}
public void unregisterPanel(TileEntityPanel panel, boolean remove, boolean callPanel) {
out = new byte[16];
PropertyComponents.PanelRenderProperties p = panel.getComponents();
for (PanelComponent pc : p) {
Consumer<byte[]> listener = pc.getRSInputHandler(id, panel);
if (listener != null) {
listener.accept(new byte[16]);
changeListeners.remove(listener);
}
pc.unregisterRSOutput(id, rsOut);
outputs.remove(new PCWrapper(pc));
}
if (callPanel) {
panel.unregisterRS(this);
}
if (remove) {
connectedPanels.remove(panel);
}
for (TileEntityPanel te : connectedPanels) {
for (PanelComponent pc : te.getComponents()) {
pc.registerRSOutput(id, rsOut);
}
}
network.updateValues();
}
@Override
public void setNetwork(@Nonnull RedstoneWireNetwork net) {
network = net;
}
@Nonnull
@Override
public RedstoneWireNetwork getNetwork() {
return network;
}
@Override
public void onChange() {
if (!Arrays.equals(oldInput, network.channelValues)) {
oldInput = Arrays.copyOf(network.channelValues, 16);
for (Consumer<byte[]> c : changeListeners) {
c.accept(oldInput);
}
}
}
@Override
public void updateInput(byte[] currIn) {
for (int i = 0; i < 16; i++) {
currIn[i] = (byte) Math.max(currIn[i], out[i]);
}
}
@Override
public BlockPos getConnectionMaster(@Nullable WireType wire, TargetingInfo target) {
return pos;
}
@Override
public boolean canConnectCable(WireType wire, TargetingInfo targetingInfo) {
return wire == WireType.REDSTONE && !hasConn;
}
@Override
public void connectCable(WireType wireType, TargetingInfo targetingInfo, IImmersiveConnectable other) {
hasConn = true;
if (other instanceof IRedstoneConnector && ((IRedstoneConnector) other).getNetwork() != network) {
network.mergeNetwork(((IRedstoneConnector) other).getNetwork());
}
}
@Override
public WireType getCableLimiter(TargetingInfo targetingInfo) {
return WireType.REDSTONE;
}
@Override
public boolean allowEnergyToPass(ImmersiveNetHandler.Connection connection) {
return false;
}
@Override
public void removeCable(ImmersiveNetHandler.Connection connection) {
hasConn = false;
network.removeFromNetwork(this);
this.markDirty();
if (world != null) {
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
}
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable other) {
EnumFacing side = facing.getOpposite();
return new Vec3d(.5 + side.getFrontOffsetX() * .0625, .5 + side.getFrontOffsetY() * .0625, .5 + side.getFrontOffsetZ() * .0625);
}
@Override
public Vec3d getConnectionOffset(ImmersiveNetHandler.Connection connection) {
EnumFacing side = facing.getOpposite();
double conRadius = connection.cableType.getRenderDiameter() / 2;
return new Vec3d(.5 - conRadius * side.getFrontOffsetX(), .5 - conRadius * side.getFrontOffsetY(), .5 - conRadius * side.getFrontOffsetZ());
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
for (TileEntityPanel panel : connectedPanels) {
unregisterPanel(panel, false, true);
}
}
@Override
public void invalidate() {
super.invalidate();
for (TileEntityPanel panel : connectedPanels) {
unregisterPanel(panel, false, true);
}
}
@Override
public void onChange(NBTTagCompound nbt, EntityPlayer p) {
if (nbt.hasKey("rsId")) {
List<BlockPos> parts = PanelUtils.discoverPanelParts(world, pos, 100);
List<TileEntityPanel> tes = new ArrayList<>(parts.size());
for (BlockPos bp : parts) {
TileEntity te = world.getTileEntity(bp);
if (te instanceof TileEntityPanel) {
tes.add((TileEntityPanel) te);
unregisterPanel((TileEntityPanel) te, true, true);
}
}
id = nbt.getInteger("rsId");
out = new byte[16];
for (TileEntityPanel panel : tes) {
registerPanel(panel);
}
network.updateValues();
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
world.addBlockEvent(pos, state.getBlock(), 255, 0);
}
}
@Override
public World getConnectorWorld() {
return world;
}
public int getRsId() {
return id;
}
@Nonnull
@Override
public EnumFacing getFacing() {
return facing;
}
@Override
public void setFacing(@Nonnull EnumFacing facing) {
this.facing = facing;
}
@Override
public int getFacingLimitation() {
return 0;
}
@Override
public boolean mirrorFacingOnPlacement(@Nonnull EntityLivingBase placer) {
return true;
}
@Override
public boolean canHammerRotate(@Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EntityLivingBase entity) {
return false;
}
@Override
public boolean canRotate(@Nonnull EnumFacing axis) {
return false;
}
private AxisAlignedBB aabb;
@Override
public AxisAlignedBB getBoundingBox() {
if (aabb == null) {
double h = 9 / 16D;
switch (facing) {
case DOWN:
aabb = new AxisAlignedBB(0, 0, 0, 1, h, 1);
break;
case UP:
aabb = new AxisAlignedBB(0, 1 - h, 0, 1, 1, 1);
break;
case NORTH:
aabb = new AxisAlignedBB(0, 0, 0, 1, 1, h);
break;
case SOUTH:
aabb = new AxisAlignedBB(0, 0, 1 - h, 1, 1, 1);
break;
case WEST:
aabb = new AxisAlignedBB(0, 0, 0, h, 1, 1);
break;
case EAST:
aabb = new AxisAlignedBB(1 - h, 0, 0, 1, 1, 1);
break;
}
}
return aabb;
}
}

View file

@ -1,19 +1,22 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.controlpanel;
package malte0811.industrialWires.blocks.controlpanel;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;

View file

@ -1,22 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.converter;
package malte0811.industrialWires.blocks.converter;
import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialwires.blocks.BlockIWBase;
import malte0811.industrialwires.blocks.IMetaEnum;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@ -24,6 +27,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
@ -36,17 +40,16 @@ import net.minecraft.world.World;
import javax.annotation.Nonnull;
public class BlockMechanicalConverter extends BlockIWBase implements IMetaEnum {
public static final String NAME = "mechanical_converter";
private static PropertyEnum<MechanicalBlockType> type = PropertyEnum.create("type", MechanicalBlockType.class);
public BlockMechanicalConverter() {
super(Material.IRON, NAME);
super(Material.IRON, "mechanical_converter");
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
for (int i = 0; i < 3; i++) {
list.add(new ItemStack(this, 1, i));
list.add(new ItemStack(itemIn, 1, i));
}
}

View file

@ -1,18 +1,21 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.converter;
package malte0811.industrialWires.blocks.converter;
import net.minecraft.util.IStringSerializable;

View file

@ -1,27 +1,30 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.converter;
package malte0811.industrialWires.blocks.converter;
import blusunrize.immersiveengineering.api.energy.IRotationAcceptor;
import blusunrize.immersiveengineering.api.energy.immersiveflux.FluxStorage;
import blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import malte0811.industrialwires.IWConfig.MechConversion;
import malte0811.industrialwires.blocks.EnergyAdapter;
import malte0811.industrialwires.blocks.TileEntityIWBase;
import malte0811.industrialwires.util.ConversionUtil;
import malte0811.industrialWires.IWConfig.MechConversion;
import malte0811.industrialWires.blocks.EnergyAdapter;
import malte0811.industrialWires.blocks.TileEntityIWBase;
import malte0811.industrialWires.util.ConversionUtil;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -30,15 +33,12 @@ import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;
import static malte0811.industrialwires.util.NBTKeys.*;
public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IFluxReceiver, IDirectionalTile {
public final double bufferMax = 2 * MechConversion.maxIfToMech * ConversionUtil.rotPerIf();
private double rotBuffer = 0;
private FluxStorage energy = new FluxStorage(20 * MechConversion.maxIfToMech, 2 * MechConversion.maxIfToMech);
private EnumFacing dir = EnumFacing.DOWN;
@ -52,8 +52,7 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
}
int max = MechConversion.maxIfToMech;
boolean dirty = false;
if (rotBuffer < 2 * MechConversion.maxIfToMech * ConversionUtil.rotPerIf()
&& energy.extractEnergy(max, true) > 0) {
if (rotBuffer < bufferMax && energy.extractEnergy(max, true) > 0) {
int extracted = energy.extractEnergy(max, false);
rotBuffer += extracted * ConversionUtil.rotPerIf() * MechConversion.ifMotorEfficiency;
dirty = true;
@ -72,19 +71,19 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
dir = EnumFacing.VALUES[in.getByte(DIRECTION)];
energy.readFromNBT(in.getCompoundTag(ENERGY));
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
energy.readFromNBT(in.getCompoundTag(ENERGY_TAG));
receiver = null;
rotBuffer = in.getDouble(BUFFER);
rotBuffer = in.getDouble(BUFFER_TAG);
}
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
out.setByte(DIRECTION, (byte) dir.getIndex());
out.setByte(DIR_TAG, (byte) dir.getIndex());
NBTTagCompound nbt = new NBTTagCompound();
energy.writeToNBT(nbt);
out.setTag(ENERGY, nbt);
out.setDouble(BUFFER, rotBuffer);
out.setTag(ENERGY_TAG, nbt);
out.setDouble(BUFFER_TAG, rotBuffer);
}
// Flux energy
@ -151,14 +150,11 @@ public class TileEntityIEMotor extends TileEntityIWBase implements ITickable, IF
return super.hasCapability(capability, facing);
}
private Map<EnumFacing, IEnergyStorage> energies = new HashMap<>();
@Override
@SuppressWarnings("unchecked")
public <T> T getCapability(@Nonnull Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityEnergy.ENERGY && canConnectEnergy(facing)) {
if (!energies.containsKey(facing))
energies.put(facing, new EnergyAdapter(this, facing));
return CapabilityEnergy.ENERGY.cast(energies.get(facing));
return (T) new EnergyAdapter(this, facing);
}
return super.getCapability(capability, facing);
}

View file

@ -1,25 +1,28 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.converter;
package malte0811.industrialWires.blocks.converter;
import blusunrize.immersiveengineering.api.energy.IRotationAcceptor;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import ic2.api.energy.tile.IKineticSource;
import malte0811.industrialwires.IWConfig.MechConversion;
import malte0811.industrialwires.blocks.TileEntityIWBase;
import malte0811.industrialwires.util.ConversionUtil;
import malte0811.industrialWires.IWConfig.MechConversion;
import malte0811.industrialWires.blocks.TileEntityIWBase;
import malte0811.industrialWires.util.ConversionUtil;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -29,14 +32,13 @@ import net.minecraft.util.math.BlockPos;
import javax.annotation.Nonnull;
import static malte0811.industrialwires.util.NBTKeys.BUFFER;
import static malte0811.industrialwires.util.NBTKeys.DIRECTION;
public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirectionalTile, ITickable {
private EnumFacing dir = EnumFacing.DOWN;
private int kinBuffer = 0;
private BlockPos to;
private BlockPos from;
EnumFacing dir = EnumFacing.DOWN;
int kinBuffer = 0;
private final int kinBufMax = 2 * MechConversion.maxKinToRot;
private final double maxInsert = ConversionUtil.rotPerKin() * MechConversion.maxKinToRot;
BlockPos to;
BlockPos from;
@Override
public void update() {
@ -50,15 +52,14 @@ public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirection
TileEntity teFrom = world.getTileEntity(from);
if (teFrom instanceof IKineticSource) {
int sourceMax = ((IKineticSource) teFrom).maxrequestkineticenergyTick(dir);
int draw = Math.min(2 * MechConversion.maxKinToRot - kinBuffer, sourceMax);
int draw = Math.min(kinBufMax - kinBuffer, sourceMax);
if (draw > 0) {
kinBuffer += ((IKineticSource) teFrom).requestkineticenergy(dir, draw) * MechConversion.kinToRotEfficiency;
}
}
TileEntity teTo = world.getTileEntity(to);
if (kinBuffer > 0 && teTo instanceof IRotationAcceptor) {
double out = Math.min(ConversionUtil.rotPerKin() * MechConversion.maxKinToRot,
ConversionUtil.rotPerKin() * kinBuffer);
double out = Math.min(maxInsert, ConversionUtil.rotPerKin() * kinBuffer);
((IRotationAcceptor) teTo).inputRotation(out, dir);
kinBuffer -= out * ConversionUtil.kinPerRot();
}
@ -67,14 +68,14 @@ public class TileEntityMechICtoIE extends TileEntityIWBase implements IDirection
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
out.setByte(DIRECTION, (byte) dir.getIndex());
out.setInteger(BUFFER, kinBuffer);
out.setByte(DIR_TAG, (byte) dir.getIndex());
out.setInteger(BUFFER_TAG, kinBuffer);
}
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
dir = EnumFacing.VALUES[in.getByte(DIRECTION)];
kinBuffer = in.getInteger(BUFFER);
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
kinBuffer = in.getInteger(BUFFER_TAG);
to = null;
from = null;
}

View file

@ -1,49 +1,50 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.converter;
package malte0811.industrialWires.blocks.converter;
import blusunrize.immersiveengineering.api.energy.IRotationAcceptor;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import ic2.api.energy.tile.IKineticSource;
import malte0811.industrialwires.IWConfig.MechConversion;
import malte0811.industrialwires.blocks.TileEntityIWBase;
import malte0811.industrialwires.util.ConversionUtil;
import malte0811.industrialWires.IWConfig.MechConversion;
import malte0811.industrialWires.blocks.TileEntityIWBase;
import malte0811.industrialWires.util.ConversionUtil;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import javax.annotation.Nonnull;
import static malte0811.industrialwires.IWConfig.MechConversion.maxRotToKin;
import static malte0811.industrialwires.util.NBTKeys.BUFFER;
import static malte0811.industrialwires.util.NBTKeys.DIRECTION;
public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirectionalTile, IRotationAcceptor, IKineticSource {
private EnumFacing dir = EnumFacing.DOWN;
private double rotBuffer = 0;
EnumFacing dir = EnumFacing.DOWN;
double rotBuffer = 0;
private final double rotBufMax = 2 * MechConversion.maxRotToKin;
private final int maxOutput = (int) (ConversionUtil.kinPerRot() * MechConversion.maxRotToKin);
@Override
public void writeNBT(NBTTagCompound out, boolean updatePacket) {
out.setByte(DIRECTION, (byte) dir.getIndex());
out.setDouble(BUFFER, rotBuffer);
out.setByte(DIR_TAG, (byte) dir.getIndex());
out.setDouble(BUFFER_TAG, rotBuffer);
}
@Override
public void readNBT(NBTTagCompound in, boolean updatePacket) {
dir = EnumFacing.VALUES[in.getByte(DIRECTION)];
rotBuffer = in.getDouble(BUFFER);
dir = EnumFacing.VALUES[in.getByte(DIR_TAG)];
rotBuffer = in.getDouble(BUFFER_TAG);
}
// Directional
@ -74,36 +75,23 @@ public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirection
return true;
}
@Override
@Deprecated
public int maxrequestkineticenergyTick(EnumFacing enumFacing) {
return 0;
}
//IC2 kinetic
@Override
public int getConnectionBandwidth(EnumFacing f) {
public int maxrequestkineticenergyTick(EnumFacing f) {
if (f == dir) {
return (int) (ConversionUtil.kinPerRot() * rotBuffer);
return maxOutput;
} else {
return 0;
}
}
@Override
@Deprecated
public int requestkineticenergy(EnumFacing enumFacing, int i) {
return 0;
}
@Override
public int drawKineticEnergy(EnumFacing f, int requested, boolean simulate) {
public int requestkineticenergy(EnumFacing f, int requested) {
if (f == dir) {
int stored = (int) (ConversionUtil.kinPerRot() * rotBuffer);
int out = Math.min(requested, stored);
if (!simulate) {
rotBuffer -= out * ConversionUtil.rotPerKin();
}
int out = Math.min(maxOutput, stored);
out = Math.min(requested, out);
rotBuffer -= out * ConversionUtil.rotPerKin();
return (int) (out * MechConversion.rotToKinEfficiency);
} else {
return 0;
@ -114,7 +102,7 @@ public class TileEntityMechIEtoIC extends TileEntityIWBase implements IDirection
@Override
public void inputRotation(double rotation, @Nonnull EnumFacing side) {
if (side == dir) {
rotBuffer = Math.min(Math.max(rotBuffer, rotation), maxRotToKin);
rotBuffer = Math.min(rotBufMax, rotBuffer + rotation);
}
}

View file

@ -1,35 +1,36 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.wire;
package malte0811.industrialWires.blocks.wire;
import blusunrize.immersiveengineering.api.IEProperties;
import malte0811.industrialwires.IWConfig;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.BlockIWBase;
import malte0811.industrialwires.blocks.IMetaEnum;
import malte0811.industrialwires.util.ConversionUtil;
import malte0811.industrialwires.wires.MixedWireType;
import net.minecraft.block.Block;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.BlockIWBase;
import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
@ -40,31 +41,28 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
public static final PropertyEnum<BlockTypes_IC2_Connector> TYPE = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
public static final String NAME = "ic2_connector";
private static PropertyEnum<BlockTypes_IC2_Connector> type = PropertyEnum.create("type", BlockTypes_IC2_Connector.class);
public BlockIC2Connector() {
super(Material.IRON, NAME);
super(Material.IRON, "ic2_connector");
setHardness(3.0F);
setResistance(15.0F);
lightOpacity = 0;
this.setCreativeTab(IndustrialWires.creativeTab);
}
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos posNeighbor) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileEntityIC2ConnectorTin) {
TileEntityIC2ConnectorTin connector = (TileEntityIC2ConnectorTin) te;
if (world.isAirBlock(pos.offset(connector.getFacing()))) {
if (world.isAirBlock(pos.offset(connector.f))) {
this.dropBlockAsItem(connector.getWorld(), pos, world.getBlockState(pos), 0);
connector.getWorld().setBlockToAir(pos);
}
@ -72,9 +70,9 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
}
@Override
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list) {
for (int i = 0; i < TYPE.getAllowedValues().size(); i++) {
list.add(new ItemStack(this, 1, i));
public void getSubBlocks(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
for (int i = 0; i < type.getAllowedValues().size(); i++) {
list.add(new ItemStack(itemIn, 1, i));
}
}
@ -90,7 +88,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
@Override
protected IProperty<?>[] getProperties() {
return new IProperty[]{TYPE, IEProperties.FACING_ALL};
return new IProperty[]{type, IEProperties.FACING_ALL};
}
@Nonnull
@ -107,7 +105,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
return super.getStateFromMeta(meta).withProperty(TYPE, BlockTypes_IC2_Connector.values()[meta]);
return super.getStateFromMeta(meta).withProperty(type, BlockTypes_IC2_Connector.values()[meta]);
}
@Override
@ -122,15 +120,7 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
@Override
public TileEntity createTileEntity(@Nonnull World world, @Nonnull IBlockState state) {
TileEntityIC2ConnectorTin base = getBaseTE(state.getValue(TYPE));
if (base!=null) {
base.setFacing(state.getValue(IEProperties.FACING_ALL));
}
return base;
}
private TileEntityIC2ConnectorTin getBaseTE(BlockTypes_IC2_Connector type) {
switch (type) {
switch (state.getValue(type)) {
case TIN_CONN:
return new TileEntityIC2ConnectorTin(false);
case TIN_RELAY:
@ -156,16 +146,12 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag advanced) {
super.addInformation(stack, world, tooltip, advanced);
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (!stack.isEmpty() && stack.getMetadata() % 2 == 0) {
int type = stack.getMetadata() / 2;
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", (type%5) + 1));
MixedWireType wire = MixedWireType.ALL[type];
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.energy_per_tick",
wire.getIORate()*ConversionUtil.euPerJoule(),
wire.getIORate()*ConversionUtil.ifPerJoule()*IWConfig.wireRatio));
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.power_tier", type + 1));
tooltip.add(I18n.format(IndustrialWires.MODID + ".tooltip.eu_per_tick", IC2Wiretype.IC2_TYPES[type].getTransferRate() / 8));
}
}
@ -205,6 +191,6 @@ public class BlockIC2Connector extends BlockIWBase implements IMetaEnum {
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(TYPE).ordinal();
return state.getValue(type).ordinal();
}
}

View file

@ -1,18 +1,21 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.wire;
package malte0811.industrialWires.blocks.wire;
import blusunrize.immersiveengineering.common.blocks.BlockIEBase.IBlockEnum;

View file

@ -1,28 +1,42 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.wire;
package malte0811.industrialWires.blocks.wire;
import static malte0811.industrialwires.wires.MixedWireType.COPPER_IC2;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import malte0811.industrialWires.wires.IC2Wiretype;
public class TileEntityIC2ConnectorCopper extends TileEntityIC2ConnectorTin {
public TileEntityIC2ConnectorCopper(boolean rel) {
super(rel, COPPER_IC2, 2, .5, .5);
super(rel);
}
public TileEntityIC2ConnectorCopper() {
this(false);
}
{
tier = 2;
maxStored = IC2Wiretype.IC2_TYPES[1].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[1];
}
}

View file

@ -1,27 +1,40 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.wire;
package malte0811.industrialWires.blocks.wire;
import static malte0811.industrialwires.wires.MixedWireType.GLASS;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import malte0811.industrialWires.wires.IC2Wiretype;
public class TileEntityIC2ConnectorGlass extends TileEntityIC2ConnectorTin {
public class TileEntityIC2ConnectorGlass extends TileEntityIC2ConnectorHV {
public TileEntityIC2ConnectorGlass(boolean rel) {
super(rel, GLASS, 5, .875, .75);
super(rel);
}
public TileEntityIC2ConnectorGlass() {
this(false);
}
{
tier = 5;
maxStored = IC2Wiretype.IC2_TYPES[4].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[4];
}
}

View file

@ -0,0 +1,58 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.blocks.wire;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3d;
public class TileEntityIC2ConnectorGold extends TileEntityIC2ConnectorTin {
public TileEntityIC2ConnectorGold(boolean rel) {
super(rel);
}
public TileEntityIC2ConnectorGold() {
}
{
tier = 3;
maxStored = IC2Wiretype.IC2_TYPES[2].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[2];
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
return new Vec3d(.5 + side.getFrontOffsetX() * .125, .5 + side.getFrontOffsetY() * .125, .5 + side.getFrontOffsetZ() * .125);
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();
double conRadius = con.cableType.getRenderDiameter() / 2;
return new Vec3d(.5 + side.getFrontOffsetX() * (.0625 - conRadius), .5 + side.getFrontOffsetY() * (.0625 - conRadius), .5 + side.getFrontOffsetZ() * (.0625 - conRadius));
}
}

View file

@ -0,0 +1,66 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.blocks.wire;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3d;
public class TileEntityIC2ConnectorHV extends TileEntityIC2ConnectorTin {
public TileEntityIC2ConnectorHV(boolean rel) {
super(rel);
}
public TileEntityIC2ConnectorHV() {
}
{
tier = 4;
maxStored = IC2Wiretype.IC2_TYPES[3].getTransferRate() / 8;
}
@Override
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[3];
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
if (relay) {
return new Vec3d(.5 + side.getFrontOffsetX() * .4375, .5 + side.getFrontOffsetY() * .4375, .5 + side.getFrontOffsetZ() * .4375);
} else {
return new Vec3d(.5 + side.getFrontOffsetX() * .3125, .5 + side.getFrontOffsetY() * .3125, .5 + side.getFrontOffsetZ() * .3125);
}
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();
double conRadius = con.cableType.getRenderDiameter() / 2;
if (relay) {
return new Vec3d(.5 + side.getFrontOffsetX() * (.375 - conRadius), .5 + side.getFrontOffsetY() * (.375 - conRadius), .5 + side.getFrontOffsetZ() * (.375 - conRadius));
} else {
return new Vec3d(.5 + side.getFrontOffsetX() * (.25 - conRadius), .5 + side.getFrontOffsetY() * (.25 - conRadius), .5 + side.getFrontOffsetZ() * (.25 - conRadius));
}
}
}

View file

@ -0,0 +1,378 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.blocks.wire;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.energy.wires.TileEntityImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergySource;
import malte0811.industrialWires.IIC2Connector;
import malte0811.industrialWires.blocks.IBlockBoundsIW;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.common.MinecraftForge;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class TileEntityIC2ConnectorTin extends TileEntityImmersiveConnectable implements IEnergySource, IEnergySink, IDirectionalTile, ITickable, IIC2Connector, IBlockBoundsIW {
EnumFacing f = EnumFacing.NORTH;
boolean relay;
private boolean first = true;
//IC2 net to IE net buffer
private double inBuffer = 0;
private double maxToNet = 0;
//IE net to IC2 net buffer
private double outBuffer = 0;
private double maxToMachine = 0;
protected double maxStored = IC2Wiretype.IC2_TYPES[0].getTransferRate() / 8;
int tier = 1;
public TileEntityIC2ConnectorTin(boolean rel) {
relay = rel;
}
public TileEntityIC2ConnectorTin() {
}
@Override
public void update() {
if (first) {
if (!world.isRemote)
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
first = false;
}
if (!world.isRemote && inBuffer > .1)
transferPower();
}
public void transferPower() {
Set<AbstractConnection> conns = new HashSet<>(ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(pos, world));
Map<AbstractConnection, Pair<IIC2Connector, Double>> maxOutputs = new HashMap<>();
double outputMax = Math.min(inBuffer, maxToNet);
double sum = 0;
for (AbstractConnection c : conns) {
IImmersiveConnectable iic = ApiUtils.toIIC(c.end, world);
if (iic instanceof IIC2Connector) {
double tmp = outputMax - ((IIC2Connector) iic).insertEnergy(outputMax, true);
if (tmp > .00000001) {
maxOutputs.put(c, new ImmutablePair<>((IIC2Connector) iic, tmp));
sum += tmp;
}
}
}
if (sum < .0001) {
return;
}
final double oldInBuf = outputMax;
HashMap<Connection, Integer> transferedPerConn = ImmersiveNetHandler.INSTANCE.getTransferedRates(world.provider.getDimension());
for (AbstractConnection c : maxOutputs.keySet()) {
Pair<IIC2Connector, Double> p = maxOutputs.get(c);
double out = oldInBuf * p.getRight() / sum;
double loss = getAverageLossRate(c);
double inserted = out - p.getLeft().insertEnergy(out - loss, false);
inBuffer -= inserted;
float intermediaryLoss = 0;
HashSet<IImmersiveConnectable> passedConnectors = new HashSet<>();
double energyAtConn = inserted + loss;
for (Connection sub : c.subConnections) {
int transferredPerCon = transferedPerConn.getOrDefault(sub, 0);
energyAtConn -= sub.cableType.getLossRatio() * sub.length;
ImmersiveNetHandler.INSTANCE.getTransferedRates(world.provider.getDimension()).put(sub, (int) (transferredPerCon + energyAtConn));
IImmersiveConnectable subStart = ApiUtils.toIIC(sub.start, world);
IImmersiveConnectable subEnd = ApiUtils.toIIC(sub.end, world);
if (subStart != null && passedConnectors.add(subStart))
subStart.onEnergyPassthrough((int) (inserted - inserted * intermediaryLoss));
if (subEnd != null && passedConnectors.add(subEnd))
subEnd.onEnergyPassthrough((int) (inserted - inserted * intermediaryLoss));
}
}
}
public double getAverageLossRate(AbstractConnection conn) {
double f = 0;
for (Connection c : conn.subConnections) {
f += c.length * c.cableType.getLossRatio();
}
return f;
}
//Input through the net
@Override
public double insertEnergy(double eu, boolean simulate) {
final double insert = Math.min(maxStored - outBuffer, eu);
if (insert > 0) {
if (outBuffer < maxToMachine) {
maxToMachine = outBuffer;
}
if (eu > maxToMachine) {
maxToMachine = eu;
}
}
if (!simulate) {
outBuffer += insert;
}
return eu - insert;
}
@Override
public void invalidate() {
if (!world.isRemote && !first)
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
first = true;
super.invalidate();
}
@Override
public void onChunkUnload() {
super.onChunkUnload();
if (!world.isRemote && !first)
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
first = true;
}
@Override
public Vec3d getRaytraceOffset(IImmersiveConnectable link) {
EnumFacing side = f.getOpposite();
return new Vec3d(.5 + side.getFrontOffsetX() * .0625, .5 + side.getFrontOffsetY() * .0625, .5 + side.getFrontOffsetZ() * .0625);
}
@Override
public Vec3d getConnectionOffset(Connection con) {
EnumFacing side = f.getOpposite();
double conRadius = con.cableType.getRenderDiameter() / 2;
return new Vec3d(.5 - conRadius * side.getFrontOffsetX(), .5 - conRadius * side.getFrontOffsetY(), .5 - conRadius * side.getFrontOffsetZ());
}
@Override
public boolean canConnect() {
return true;
}
@Override
public boolean isEnergyOutput() {
return !relay;
}
@Override
public boolean canConnectCable(WireType cableType, TargetingInfo target) {
return (limitType == null || (this.isRelay() && limitType == cableType)) && canConnect(cableType);
}
public boolean canConnect(WireType t) {
return t == IC2Wiretype.IC2_TYPES[0];
}
@Override
protected boolean isRelay() {
return relay;
}
@Override
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing side) {
return !relay && side == f;
}
@Override
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing side) {
return !relay && side == f;
}
@Override
public double getDemandedEnergy() {
double ret = maxStored + .5 - inBuffer;
if (ret < .1)
ret = 0;
return ret;
}
@Override
public int getSinkTier() {
return tier;
}
@Override
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
if (inBuffer < maxStored) {
if (inBuffer < maxToNet) {
maxToNet = inBuffer;
}
inBuffer += amount;
if (amount > maxToNet) {
maxToNet = amount;
}
markDirty();
return 0;
}
return amount;
}
@Override
public double getOfferedEnergy() {
return Math.min(maxToMachine, outBuffer);
}
@Override
public void drawEnergy(double amount) {
outBuffer -= amount;
markDirty();
}
@Override
public int getSourceTier() {
return tier;
}
@Override
public void readCustomNBT(NBTTagCompound nbt, boolean descPacket) {
super.readCustomNBT(nbt, descPacket);
f = EnumFacing.getFront(nbt.getInteger("facing"));
relay = nbt.getBoolean("relay");
inBuffer = nbt.getDouble("inBuffer");
outBuffer = nbt.getDouble("outBuffer");
if (nbt.hasKey("maxToNet")) {
maxToNet = nbt.getDouble("maxToNet");
} else {
maxToNet = inBuffer;
}
if (nbt.hasKey("maxToMachine")) {
maxToMachine = nbt.getDouble("maxToMachine");
} else {
maxToMachine = outBuffer;
}
}
@Override
public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket) {
super.writeCustomNBT(nbt, descPacket);
nbt.setInteger("facing", f.getIndex());
nbt.setBoolean("relay", relay);
nbt.setDouble("inBuffer", inBuffer);
nbt.setDouble("outBuffer", outBuffer);
nbt.setDouble("maxToNet", maxToNet);
nbt.setDouble("maxToMachine", maxToMachine);
}
@Nonnull
@Override
public EnumFacing getFacing() {
return f;
}
@Override
public void setFacing(@Nonnull EnumFacing facing) {
f = facing;
}
@Override
public int getFacingLimitation() {
return 0;
}
@Override
public boolean mirrorFacingOnPlacement(@Nonnull EntityLivingBase placer) {
return true;
}
@Override
public boolean canHammerRotate(@Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EntityLivingBase entity) {
return false;
}
@Override
public AxisAlignedBB getBoundingBox() {
float length = this instanceof TileEntityIC2ConnectorHV ? (relay ? .875f : .75f) : this instanceof TileEntityIC2ConnectorGold ? .5625f : .5f;
float wMin = .3125f;
float wMax = .6875f;
switch (f.getOpposite()) {
case UP:
return new AxisAlignedBB(wMin, 0, wMin, wMax, length, wMax);
case DOWN:
return new AxisAlignedBB(wMin, 1 - length, wMin, wMax, 1, wMax);
case SOUTH:
return new AxisAlignedBB(wMin, wMin, 0, wMax, wMax, length);
case NORTH:
return new AxisAlignedBB(wMin, wMin, 1 - length, wMax, wMax, 1);
case EAST:
return new AxisAlignedBB(0, wMin, wMin, length, wMax, wMax);
case WEST:
return new AxisAlignedBB(1 - length, wMin, wMin, 1, wMax, wMax);
}
return new AxisAlignedBB(0, 0, 0, 1, 1, 1);
}
/*
* regarding equals+hashCode
* TE's are considered equal if they have the same pos+dimension id
* This is necessary to work around a weird bug causing a lot of log spam (100GB and above are well possible).
* For further information see #1 (https://github.com/malte0811/IndustrialWires/issues/1)
*/
@Override
public int hashCode() {
int ret = world.provider.getDimension();
ret = 31 * ret + pos.hashCode();
return ret;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof TileEntityIC2ConnectorTin)) {
return false;
}
if (obj.getClass() != getClass()) {
return false;
}
TileEntityIC2ConnectorTin te = (TileEntityIC2ConnectorTin) obj;
if (!te.pos.equals(pos)) {
return false;
}
if (te.world.provider.getDimension() != world.provider.getDimension()) {
return false;
}
return true;
}
@Override
public boolean canRotate(@Nonnull EnumFacing axis) {
return false;
}
}

View file

@ -0,0 +1,103 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.client;
import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.client.ClientUtils;
import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.panelmodel.PanelModel;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.client.GuiIngameForge;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.tuple.Pair;
public class ClientEventHandler {
@SubscribeEvent
public void renderOverlayPost(RenderGameOverlayEvent.Post e) {
if (ClientUtils.mc().player != null && e.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
EntityPlayer player = ClientUtils.mc().player;
for (EnumHand hand : EnumHand.values()) {
if (!player.getHeldItem(hand).isEmpty()) {
ItemStack equipped = player.getHeldItem(hand);
if (OreDictionary.itemMatches(new ItemStack(IndustrialWires.coil, 1, OreDictionary.WILDCARD_VALUE), equipped, false)) {
IC2Wiretype type = IC2Wiretype.IC2_TYPES[equipped.getItemDamage()];
int color = type.getColour(null);
String s = I18n.format(IndustrialWires.MODID + ".desc.wireLength", ItemIC2Coil.getLength(equipped));
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, e.getResolution().getScaledHeight() - GuiIngameForge.left_height - 40, color, true);
if (ItemNBTHelper.hasKey(equipped, "linkingPos")) {
int[] link = ItemNBTHelper.getIntArray(equipped, "linkingPos");
if (link != null && link.length > 3) {
s = I18n.format(Lib.DESC_INFO + "attachedTo", link[1], link[2], link[3]);
RayTraceResult focussedBlock = ClientUtils.mc().objectMouseOver;
double distSquared;
if (focussedBlock != null && focussedBlock.typeOfHit == RayTraceResult.Type.BLOCK) {
distSquared = focussedBlock.getBlockPos().distanceSq(link[1], link[2], link[3]);
} else {
distSquared = player.getDistanceSq(link[1], link[2], link[3]);
}
int length = Math.min(ItemIC2Coil.getLength(equipped), type.getMaxLength());
if (length * length < distSquared) {
color = 0xdd3333;
}
ClientUtils.font().drawString(s, e.getResolution().getScaledWidth() / 2 - ClientUtils.font().getStringWidth(s) / 2, e.getResolution().getScaledHeight() - GuiIngameForge.left_height - 20, color, true);
}
}
}
}
}
}
}
@SubscribeEvent
public void renderBoundingBoxes(DrawBlockHighlightEvent event) {
if (!event.isCanceled() && event.getSubID() == 0 && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) {
TileEntity tile = event.getPlayer().world.getTileEntity(event.getTarget().getBlockPos());
if (tile instanceof TileEntityPanel) {
TileEntityPanel panel = (TileEntityPanel) tile;
Pair<PanelComponent, RayTraceResult> pc = panel.getSelectedComponent(Minecraft.getMinecraft().player, event.getTarget().hitVec, true);
if (pc != null) {
pc.getLeft().renderBox(panel);
event.setCanceled(true);
}
}
}
}
@SubscribeEvent
public void bakeModel(ModelBakeEvent event) {
event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID + ":control_panel", "inventory,type=top"), new PanelModel());
event.getModelRegistry().putObject(new ModelResourceLocation(IndustrialWires.MODID + ":control_panel", "inventory,type=unfinished"), new PanelModel());
}
}

View file

@ -0,0 +1,312 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.client;
import blusunrize.immersiveengineering.api.ManualHelper;
import blusunrize.immersiveengineering.client.ClientUtils;
import blusunrize.immersiveengineering.client.models.smart.ConnLoader;
import blusunrize.immersiveengineering.common.Config;
import blusunrize.lib.manual.ManualInstance;
import blusunrize.lib.manual.ManualPages;
import blusunrize.lib.manual.ManualPages.PositionedItemStack;
import com.google.common.collect.ImmutableMap;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.CommonProxy;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.IMetaEnum;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.client.gui.GuiPanelComponent;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.client.gui.GuiRSPanelConn;
import malte0811.industrialWires.client.gui.GuiRenameKey;
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
import malte0811.industrialWires.client.render.TileRenderJacobsLadder;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ISound;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import java.util.Locale;
import java.util.Random;
import java.util.WeakHashMap;
public class ClientProxy extends CommonProxy {
@Override
public void preInit() {
super.preInit();
ConnLoader.baseModels.put("ic2_conn_tin", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
ConnLoader.textureReplacements.put("ic2_conn_tin", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
IndustrialWires.MODID + ":blocks/ic2_conn_tin"));
ConnLoader.baseModels.put("ic2_relay_tin", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
ConnLoader.textureReplacements.put("ic2_relay_tin", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
IndustrialWires.MODID + ":blocks/ic2_relay_tin"));
ConnLoader.baseModels.put("ic2_conn_copper", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
ConnLoader.textureReplacements.put("ic2_conn_copper", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
IndustrialWires.MODID + ":blocks/ic2_conn_copper"));
ConnLoader.baseModels.put("ic2_relay_copper", new ResourceLocation("immersiveengineering:block/connector/connector_lv.obj"));
ConnLoader.textureReplacements.put("ic2_relay_copper", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_lv",
IndustrialWires.MODID + ":blocks/ic2_relay_copper"));
ConnLoader.baseModels.put("ic2_conn_gold", new ResourceLocation("immersiveengineering:block/connector/connector_mv.obj"));
ConnLoader.textureReplacements.put("ic2_conn_gold", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_mv",
IndustrialWires.MODID + ":blocks/ic2_conn_gold"));
ConnLoader.baseModels.put("ic2_relay_gold", new ResourceLocation("immersiveengineering:block/connector/connector_mv.obj"));
ConnLoader.textureReplacements.put("ic2_relay_gold", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_mv",
IndustrialWires.MODID + ":blocks/ic2_relay_gold"));
ConnLoader.baseModels.put("ic2_conn_hv", new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"));
ConnLoader.textureReplacements.put("ic2_conn_hv", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
IndustrialWires.MODID + ":blocks/ic2_conn_hv"));
ConnLoader.baseModels.put("ic2_relay_hv", new ResourceLocation("immersiveengineering:block/connector/relay_hv.obj"));
ConnLoader.baseModels.put("ic2_conn_glass", new ResourceLocation("immersiveengineering:block/connector/connector_hv.obj"));
ConnLoader.textureReplacements.put("ic2_conn_glass", ImmutableMap.of("#immersiveengineering:blocks/connector_connector_hv",
IndustrialWires.MODID + ":blocks/ic2_conn_glass"));
ConnLoader.baseModels.put("ic2_relay_glass", new ResourceLocation("immersiveengineering:block/connector/relay_hv.obj"));
ConnLoader.textureReplacements.put("ic2_relay_glass", ImmutableMap.of("#immersiveengineering:blocks/connector_relay_hv",
IndustrialWires.MODID + ":blocks/ic2_relay_glass"));
ConnLoader.baseModels.put("rs_panel_conn", new ResourceLocation("industrialwires:block/rs_panel_conn.obj"));
for (int meta = 0; meta < ItemIC2Coil.subNames.length; meta++) {
ResourceLocation loc = new ResourceLocation(IndustrialWires.MODID, "ic2_wire_coil/" + ItemIC2Coil.subNames[meta]);
ModelBakery.registerItemVariants(IndustrialWires.coil, loc);
ModelLoader.setCustomModelResourceLocation(IndustrialWires.coil, meta, new ModelResourceLocation(loc, "inventory"));
}
for (int meta = 0; meta < ItemPanelComponent.types.length; meta++) {
ResourceLocation loc = new ResourceLocation(IndustrialWires.MODID, "panel_component/" + ItemPanelComponent.types[meta]);
ModelBakery.registerItemVariants(IndustrialWires.panelComponent, loc);
ModelLoader.setCustomModelResourceLocation(IndustrialWires.panelComponent, meta, new ModelResourceLocation(loc, "inventory"));
}
for (int meta = 0; meta < ItemKey.types.length; meta++) {
ResourceLocation loc = new ResourceLocation(IndustrialWires.MODID, "key/" + ItemKey.types[meta]);
ModelBakery.registerItemVariants(IndustrialWires.key, loc);
ModelLoader.setCustomModelResourceLocation(IndustrialWires.key, meta, new ModelResourceLocation(loc, "inventory"));
}
Block[] blocks = {IndustrialWires.ic2conn, IndustrialWires.mechConv, IndustrialWires.jacobsLadder, IndustrialWires.panel};
for (Block b : blocks) {
if (b != null) {
Item blockItem = Item.getItemFromBlock(b);
final ResourceLocation loc = b.getRegistryName();
assert loc != null;
ModelLoader.setCustomMeshDefinition(blockItem, stack -> new ModelResourceLocation(loc, "inventory"));
Object[] v = ((IMetaEnum) b).getValues();
for (int meta = 0; meta < v.length; meta++) {
String location = loc.toString();
String prop = "inventory,type=" + v[meta].toString().toLowerCase(Locale.US);
try {
ModelLoader.setCustomModelResourceLocation(blockItem, meta, new ModelResourceLocation(location, prop));
} catch (NullPointerException npe) {
throw new RuntimeException(b + " lacks an item!", npe);
}
}
}
}
OBJLoader.INSTANCE.addDomain(IndustrialWires.MODID);
ModelLoaderRegistry.registerLoader(new PanelModelLoader());
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityJacobsLadder.class, new TileRenderJacobsLadder());
}
@Override
public void postInit() {
super.postInit();
ManualInstance m = ManualHelper.getManual();
PositionedItemStack[][] wireRecipes = new PositionedItemStack[3][10];
int xBase = 15;
ItemStack tinCable = IC2Items.getItem("cable", "type:tin,insulation:0");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
wireRecipes[0][3 * i + j] = new PositionedItemStack(tinCable.copy(), 18 * i + xBase, 18 * j);
}
}
ItemStack tmp = new ItemStack(IndustrialWires.coil);
ItemIC2Coil.setLength(tmp, 9);
wireRecipes[0][9] = new PositionedItemStack(tmp, 18 * 4 + xBase, 18);
Random r = new Random();
for (int i = 1; i < 3; i++) {
int lengthSum = 0;
for (int j1 = 0; j1 < 3; j1++) {
for (int j2 = 0; j2 < 3; j2++) {
if (r.nextBoolean()) {
// cable
lengthSum++;
wireRecipes[i][3 * j1 + j2] = new PositionedItemStack(tinCable.copy(), 18 * j1 + xBase, 18 * j2);
} else {
// wire coil
int length = r.nextInt(99) + 1;
tmp = new ItemStack(IndustrialWires.coil);
ItemIC2Coil.setLength(tmp, length);
wireRecipes[i][3 * j1 + j2] = new PositionedItemStack(tmp, 18 * j1 + xBase, 18 * j2);
lengthSum += length;
}
}
}
tmp = new ItemStack(IndustrialWires.coil);
ItemIC2Coil.setLength(tmp, lengthSum);
wireRecipes[i][9] = new PositionedItemStack(tmp, 18 * 4 + xBase, 18);
}
ClientUtils.mc().getItemColors().registerItemColorHandler((stack, pass) -> {
if (pass == 1) {
PanelComponent pc = ItemPanelComponent.componentFromStack(stack);
if (pc != null) {
return 0xff000000 | pc.getColor();
}
}
return ~0;
}, IndustrialWires.panelComponent);
m.addEntry("industrialwires.wires", "industrialwires",
new ManualPages.CraftingMulti(m, "industrialwires.wires0", new ItemStack(IndustrialWires.ic2conn, 1, 0), new ItemStack(IndustrialWires.ic2conn, 1, 1), new ItemStack(IndustrialWires.ic2conn, 1, 2), new ItemStack(IndustrialWires.ic2conn, 1, 3),
new ItemStack(IndustrialWires.ic2conn, 1, 4), new ItemStack(IndustrialWires.ic2conn, 1, 5), new ItemStack(IndustrialWires.ic2conn, 1, 6), new ItemStack(IndustrialWires.ic2conn, 1, 7)),
new ManualPages.Text(m, "industrialwires.wires1"),
new ManualPages.CraftingMulti(m, "industrialwires.wires2", (Object[]) wireRecipes)
);
if (IndustrialWires.mechConv != null) {
m.addEntry("industrialwires.mechConv", "industrialwires",
new ManualPages.Crafting(m, "industrialwires.mechConv0", new ItemStack(IndustrialWires.mechConv, 1, 1)),
new ManualPages.Crafting(m, "industrialwires.mechConv1", new ItemStack(IndustrialWires.mechConv, 1, 2)),
new ManualPages.Crafting(m, "industrialwires.mechConv2", new ItemStack(IndustrialWires.mechConv, 1, 0))
);
}
Config.manual_doubleA.put("iwJacobsUsage", IWConfig.HVStuff.jacobsUsageEU);
Config.manual_int.put("iwKeysOnRing", IWConfig.maxKeysOnRing);
m.addEntry("industrialwires.jacobs", "industrialwires",
new ManualPages.CraftingMulti(m, "industrialwires.jacobs0", new ItemStack(IndustrialWires.jacobsLadder, 1, 0), new ItemStack(IndustrialWires.jacobsLadder, 1, 1), new ItemStack(IndustrialWires.jacobsLadder, 1, 2)),
new ManualPages.Text(m, "industrialwires.jacobs1"));
m.addEntry("industrialwires.intro", "control_panels",
new ManualPages.Text(m, "industrialwires.intro0"),
new ManualPages.Text(m, "industrialwires.intro1"),
new ManualPages.Crafting(m, "industrialwires.intro2", new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.DUMMY.ordinal())),
new ManualPages.Text(m, "industrialwires.intro3"),
new ManualPages.Crafting(m, "industrialwires.intro4", new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.UNFINISHED.ordinal())),
new ManualPages.Text(m, "industrialwires.intro5")
);
m.addEntry("industrialwires.panel_creator", "control_panels",
new ManualPages.Crafting(m, "industrialwires.panel_creator0", new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.CREATOR.ordinal())),
new ManualPages.Text(m, "industrialwires.panel_creator1"),
new ManualPages.Text(m, "industrialwires.panel_creator2")
);
m.addEntry("industrialwires.redstone", "control_panels",
new ManualPages.Crafting(m, "industrialwires.redstone0", new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.RS_WIRE.ordinal())),
new ManualPages.Text(m, "industrialwires.redstone1")
);
m.addEntry("industrialwires.components", "control_panels",
new ManualPages.Text(m, "industrialwires.components.general"),
new ManualPages.Crafting(m, "industrialwires.button", new ItemStack(IndustrialWires.panelComponent, 1, 0)),
new ManualPages.Crafting(m, "industrialwires.label", new ItemStack(IndustrialWires.panelComponent, 1, 1)),
new ManualPages.Crafting(m, "industrialwires.indicator_light", new ItemStack(IndustrialWires.panelComponent, 1, 2)),
new ManualPages.Crafting(m, "industrialwires.slider", new ItemStack(IndustrialWires.panelComponent, 1, 3)),
new ManualPages.CraftingMulti(m, "industrialwires.toggle_switch", new ItemStack(IndustrialWires.panelComponent, 1, 5), new ItemStack(IndustrialWires.panelComponent, 1, 6)),
new ManualPages.Text(m, "industrialwires.toggle_switch1"),
new ManualPages.Crafting(m, "industrialwires.variac", new ItemStack(IndustrialWires.panelComponent, 1, 4)),
new ManualPages.CraftingMulti(m, "industrialwires.lock", new ItemStack(IndustrialWires.panelComponent, 1, 7), new ItemStack(IndustrialWires.key)),
new ManualPages.Crafting(m, "industrialwires.lock1", new ItemStack(IndustrialWires.key, 1, 2)),
new ManualPages.Crafting(m, "industrialwires.panel_meter", new ItemStack(IndustrialWires.panelComponent, 1, 8))
);
}
@Override
public World getClientWorld() {
return Minecraft.getMinecraft().world;
}
private WeakHashMap<BlockPos, ISound> playingSounds = new WeakHashMap<>();
private static ResourceLocation jacobsStart = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_start");//~470 ms ~=9 ticks
private static ResourceLocation jacobsMiddle = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_middle");
private static ResourceLocation jacobsEnd = new ResourceLocation(IndustrialWires.MODID, "jacobs_ladder_end");//~210 ms ~= 4 ticks
@Override
public void playJacobsLadderSound(TileEntityJacobsLadder te, int phase, Vec3d soundPos) {
if (playingSounds.containsKey(te.getPos())) {
Minecraft.getMinecraft().getSoundHandler().stopSound(playingSounds.get(te.getPos()));
playingSounds.remove(te.getPos());
}
ResourceLocation event;
switch (phase) {
case 0:
event = jacobsStart;
break;
case 1:
event = jacobsMiddle;
break;
case 2:
event = jacobsEnd;
break;
default:
return;
}
PositionedSoundRecord sound = new PositionedSoundRecord(event, SoundCategory.BLOCKS, te.size.soundVolume, 1, false, 0, ISound.AttenuationType.LINEAR, (float) soundPos.x, (float) soundPos.y, (float) soundPos.z);
ClientUtils.mc().getSoundHandler().playSound(sound);
playingSounds.put(te.getPos(), sound);
}
@Override
public Gui getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == 0) {
TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
if (te instanceof TileEntityRSPanelConn) {
return new GuiRSPanelConn((TileEntityRSPanelConn) te);
}
if (te instanceof TileEntityPanelCreator) {
return new GuiPanelCreator(player.inventory, (TileEntityPanelCreator) te);
}
} else if (ID == 1) {
EnumHand h = z == 1 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
ItemStack held = player.getHeldItem(h);
if (!held.isEmpty()) {
if (held.getItem() == IndustrialWires.panelComponent) {
return new GuiPanelComponent(h, ItemPanelComponent.componentFromStack(held));
} else if (held.getItem() == IndustrialWires.key) {
return new GuiRenameKey(h);
}
}
}
return null;
}
}

View file

@ -1,28 +1,26 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client;
package malte0811.industrialWires.client;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nullable;
@ -31,7 +29,6 @@ import java.util.Arrays;
import static org.lwjgl.util.vector.Vector3f.cross;
import static org.lwjgl.util.vector.Vector3f.sub;
@SideOnly(Side.CLIENT)
public class RawQuad {
public final Vector3f[] vertices = new Vector3f[4];
public final EnumFacing facing;
@ -81,56 +78,10 @@ public class RawQuad {
this.light = light;
}
public static RawQuad unbake(BakedQuad q) {
Vector3f[] vertices = new Vector3f[4];
float[] color = new float[4];
Vector3f normal = new Vector3f();
float[][] uvs = new float[4][2];
TextureAtlasSprite sprite = q.getSprite();
VertexFormat format = q.getFormat();
int pos = 0;
for (int v = 0; v < 4; v++) {
for (int e = 0; e < format.getElementCount(); e++) {
switch (format.getElement(e).getUsage()) {
case POSITION:
int x = q.getVertexData()[pos];
int y = q.getVertexData()[pos + 1];
int z = q.getVertexData()[pos + 2];
vertices[v] = new Vector3f(Float.intBitsToFloat(x),
Float.intBitsToFloat(y),
Float.intBitsToFloat(z));
break;
case COLOR:
for (int i = 0; i < 4; i++) {
color[i] = Float.intBitsToFloat(q.getVertexData()[pos + i]);
}
break;
case UV:
if (format.getElement(e).getType() == VertexFormatElement.EnumType.FLOAT) {
uvs[v][0] = sprite.getUnInterpolatedU(Float.intBitsToFloat(q.getVertexData()[pos]));
uvs[v][1] = sprite.getUnInterpolatedV(Float.intBitsToFloat(q.getVertexData()[pos + 1]));
}
break;
case NORMAL:
x = q.getVertexData()[pos];
y = q.getVertexData()[pos + 1];
z = q.getVertexData()[pos + 2];
normal.set(Float.intBitsToFloat(x),
Float.intBitsToFloat(y),
Float.intBitsToFloat(z));
break;
}
pos += format.getElement(e).getSize() / 4;
}
}
return new RawQuad(vertices[0], vertices[1], vertices[2], vertices[3],
q.getFace(), sprite, color, normal, uvs, -1);
}
public RawQuad apply(Matrix4 mat) {
Matrix4 matNormal = mat.copy().transpose();
matNormal.invert();
return new RawQuad(mat.apply(vertices[0]), mat.apply(vertices[1]), mat.apply(vertices[2]), mat.apply(vertices[3]),
facing, tex, colorA, matNormal.apply(normal), uvs, light);
}
}
}

View file

@ -1,33 +1,18 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.gui;
package malte0811.industrialWires.client.gui;
import blusunrize.immersiveengineering.client.ClientUtils;
import blusunrize.immersiveengineering.client.gui.elements.GuiButtonCheckbox;
import blusunrize.immersiveengineering.client.gui.elements.GuiSliderIE;
import com.google.common.collect.ImmutableList;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.gui.elements.GuiChannelPicker;
import malte0811.industrialwires.client.gui.elements.GuiChannelPickerSmall;
import malte0811.industrialwires.client.gui.elements.GuiIntChooser;
import malte0811.industrialwires.containers.ContainerPanelComponent;
import malte0811.industrialwires.controlpanel.IConfigurableComponent;
import malte0811.industrialwires.controlpanel.PanelComponent;
import malte0811.industrialwires.network.MessageItemSync;
import net.minecraft.client.Minecraft;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.client.gui.elements.GuiChannelPicker;
import malte0811.industrialWires.client.gui.elements.GuiChannelPickerSmall;
import malte0811.industrialWires.client.gui.elements.GuiIntChooser;
import malte0811.industrialWires.containers.ContainerPanelComponent;
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.network.MessageItemSync;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
@ -43,8 +28,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.*;
public class GuiPanelComponent extends GuiContainer {
private PanelComponent component;
private IConfigurableComponent confComp;
@ -84,9 +67,9 @@ public class GuiPanelComponent extends GuiContainer {
toAdd.setText(sc.value);
stringTexts.add(toAdd);
}
IConfigurableComponent.RSColorConfig[] rs = confComp.getRSChannelOptions();
IConfigurableComponent.RSChannelConfig[] rs = confComp.getRSChannelOptions();
rsChannelChoosers.clear();
for (IConfigurableComponent.RSColorConfig rc : rs) {
for (IConfigurableComponent.RSChannelConfig rc : rs) {
if (rc.small) {
rsChannelChoosers.add(new GuiChannelPickerSmall(0, componentLeft + rc.x, componentTop + rc.y, 10, 40, rc.value));
} else {
@ -152,11 +135,6 @@ public class GuiPanelComponent extends GuiContainer {
sync(i, picker.getSelected());
}
if (stopNow) {
for (GuiChannelPicker picker2:rsChannelChoosers) {
if (picker!=picker2&&picker2 instanceof GuiChannelPickerSmall) {
((GuiChannelPickerSmall) picker2).close();
}
}
return;
}
}
@ -209,13 +187,14 @@ public class GuiPanelComponent extends GuiContainer {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
GlStateManager.color(1, 1, 1, 1);
RenderHelper.disableStandardItemLighting();
for (GuiChannelPicker pick : rsChannelChoosers) {
pick.drawButton(mc, mouseX, mouseY);
}
for (GuiButtonCheckbox box : boolButtons) {
box.drawButton(mc, mouseX, mouseY, partialTicks);
box.drawButton(mc, mouseX, mouseY);
}
for (GuiTextField field : stringTexts) {
field.drawTextBox();
@ -223,24 +202,8 @@ public class GuiPanelComponent extends GuiContainer {
for (GuiIntChooser choose : intChoosers) {
choose.drawChooser();
}
for (int i = 0; i < floatSliders.size(); i++) {
GuiSliderIE slider = floatSliders.get(i);
double oldV = slider.getValue();
slider.drawButton(mc, mouseX, mouseY, partialTicks);
if (oldV != slider.getValue()) {
sync(i, (float) slider.getValue());
}
}
GuiChannelPickerSmall openPicker = null;
for (GuiChannelPicker pick : rsChannelChoosers) {
if (pick instanceof GuiChannelPickerSmall&&((GuiChannelPickerSmall) pick).open) {
openPicker = (GuiChannelPickerSmall) pick;
} else {
pick.drawButton(mc, mouseX, mouseY, partialTicks);
}
}
if (openPicker != null) {
openPicker.drawButton(mc, mouseX, mouseY, partialTicks);
for (GuiSliderIE choose : floatSliders) {
choose.drawButton(mc, mouseX, mouseY);
}
//TOOLTIPS
for (int i = 0; i < rsChannelChoosers.size(); i++) {
@ -248,7 +211,6 @@ public class GuiPanelComponent extends GuiContainer {
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.RS_CHANNEL, i);
if (tooltip != null && pick.isHovered(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < boolButtons.size(); i++) {
@ -256,7 +218,6 @@ public class GuiPanelComponent extends GuiContainer {
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.BOOL, i);
if (tooltip != null && box.isMouseOver()) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < stringTexts.size(); i++) {
@ -265,7 +226,6 @@ public class GuiPanelComponent extends GuiContainer {
if (tooltip != null && mouseX >= field.x && mouseX < field.x + field.width &&
mouseY >= field.y && mouseY < field.y + field.height) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < intChoosers.size(); i++) {
@ -273,7 +233,6 @@ public class GuiPanelComponent extends GuiContainer {
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.INT, i);
if (tooltip != null && choose.isMouseOver(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < floatSliders.size(); i++) {
@ -281,48 +240,47 @@ public class GuiPanelComponent extends GuiContainer {
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.FLOAT, i);
if (tooltip != null && choose.isMouseOver()) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
}
private void sync(int id, String value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ID, id);
update.setString(VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setString(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, boolean value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ID, id);
update.setBoolean(VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setBoolean(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, byte value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ID, id);
update.setByte(VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setByte(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, int value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ID, id);
update.setInteger(VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setInteger(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
private void sync(int id, float value) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ID, id);
update.setFloat(VALUE, value);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ItemPanelComponent.ID, id);
update.setFloat(ItemPanelComponent.VALUE, value);
syncSingle(update);
}
@ -330,37 +288,37 @@ public class GuiPanelComponent extends GuiContainer {
NBTTagList list = new NBTTagList();
for (int i = 0; i < stringTexts.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ID, i);
update.setString(VALUE, stringTexts.get(i).getText());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setString(ItemPanelComponent.VALUE, stringTexts.get(i).getText());
list.appendTag(update);
}
for (int i = 0; i < boolButtons.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ID, i);
update.setBoolean(VALUE, boolButtons.get(i).state);
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setBoolean(ItemPanelComponent.VALUE, boolButtons.get(i).state);
list.appendTag(update);
}
for (int i = 0; i < rsChannelChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ID, i);
update.setByte(VALUE, rsChannelChoosers.get(i).getSelected());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setByte(ItemPanelComponent.VALUE, rsChannelChoosers.get(i).getSelected());
list.appendTag(update);
}
for (int i = 0; i < intChoosers.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ID, i);
update.setInteger(VALUE, intChoosers.get(i).getValue());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setInteger(ItemPanelComponent.VALUE, intChoosers.get(i).getValue());
list.appendTag(update);
}
for (int i = 0; i < floatSliders.size(); i++) {
NBTTagCompound update = new NBTTagCompound();
update.setInteger(TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ID, i);
update.setFloat(VALUE, (float) floatSliders.get(i).getValue());
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
update.setInteger(ItemPanelComponent.ID, i);
update.setFloat(ItemPanelComponent.VALUE, (float) floatSliders.get(i).getValue());
list.appendTag(update);
}
sync(list);
@ -376,6 +334,5 @@ public class GuiPanelComponent extends GuiContainer {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("data", list);
IndustrialWires.packetHandler.sendToServer(new MessageItemSync(container.hand, nbt));
IndustrialWires.panelComponent.onChange(nbt, Minecraft.getMinecraft().player, container.hand);
}
}

View file

@ -1,30 +1,33 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.gui;
package malte0811.industrialWires.client.gui;
import blusunrize.immersiveengineering.client.ClientUtils;
import com.google.common.collect.ImmutableList;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialwires.containers.ContainerPanelCreator;
import malte0811.industrialwires.controlpanel.MessageType;
import malte0811.industrialwires.controlpanel.PanelComponent;
import malte0811.industrialwires.controlpanel.PanelUtils;
import malte0811.industrialwires.items.ItemPanelComponent;
import malte0811.industrialwires.network.MessageGUIInteract;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.containers.ContainerPanelCreator;
import malte0811.industrialWires.controlpanel.MessageType;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.items.ItemPanelComponent;
import malte0811.industrialWires.network.MessageGUIInteract;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
@ -36,23 +39,14 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
public class GuiPanelCreator extends GuiContainer {
public int panelSize = 128;
private ContainerPanelCreator container;
private int snapToGrid = 0;
private boolean snapToGrid = false;
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/panel_creator.png");
public GuiPanelCreator(InventoryPlayer ip, TileEntityPanelCreator te) {
@ -66,128 +60,26 @@ public class GuiPanelCreator extends GuiContainer {
GlStateManager.color(1, 1, 1, 1);
mc.getTextureManager().bindTexture(textureLoc);
this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
for (PanelComponent pc : container.tile.components) {
drawPanelComponent(pc, -1, -1);
}
int x0 = getX0();
int y0 = getY0();
int xRel = mouseX - x0;
int yRel = mouseY - y0;
if (snapToGrid) {
xRel = (int) Math.floor(xRel * 16 / panelSize) * panelSize / 16;
yRel = (int) Math.floor(yRel * 16 / panelSize) * panelSize / 16;
}
for (PanelComponent pc : container.tile.components) {
drawPanelComponent(pc, -1, -1);
}
PanelComponent curr = getFloatingPC();
if (curr != null && 0 <= xRel && xRel <= panelSize && 0 <= yRel && yRel <= panelSize) {
Runnable after = ()->{};
if (snapToGrid != 0) {
curr.setX(xRel/(float)panelSize);
curr.setY(yRel/(float)panelSize);
BiFunction<Integer, Integer, Integer> right = (a, b)->b;
BiFunction<Integer, Integer, Integer> left = (a, b)->a;
Function<PanelComponent, Double> xSize = (pc)->{
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
return aabb.maxX-aabb.minX;
};
Function<PanelComponent, Double> ySize = (pc)->{
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
return aabb.maxZ-aabb.minZ;
};
Pair<Integer, Runnable> xSnap = snapToGrid(xRel, curr, PanelComponent::getX, PanelComponent::getY,
xSize, ySize, left, right);
xRel = xSnap.getLeft();
Pair<Integer, Runnable> ySnap = snapToGrid(yRel, curr, PanelComponent::getY, PanelComponent::getX,
ySize, xSize, right, left);
yRel = ySnap.getLeft();
after = ()->{
xSnap.getRight().run();
ySnap.getRight().run();
};
}
drawPanelComponent(curr, xRel, yRel);
after.run();
}
}
private Pair<Integer, Runnable> snapToGrid(int mouse, PanelComponent toPlace, Function<PanelComponent, Float> pos, Function<PanelComponent, Float> pos2,
Function<PanelComponent, Double> size,Function<PanelComponent, Double> size2,
BiFunction<Integer, Integer, Integer> getY, BiFunction<Integer, Integer, Integer> getX) {
List<PanelComponent> components = container.tile.components;
if (snapToGrid==2&&!components.isEmpty()) {
List<Pair<PanelComponent, Double>> compLefts = new ArrayList<>(components.size());
List<Pair<PanelComponent, Double>> compCenters = new ArrayList<>(components.size());
List<Pair<PanelComponent, Double>> compRights = new ArrayList<>(components.size());
for (PanelComponent pc : components) {
double compLeft = pos.apply(pc);
double compSize = size.apply(pc);
compLefts.add(new ImmutablePair<>(pc, compLeft));
compRights.add(new ImmutablePair<>(pc, compLeft + compSize));
compCenters.add(new ImmutablePair<>(pc, compLeft + compSize / 2));
}
double mainLeft = pos.apply(toPlace);
double mainSize = size.apply(toPlace);
double mainRight = mainLeft + mainSize;
double mainCenter = (mainRight + mainLeft) / 2;
Triple<PanelComponent, ComponentSnapType, Double> min = getMinDist(compLefts, mainLeft, mainCenter, mainRight);
{
Triple<PanelComponent, ComponentSnapType, Double> tmpMin = getMinDist(compCenters, mainLeft, mainCenter, mainRight);
if (Math.abs(tmpMin.getRight()) < Math.abs(min.getRight())) {
min = tmpMin;
}
tmpMin = getMinDist(compRights, mainLeft, mainCenter, mainRight);
if (Math.abs(tmpMin.getRight()) < Math.abs(min.getRight())) {
min = tmpMin;
}
}
if (Math.abs(min.getRight())<.5/16) {
int ret = (int)(mouse+min.getRight()*panelSize);
PanelComponent snappedTo = min.getLeft();
ComponentSnapType type = min.getMiddle();
return new ImmutablePair<>(ret,()->{
int hor1, hor2;
float posOther = pos2.apply(toPlace);
hor1 = Math.round(Math.min(posOther, pos2.apply(snappedTo))*panelSize);
hor2 = (int) Math.round(Math.max(posOther+size2.apply(toPlace), pos2.apply(snappedTo)+size2.apply(snappedTo))*panelSize);
int vert1 = (int) (ret+(.5*type.ordinal())*mainSize*panelSize);
int vert2 = vert1+1;
int x0 = getX0(), y0 = getY0();
drawRect(x0+getX.apply(hor1, vert1), y0+getY.apply(hor1, vert1), x0+getX.apply(hor2, vert2),
y0+getY.apply(hor2, vert2), 0xff666666);
});
}
}
if (snapToGrid!=0) {
mouse = Math.round(mouse * 16 / panelSize) * panelSize / 16;
}
return new ImmutablePair<>(mouse, ()->{});
}
private Triple<PanelComponent, ComponentSnapType, Double> getMinDist(List<Pair<PanelComponent, Double>> comps,
double left, double center, double right) {
Pair<PanelComponent, Double> tmpMin = Collections.min(comps, Comparator.comparingDouble(a -> Math.abs(a.getRight() - left)));
Triple<PanelComponent, ComponentSnapType, Double> totalMin = new ImmutableTriple<>(tmpMin.getLeft(), ComponentSnapType.LEFT,
tmpMin.getRight()-left);
tmpMin = Collections.min(comps, Comparator.comparingDouble(a -> Math.abs(a.getRight() - center)));
if (Math.abs(tmpMin.getRight() - center)<Math.abs(totalMin.getRight())) {
totalMin = new ImmutableTriple<>(tmpMin.getLeft(), ComponentSnapType.CENTER,
tmpMin.getRight()-center);
}
tmpMin = Collections.min(comps, Comparator.comparingDouble(a -> Math.abs(a.getRight() - right)));
if (Math.abs(tmpMin.getRight() - right)<Math.abs(totalMin.getRight())) {
totalMin = new ImmutableTriple<>(tmpMin.getLeft(), ComponentSnapType.RIGHT,
tmpMin.getRight()-right);
}
return totalMin;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
String tooltip = null;
if (buttonList.get(0).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID + ".desc.create_panel");
@ -195,7 +87,11 @@ public class GuiPanelCreator extends GuiContainer {
} else if (buttonList.get(1).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID + ".desc.remove_all");
} else if (buttonList.get(2).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID + ".desc.snap"+snapToGrid);
if (snapToGrid) {
tooltip = I18n.format(IndustrialWires.MODID + ".desc.disable_snap");
} else {
tooltip = I18n.format(IndustrialWires.MODID + ".desc.enable_snap");
}
} else if (buttonList.get(3).isMouseOver()) {
tooltip = I18n.format(IndustrialWires.MODID + ".desc.disassemble");
}
@ -303,13 +199,13 @@ public class GuiPanelCreator extends GuiContainer {
nbt.setInteger("type", MessageType.REMOVE_ALL.ordinal());
break;
case 2:
snapToGrid = (snapToGrid+1)%3;
snapToGrid = !snapToGrid;
break;
case 3:
nbt.setInteger("type", MessageType.DISASSEMBLE.ordinal());
break;
}
if (!nbt.isEmpty()) {
if (!nbt.hasNoTags()) {
IndustrialWires.packetHandler.sendToServer(new MessageGUIInteract(container.tile, nbt));
}
}
@ -329,10 +225,4 @@ public class GuiPanelCreator extends GuiContainer {
lastFloatingPC = ItemPanelComponent.componentFromStack(floating);
return lastFloatingPC;
}
private enum ComponentSnapType {
LEFT,
CENTER,
RIGHT;
}
}

View file

@ -1,25 +1,28 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.gui;
package malte0811.industrialWires.client.gui;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.controlpanel.TileEntityRSPanel;
import malte0811.industrialwires.client.gui.elements.GuiIntChooser;
import malte0811.industrialwires.containers.ContainerRSPanelConn;
import malte0811.industrialwires.network.MessageGUIInteract;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import malte0811.industrialWires.client.gui.elements.GuiIntChooser;
import malte0811.industrialWires.containers.ContainerRSPanelConn;
import malte0811.industrialWires.network.MessageGUIInteract;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
@ -30,10 +33,10 @@ import net.minecraft.util.ResourceLocation;
import java.io.IOException;
public class GuiRSPanelConn extends GuiContainer {
private TileEntityRSPanel te;
private TileEntityRSPanelConn te;
private GuiIntChooser chooser;
public GuiRSPanelConn(TileEntityRSPanel tile) {
public GuiRSPanelConn(TileEntityRSPanelConn tile) {
super(new ContainerRSPanelConn(tile));
te = tile;
}
@ -56,9 +59,7 @@ public class GuiRSPanelConn extends GuiContainer {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
GlStateManager.color(1, 1, 1, 1);
RenderHelper.disableStandardItemLighting();
chooser.drawChooser();

View file

@ -1,23 +1,26 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.gui;
package malte0811.industrialWires.client.gui;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.containers.ContainerRenameKey;
import malte0811.industrialwires.network.MessageItemSync;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.containers.ContainerRenameKey;
import malte0811.industrialWires.network.MessageItemSync;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
@ -56,9 +59,7 @@ public class GuiRenameKey extends GuiContainer {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
GlStateManager.color(1, 1, 1, 1);
RenderHelper.disableStandardItemLighting();
field.drawTextBox();

View file

@ -1,19 +1,4 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.gui.elements;
package malte0811.industrialWires.client.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
@ -32,7 +17,7 @@ public class GuiChannelPicker extends GuiButton {
}
@Override
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float patrtialTicks) {
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
@ -46,7 +31,7 @@ public class GuiChannelPicker extends GuiButton {
int xMax = xMin + width / 4;
int yMax = yMin + height / 4;
EnumDyeColor color = EnumDyeColor.byMetadata(i);
int colorVal = color.getColorValue() | 0xff000000;
int colorVal = color.getMapColor().colorValue | 0xff000000;
if (mouseX >= xMin && mouseX < xMax && mouseY >= yMin && mouseY < yMax) {
currHovered = i;
}

View file

@ -1,19 +1,22 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.gui.elements;
package malte0811.industrialWires.client.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
@ -22,7 +25,7 @@ import net.minecraft.item.EnumDyeColor;
import javax.annotation.Nonnull;
public class GuiChannelPickerSmall extends GuiChannelPicker {
public boolean open = false;
private boolean open = false;
private int offSize, onSize;
public GuiChannelPickerSmall(int id, int x, int y, int offSize, int onSize, byte selectedChannel) {
@ -33,17 +36,16 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
}
@Override
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float partialTicks) {
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
if (open) {
drawRect(x, y, x + width, y + height, 0xff99ff99);
super.drawButton(mc, mouseX, mouseY, partialTicks);
super.drawButton(mc, mouseX, mouseY);
} else {
EnumDyeColor color = EnumDyeColor.byMetadata(selected);
int colorVal = color.getColorValue() | 0xff000000;
int colorVal = color.getMapColor().colorValue | 0xff000000;
drawRect(x, y, x + width, y + height, colorVal);
}
}
@ -64,14 +66,10 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
select();
ret = true;
}
close();
open = false;
width = offSize;
height = offSize;
return ret;
}
}
public void close() {
open = false;
width = offSize;
height = offSize;
}
}

View file

@ -1,19 +1,4 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.gui.elements;
package malte0811.industrialWires.client.gui.elements;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
@ -39,23 +24,13 @@ public class GuiIntChooser extends Gui {
public void drawChooser() {
int color = 0xE0E0E0;
String val = String.format(format, Integer.toString(Math.abs(value))).replace(' ', '0');
if (allowNegative) {
if (value > 0) {
val = "+" + val;
} else if (value < 0) {
val = "-" + val;
} else {
val = "0" + val;
}
}
mc.fontRenderer.drawStringWithShadow("-", xPos, yPos, color);
mc.fontRenderer.drawStringWithShadow("+", xPlus, yPos, color);
color = 0x9999ff;
if (allowNegative&&value!=0) {
color = value<0?0xff9999:0x99ff99;
String val = String.format(format, Integer.toString(value)).replace(' ', '0');
if (value >= 0 && allowNegative) {
val = "+" + val;
}
mc.fontRenderer.drawStringWithShadow(val, xPos + mc.fontRenderer.getCharWidth('-') + 1, yPos, color);
mc.fontRenderer.drawStringWithShadow("-", xPos, yPos, color);
mc.fontRenderer.drawStringWithShadow("+", xPlus, yPos, color);
}
public void click(int x, int y) {
@ -66,7 +41,7 @@ public class GuiIntChooser extends Gui {
value++;
}
} else if (x >= xPos && x <= xPos + mc.fontRenderer.getCharWidth('-')) {
if (value > (allowNegative ? -1 : 0)) {
if (value > (allowNegative ? -value : 0)) {
value--;
}
}

View file

@ -1,30 +1,33 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.panelmodel;
package malte0811.industrialWires.client.panelmodel;
import blusunrize.immersiveengineering.api.IEApi;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableList;
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialwires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialwires.blocks.controlpanel.TileEntityUnfinishedPanel;
import malte0811.industrialwires.controlpanel.PanelUtils;
import malte0811.industrialwires.controlpanel.PropertyComponents;
import malte0811.industrialwires.controlpanel.PropertyComponents.PanelRenderProperties;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityUnfinishedPanel;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.controlpanel.PropertyComponents;
import malte0811.industrialWires.controlpanel.PropertyComponents.PanelRenderProperties;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -33,8 +36,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -44,7 +45,6 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@SideOnly(Side.CLIENT)
public class PanelModel implements IBakedModel {
public final static Cache<PanelRenderProperties, AssembledBakedModel> modelCache = CacheBuilder.newBuilder()
.maximumSize(100)

View file

@ -1,23 +1,27 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.panelmodel;
package malte0811.industrialWires.client.panelmodel;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.controlpanel.PanelUtils;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
@ -33,7 +37,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
public class PanelModelLoader implements ICustomModelLoader {
public static final String RESOURCE_BASE = "models/block/";
@ -46,14 +49,13 @@ public class PanelModelLoader implements ICustomModelLoader {
}
@Override
public boolean accepts(@Nonnull ResourceLocation modelLocation) {
return modelLocation.getPath().contains(RESOURCE_BASE + RESOURCE_LOCATION);
public boolean accepts(ResourceLocation modelLocation) {
return modelLocation.getResourcePath().contains(RESOURCE_BASE + RESOURCE_LOCATION);
}
@Nonnull
@Override
public IModel loadModel(@Nonnull ResourceLocation modelLocation) throws IOException {
String resourcePath = modelLocation.getPath();
public IModel loadModel(ResourceLocation modelLocation) throws IOException {
String resourcePath = modelLocation.getResourcePath();
int pos = resourcePath.indexOf(RESOURCE_LOCATION);
if (pos >= 0) {
return new PanelModelBase();
@ -63,13 +65,11 @@ public class PanelModelLoader implements ICustomModelLoader {
private class PanelModelBase implements IModel {
@Nonnull
@Override
public Collection<ResourceLocation> getDependencies() {
return ImmutableList.of();
}
@Nonnull
@Override
public Collection<ResourceLocation> getTextures() {
try {
@ -82,9 +82,8 @@ public class PanelModelLoader implements ICustomModelLoader {
}
}
@Nonnull
@Override
public IBakedModel bake(@Nonnull IModelState state, @Nonnull VertexFormat format, @Nonnull Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
try {
return new PanelModel();
} catch (Exception e) {
@ -92,5 +91,10 @@ public class PanelModelLoader implements ICustomModelLoader {
}
}
@Override
public IModelState getDefaultState() {
return null;
}
}
}

View file

@ -1,23 +1,26 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.panelmodel;
package malte0811.industrialWires.client.panelmodel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import com.google.common.collect.ImmutableList;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialWires.client.RawQuad;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@ -29,38 +32,22 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.Map;
import java.util.WeakHashMap;
public class RawModelFontRenderer extends FontRenderer {
public static final ResourceLocation FONT = new ResourceLocation("minecraft", "textures/font/ascii.png");
private static final Map<Thread, RawModelFontRenderer> instances = new WeakHashMap<>();
float[] colorA = new float[4];
private ImmutableList.Builder<RawQuad> builder = ImmutableList.builder();
private final Vector3f normal = new Vector3f(0, 1, 0);
private float scale;
public final float scale;
public Matrix4 transform = null;
private static TextureAtlasSprite sprite = null;
private TextureAtlasSprite sprite;
public static RawModelFontRenderer get() {
Thread current = Thread.currentThread();
if (!instances.containsKey(current)) {
instances.put(current, new RawModelFontRenderer(Minecraft.getMinecraft().gameSettings, FONT, Minecraft.getMinecraft().getTextureManager(),
false, 1));
}
return instances.get(current);
}
private RawModelFontRenderer(GameSettings settings, ResourceLocation font, TextureManager manager, boolean isUnicode, float scale) {
public RawModelFontRenderer(GameSettings settings, ResourceLocation font, TextureManager manager, boolean isUnicode, float scale) {
super(settings, font, manager, isUnicode);
this.scale = scale / (9 * 16);
onResourceManagerReload(null);
}
public void setScale(float scale) {
this.scale = scale / (9 * 16);
}
@Override
protected float renderDefaultChar(int pos, boolean italic) {
float x = (pos % 16);
@ -91,10 +78,10 @@ public class RawModelFontRenderer extends FontRenderer {
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
super.onResourceManagerReload(resourceManager);
String p = locationFontTexture.getPath();
String p = locationFontTexture.getResourcePath();
if (p.startsWith("textures/")) p = p.substring("textures/".length(), p.length());
if (p.endsWith(".png")) p = p.substring(0, p.length() - ".png".length());
String f = locationFontTexture.getNamespace() + ":" + p;
String f = locationFontTexture.getResourceDomain() + ":" + p;
sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(f);
}
@ -125,8 +112,4 @@ public class RawModelFontRenderer extends FontRenderer {
protected void bindTexture(@Nonnull ResourceLocation location) {
//NO-OP
}
public float getScale() {
return scale;
}
}
}

View file

@ -1,19 +1,4 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.panelmodel;
package malte0811.industrialWires.client.panelmodel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;

View file

@ -1,57 +1,58 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.client.render;
package malte0811.industrialWires.client.render;
import malte0811.industrialwires.blocks.hv.TileEntityJacobsLadder;
import malte0811.industrialwires.blocks.hv.TileEntityJacobsLadder.LadderSize;
import malte0811.industrialwires.util.Beziers;
import net.minecraft.client.renderer.BufferBuilder;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.TileEntityJacobsLadder.LadderSize;
import malte0811.industrialWires.util.Beziers;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.Vec3d;
import org.lwjgl.opengl.GL11;
import static malte0811.industrialwires.blocks.hv.TileEntityJacobsLadder.getColor;
public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntityJacobsLadder> {
@Override
public void render(TileEntityJacobsLadder tile, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
super.render(tile, x, y, z, partialTicks, destroyStage, alpha);
public void renderTileEntityAt(TileEntityJacobsLadder tile, double x, double y, double z, float partialTicks, int destroyStage) {
super.renderTileEntityAt(tile, x, y, z, partialTicks, destroyStage);
if (!tile.isDummy() && tile.timeTillActive == 0 && tile.controls[0] != null) {
GlStateManager.pushMatrix();
GlStateManager.translate(x + .5, y + tile.size.heightOffset, z + .5);
GlStateManager.rotate(tile.facing.getHorizontalAngle(), 0, 1, 0);
GlStateManager.translate(-tile.size.bottomDistance / 2, 0, 0);
GlStateManager.disableTexture2D();
GlStateManager.disableLighting();
GlStateManager.shadeModel(GL11.GL_SMOOTH);
if (Shaders.areShadersEnabled()) {
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
}
setLightmapDisabled(true);
float oldBX = OpenGlHelper.lastBrightnessX;
float oldBY = OpenGlHelper.lastBrightnessY;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 238, 238);
GlStateManager.color(1, .85F, 1, 1);
Vec3d[] controls = new Vec3d[tile.size.arcPoints];
for (int i = 0; i < tile.size.arcPoints; i++) {
Vec3d speed = tile.controlMovement[i].scale(partialTicks);
controls[i] = tile.controls[i].add(speed);
Vec3d speed = tile.controlMovement[i];
controls[i] = tile.controls[i].addVector(speed.x * partialTicks, speed.y * partialTicks, speed.z * partialTicks);
}
drawBezier(controls, tile.salt, tile.size);
//DEBUG CODE
@ -69,64 +70,85 @@ public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntity
tes.draw();*/
//END OF DEBUG CODE
setLightmapDisabled(false);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, oldBX, oldBY);
GlStateManager.enableTexture2D();
GlStateManager.enableLighting();
GlStateManager.shadeModel(GL11.GL_FLAT);
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
private void drawBezier(Vec3d[] controls, double salt, LadderSize size) {
Shaders.useShader(Shaders.JACOBS_ARC);
int steps = size.renderPoints;
double diameter = size.renderDiameter;
Vec3d radY = new Vec3d(0, diameter / 2, 0);
Vec3d radZ = new Vec3d(0, 0, diameter / 2);
Tessellator tes = Tessellator.getInstance();
BufferBuilder vertBuffer = tes.getBuffer();
VertexBuffer vertBuffer = tes.getBuffer();
float[][] colors = new float[steps + 1][];
vertBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
Vec3d last = Beziers.getPoint(0, controls);
colors[0] = getColor(0, salt, size);
if (Shaders.areShadersEnabled()) {
colors[0][0] = 0;
}
for (int i = 1; i <= steps; i++) {
double d = i / (double) steps;
colors[i] = getColor(d, salt, size);
Vec3d pos = Beziers.getPoint(d, controls);
if (Shaders.areShadersEnabled()) {
colors[i][0] = (float) d;
}
drawQuad(last, pos, radY, colors[i - 1], colors[i], vertBuffer, false);
drawQuad(last, pos, radZ, colors[i - 1], colors[i], vertBuffer, false);
drawQuad(last, pos, radY, colors[i - 1], colors[i], vertBuffer);
drawQuad(last, pos, radZ, colors[i - 1], colors[i], vertBuffer);
last = pos;
}
tes.draw();
Shaders.stopUsingShaders();
}
private void drawQuad(Vec3d v0, Vec3d v1, Vec3d rad, float[] color0, float[] color1, BufferBuilder vertexBuffer,
boolean horizontal) {
float alpha0 = horizontal?.5F:0;
float alpha1 = horizontal?.5F:1;
color(color1, alpha0, vertexBuffer.pos(v1.x - rad.x, v1.y - rad.y, v1.z - rad.z)).endVertex();
color(color0, alpha0, vertexBuffer.pos(v0.x - rad.x, v0.y - rad.y, v0.z - rad.z)).endVertex();
color(color0, alpha1, vertexBuffer.pos(v0.x + rad.x, v0.y + rad.y, v0.z + rad.z)).endVertex();
color(color1, alpha1, vertexBuffer.pos(v1.x + rad.x, v1.y + rad.y, v1.z + rad.z)).endVertex();
private final float[] saltColor = {1, 190 / 255F, 50 / 255F};
private final float[] airColor = {1, .85F, 1};
color(color1, alpha1, vertexBuffer.pos(v1.x + rad.x, v1.y + rad.y, v1.z + rad.z)).endVertex();
color(color0, alpha1, vertexBuffer.pos(v0.x + rad.x, v0.y + rad.y, v0.z + rad.z)).endVertex();
color(color0, alpha0, vertexBuffer.pos(v0.x - rad.x, v0.y - rad.y, v0.z - rad.z)).endVertex();
color(color1, alpha0, vertexBuffer.pos(v1.x - rad.x, v1.y - rad.y, v1.z - rad.z)).endVertex();
private float[] getColor(double t, double salt, LadderSize size) {
salt = Math.min(salt, 1);
int factor = 20;
double smallMin = Math.exp(-.5);
double normalMin = Math.exp(-.25 * factor);
double hugeMin = Math.exp(-.75 * factor);
double saltyness = 0;
double t2 = t - .5;
switch (size) {
case SMALL:
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(t2)) - smallMin));
break;
case NORMAL:
saltyness = salt * (1 - .9 * (Math.exp(-factor * t2 * t2) - normalMin));
break;
case HUGE:
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(factor * t2 * t2 * t2)) - hugeMin));
break;
}
return interpolate(saltyness, saltColor, 1 - saltyness, airColor);
}
private BufferBuilder color(float[] color, float alpha, BufferBuilder vb) {
vb.color(color[0], color[1], color[2], alpha);
private float[] interpolate(double a, float[] cA, double b, float[] cB) {
float[] ret = new float[cA.length];
for (int i = 0; i < ret.length; i++) {
ret[i] = (float) (a * cA[i] + b * cB[i]);
}
return ret;
}
private void drawQuad(Vec3d v0, Vec3d v1, Vec3d rad, float[] color0, float[] color1, VertexBuffer vertexBuffer) {
color(color1, vertexBuffer.pos(v1.x - rad.x, v1.y - rad.y, v1.z - rad.z)).endVertex();
color(color0, vertexBuffer.pos(v0.x - rad.x, v0.y - rad.y, v0.z - rad.z)).endVertex();
color(color0, vertexBuffer.pos(v0.x + rad.x, v0.y + rad.y, v0.z + rad.z)).endVertex();
color(color1, vertexBuffer.pos(v1.x + rad.x, v1.y + rad.y, v1.z + rad.z)).endVertex();
color(color1, vertexBuffer.pos(v1.x + rad.x, v1.y + rad.y, v1.z + rad.z)).endVertex();
color(color0, vertexBuffer.pos(v0.x + rad.x, v0.y + rad.y, v0.z + rad.z)).endVertex();
color(color0, vertexBuffer.pos(v0.x - rad.x, v0.y - rad.y, v0.z - rad.z)).endVertex();
color(color1, vertexBuffer.pos(v1.x - rad.x, v1.y - rad.y, v1.z - rad.z)).endVertex();
}
private VertexBuffer color(float[] color, VertexBuffer vb) {
vb.color(color[0], color[1], color[2], 1);
return vb;
}
}

View file

@ -1,21 +1,24 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.containers;
package malte0811.industrialWires.containers;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.EnumHand;

View file

@ -1,24 +1,27 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.containers;
package malte0811.industrialWires.containers;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialwires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialwires.controlpanel.PanelUtils;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanelCreator;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;

View file

@ -1,35 +1,38 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.containers;
package malte0811.industrialWires.containers;
import malte0811.industrialwires.blocks.controlpanel.TileEntityRSPanel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import javax.annotation.Nonnull;
public class ContainerRSPanelConn extends Container {
private final TileEntityRSPanel te;
private final TileEntityRSPanelConn te;
public ContainerRSPanelConn(TileEntityRSPanel tile) {
public ContainerRSPanelConn(TileEntityRSPanelConn tile) {
te = tile;
}
@Override
public boolean canInteractWith(@Nonnull EntityPlayer playerIn) {
return playerIn.getDistanceSq(te.getBlockPos()) < 64;
return playerIn.getDistanceSq(te.getPos()) < 64;
}
}

View file

@ -1,21 +1,24 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.containers;
package malte0811.industrialWires.containers;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.EnumHand;

View file

@ -1,38 +1,38 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.COLOR;
public class CoveredToggleSwitch extends ToggleSwitch {
private int color = 0xff0000;
private SwitchState state = SwitchState.CLOSED;
@ -43,7 +43,6 @@ public class CoveredToggleSwitch extends ToggleSwitch {
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
float[] color = PanelUtils.getFloatColor(true, this.color);
active = state.active;
@ -61,17 +60,17 @@ public class CoveredToggleSwitch extends ToggleSwitch {
}
@Override
public void interactWith(Vec3d hitRel, EntityPlayerMP player) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (player.isSneaking() && state == SwitchState.OPEN) {
state = SwitchState.CLOSED;
} else {
state = state.next();
}
setOut(state.active);
setOut(state.active, tile);
tile.triggerRenderUpdate();
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
super.renderInGUIDefault(gui, 0xff000000 | this.color);
super.renderInGUI(gui);
@ -80,18 +79,20 @@ public class CoveredToggleSwitch extends ToggleSwitch {
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
super.writeCustomNBT(nbt, toItem);
if (!toItem) {
nbt.setInteger("state", state.ordinal());
}
nbt.setByte(RS_CHANNEL, rsOutputChannel);
nbt.setInteger(RS_ID, rsOutputId);
nbt.setInteger(COLOR, color);
}
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
super.readCustomNBT(nbt);
state = SwitchState.values()[nbt.getInteger("state")];
color = nbt.getInteger(COLOR);
rsOutputChannel = nbt.getByte(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
@Nonnull
@ -100,7 +101,8 @@ public class CoveredToggleSwitch extends ToggleSwitch {
CoveredToggleSwitch ret = new CoveredToggleSwitch();
ret.color = color;
ret.state = state;
ret.outputChannel = outputChannel;
ret.rsOutputChannel = rsOutputChannel;
ret.rsOutputId = rsOutputId;
ret.active = active;
ret.setX(getX());
ret.setY(getY());
@ -129,7 +131,6 @@ public class CoveredToggleSwitch extends ToggleSwitch {
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigName(ConfigType type, int id) {
if (type == ConfigType.FLOAT) {
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
@ -138,7 +139,6 @@ public class CoveredToggleSwitch extends ToggleSwitch {
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
if (type == ConfigType.FLOAT) {
return null;
@ -159,15 +159,20 @@ public class CoveredToggleSwitch extends ToggleSwitch {
CoveredToggleSwitch that = (CoveredToggleSwitch) o;
if (rsOutputId != that.rsOutputId) return false;
if (rsOutputChannel != that.rsOutputChannel) return false;
if (color != that.color) return false;
return state == that.state;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + rsOutputId;
result = 31 * result + (int) rsOutputChannel;
result = 31 * result + color;
result = 31 * result + state.hashCode();
result = 31 * result + (state != null ? state.hashCode() : 0);
return result;
}

View file

@ -1,24 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.api.tool.IConfigurableTool.ToolConfig;
import net.minecraft.nbt.NBTBase;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
@ -33,22 +34,20 @@ public interface IConfigurableComponent {
* @return a TRANSLATED name for the config option. Try to keep this short.
*/
@Nullable
@SideOnly(Side.CLIENT)
String fomatConfigName(ConfigType type, int id);
/**
* @return a TRANSLATED name for the config option, displayed when hovering over it
*/
@Nullable
@SideOnly(Side.CLIENT)
String fomatConfigDescription(ConfigType type, int id);
default StringConfig[] getStringOptions() {
return new StringConfig[0];
}
default RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[0];
default RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[0];
}
default IntConfig[] getIntegerOptions() {
@ -84,14 +83,14 @@ public interface IConfigurableComponent {
}
}
class RSColorConfig extends UniversalConfig<Byte> {
class RSChannelConfig extends UniversalConfig<Byte> {
public boolean small;
public RSColorConfig(String name, int x, int y, Byte value) {
public RSChannelConfig(String name, int x, int y, Byte value) {
this(name, x, y, value, false);
}
public RSColorConfig(String name, int x, int y, Byte value, boolean small) {
public RSChannelConfig(String name, int x, int y, Byte value, boolean small) {
super(name, x, y, value);
this.small = small;
}

View file

@ -1,33 +1,36 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -36,11 +39,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import static malte0811.industrialwires.util.NBTKeys.*;
public class IndicatorLight extends PanelComponent implements IConfigurableComponent {
@Nonnull
private RSChannel inputChannel = RSChannel.DEFAULT_CHANNEL;
private int rsInputId;
private byte rsInputChannel;
private int colorA = 0xff00;
private byte rsInput;
@ -48,16 +49,17 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
super("indicator_light");
}
public IndicatorLight(@Nonnull RSChannel input, int color) {
public IndicatorLight(int rsId, byte rsChannel, int color) {
this();
colorA = color;
inputChannel = input;
rsInputChannel = rsChannel;
rsInputId = rsId;
}
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
nbt.setInteger(RS_ID, inputChannel.getController());
nbt.setByte(RS_CHANNEL, inputChannel.getColor());
nbt.setInteger(RS_ID, rsInputId);
nbt.setByte(RS_CHANNEL, rsInputChannel);
nbt.setInteger(COLOR, colorA);
if (!toItem) {
nbt.setInteger("rsInput", rsInput);
@ -66,9 +68,8 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
int rsController = nbt.getInteger(RS_ID);
byte rsColor = nbt.getByte(RS_CHANNEL);
inputChannel = new RSChannel(rsController, rsColor);
rsInputId = nbt.getInteger(RS_ID);
rsInputChannel = nbt.getByte(RS_CHANNEL);
colorA = nbt.getInteger(COLOR);
rsInput = nbt.getByte("rsInput");
}
@ -76,7 +77,6 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
private static final float size = .0625F;
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
float[] color = new float[4];
color[3] = 1;
@ -94,7 +94,7 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Nonnull
@Override
public PanelComponent copyOf() {
IndicatorLight ret = new IndicatorLight(inputChannel, colorA);
IndicatorLight ret = new IndicatorLight(rsInputId, rsInputChannel, colorA);
ret.rsInput = rsInput;
ret.setX(x);
ret.setY(y);
@ -112,27 +112,30 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
}
@Override
public void interactWith(Vec3d hitRelative, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
}
@Override
public void update() {
public void update(TileEntityPanel tile) {
}
private Consumer<ControlPanelNetwork.RSChannelState> handler = (state) -> {
if (state.getStrength() != rsInput) {
rsInput = state.getStrength();
panel.markDirty();
private TileEntityPanel panel;
private Consumer<byte[]> handler = (input) -> {
if (input[rsInputChannel] != rsInput) {
rsInput = input[rsInputChannel];
panel.triggerRenderUpdate();
}
};
@Nullable
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
net.addListener(this, handler, inputChannel);
public Consumer<byte[]> getRSInputHandler(int id, TileEntityPanel panel) {
if (id == rsInputId) {
this.panel = panel;
return handler;
}
return null;
}
@Override
@ -161,7 +164,6 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, colorA);
}
@ -169,16 +171,12 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
if (id == 0) {
inputChannel = inputChannel.withColor(value);
}
break;
case INT:
if (id == 0) {
inputChannel = inputChannel.withController(value);
}
break;
case RS_CHANNEL:
rsInputChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsInputId = ((NBTTagInt) value).getInt();
break;
case FLOAT:
colorA = PanelUtils.setColor(colorA, id, value);
break;
@ -187,7 +185,6 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Nullable
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
@ -201,7 +198,6 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Nullable
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case FLOAT:
@ -216,16 +212,16 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
}
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{
new RSColorConfig("channel", 0, 0, inputChannel.getColor())
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsInputChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 45, inputChannel.getController(), 2, false)
new IntConfig("rsId", 0, 45, rsInputId, 2, false)
};
}

View file

@ -1,45 +1,49 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.client.panelmodel.RawModelFontRenderer;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.client.panelmodel.RawModelFontRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.COLOR;
import static malte0811.industrialwires.util.NBTKeys.TEXT;
public class Label extends PanelComponent implements IConfigurableComponent {
public static final ResourceLocation FONT = new ResourceLocation("minecraft", "textures/font/ascii.png");
private String text = "Test";
private RawModelFontRenderer renderer;
private int color = 0x808080;
public Label(String text, int color) {
@ -65,10 +69,8 @@ public class Label extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
RawModelFontRenderer render = RawModelFontRenderer.get();
render.setScale(1);
RawModelFontRenderer render = fontRenderer();
render.drawString(text, 0, 0, 0xff000000 | color);
return render.build();
}
@ -88,9 +90,9 @@ public class Label extends PanelComponent implements IConfigurableComponent {
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb == null) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
RawModelFontRenderer fr = RawModelFontRenderer.get();
float width = fr.getStringWidth(text) * fr.getScale();
float height = fr.FONT_HEIGHT * fr.getScale();
RawModelFontRenderer fr = fontRenderer();
float width = fr.getStringWidth(text) * fr.scale;
float height = fr.FONT_HEIGHT * fr.scale;
aabb = new AxisAlignedBB(getX(), 0, getY(), getX() + width, 0, getY() + height);
} else {
aabb = new AxisAlignedBB(getX(), 0, getY(), getX() + .001, 0, getY() + .001);
@ -100,12 +102,12 @@ public class Label extends PanelComponent implements IConfigurableComponent {
}
@Override
public void interactWith(Vec3d hitRelative, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
}
@Override
public void update() {
//NOP
public void update(TileEntityPanel tile) {
}
@Override
@ -118,8 +120,15 @@ public class Label extends PanelComponent implements IConfigurableComponent {
return 0;
}
private RawModelFontRenderer fontRenderer() {
if (renderer == null) {
renderer = new RawModelFontRenderer(Minecraft.getMinecraft().gameSettings, FONT, Minecraft.getMinecraft().getTextureManager(),
false, 1);
}
return renderer;
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
int left = (int) (gui.getX0() + getX() * gui.panelSize);
int top = (int) (gui.getY0() + getY() * gui.panelSize);
@ -145,7 +154,6 @@ public class Label extends PanelComponent implements IConfigurableComponent {
@Nullable
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
@ -157,7 +165,6 @@ public class Label extends PanelComponent implements IConfigurableComponent {
@Nullable
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case STRING:

View file

@ -1,60 +1,61 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannelState;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.*;
import static net.minecraftforge.fml.relauncher.Side.CLIENT;
public class LightedButton extends PanelComponent implements IConfigurableComponent {
public int color = 0xFF0000;
private boolean active;
private boolean latching;
@Nonnull
private RSChannel outputChannel = RSChannel.DEFAULT_CHANNEL;
public boolean active;
public boolean latching;
public int rsOutputId;
public int rsOutputChannel;
private int ticksTillOff;
LightedButton() {
public LightedButton() {
super("lighted_button");
}
public LightedButton(int color, boolean active, boolean latching, @Nonnull RSChannel out) {
public LightedButton(int color, boolean active, boolean latching, int rsOutputId, int rsOutputChannel) {
this();
this.color = color;
this.active = active;
this.latching = latching;
this.outputChannel = out;
this.rsOutputChannel = rsOutputChannel;
this.rsOutputId = rsOutputId;
}
@Override
@ -65,8 +66,8 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
nbt.setBoolean("active", active);
}
nbt.setBoolean(LATCHING, latching);
nbt.setByte(RS_CHANNEL, outputChannel.getColor());
nbt.setInteger(RS_ID, outputChannel.getController());
nbt.setInteger(RS_CHANNEL, rsOutputChannel);
nbt.setInteger(RS_ID, rsOutputId);
}
@Override
@ -75,15 +76,13 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
ticksTillOff = nbt.getInteger("timeout");
active = nbt.getBoolean("active");
latching = nbt.getBoolean(LATCHING);
byte rsOutputChannel = nbt.getByte(RS_CHANNEL);
int rsOutputId = nbt.getInteger(RS_ID);
this.outputChannel = new RSChannel(rsOutputId, rsOutputChannel);
rsOutputChannel = nbt.getInteger(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
private final static float size = .0625F;
@Override
@SideOnly(CLIENT)
public List<RawQuad> getQuads() {
float[] color = PanelUtils.getFloatColor(active, this.color);
List<RawQuad> ret = new ArrayList<>(5);
@ -98,7 +97,7 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
@Override
@Nonnull
public PanelComponent copyOf() {
LightedButton ret = new LightedButton(color, active, latching, outputChannel);
LightedButton ret = new LightedButton(color, active, latching, rsOutputId, rsOutputChannel);
ret.setX(x);
ret.setY(y);
ret.panelHeight = panelHeight;
@ -115,34 +114,34 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
public void interactWith(Vec3d hitRel, EntityPlayerMP player) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
if (!latching && active) {
return;
}
setOut(!active, tile);
if (!latching) {
ticksTillOff = 10;
} else {
setOut(!active);
if (!latching) {
ticksTillOff = 10;
}
}
panel.markDirty();
panel.triggerRenderUpdate();
tile.triggerRenderUpdate();
}
@Override
public void update() {
if (!latching && active) {
public void update(TileEntityPanel tile) {
if (!latching && ticksTillOff > 0) {
ticksTillOff--;
panel.markDirty();
if (ticksTillOff <= 0) {
setOut(false);
tile.markDirty();
if (ticksTillOff == 0) {
setOut(false, tile);
}
}
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
net.setOutputs(this, new RSChannelState(outputChannel, (byte) (active?15:0)));
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
super.registerRSOutput(id, out);
out.accept(rsOutputChannel, (byte) (active ? 15 : 0), this);
}
}
@Override
@ -151,16 +150,19 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
@SideOnly(CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, 0xff000000 | color);
}
private void setOut(boolean on) {
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsOutputChannel, 0);
}
private void setOut(boolean on, TileEntityPanel tile) {
active = on;
panel.markDirty();
panel.triggerRenderUpdate();
network.setOutputs(this, new RSChannelState(outputChannel, (byte)(active?15:0)));
tile.triggerRenderUpdate();
setOut(rsOutputChannel, active ? 15 : 0);
}
@Override
@ -195,12 +197,12 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
break;
case RS_CHANNEL:
if (id == 0) {
outputChannel = outputChannel.withColor(value);
rsOutputChannel = ((NBTTagByte) value).getByte();
}
break;
case INT:
if (id == 0) {
outputChannel = outputChannel.withController(value);
rsOutputId = ((NBTTagInt) value).getInt();
}
break;
case FLOAT:
@ -210,7 +212,6 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
@SideOnly(CLIENT)
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case BOOL:
@ -226,7 +227,6 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
@SideOnly(CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case BOOL:
@ -243,14 +243,13 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{new RSColorConfig("channel", 0, 0, outputChannel.getColor())};
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{new IntConfig("rsId", 0, 50,
outputChannel.getController(), 2, false)};
return new IntConfig[]{new IntConfig("rsId", 0, 50, rsOutputId, 2, false)};
}
@Override

View file

@ -1,27 +1,30 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannelState;
import malte0811.industrialwires.items.ItemKey;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.block.Block;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
@ -35,8 +38,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -45,16 +46,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static malte0811.industrialwires.util.NBTKeys.*;
public class Lock extends PanelComponent implements IConfigurableComponent {
private final static Random rand = new Random();
@Nullable
private NBTTagCompound keyNBT;
private boolean turned;
private boolean latching = false;
@Nonnull
private RSChannel outputChannel = RSChannel.DEFAULT_CHANNEL;
private int rsOutputId;
private int rsOutputChannel;
private int ticksTillOff;
private int lockID;
@ -65,10 +64,11 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
}
public Lock(boolean latching, @Nonnull RSChannel out) {
public Lock(boolean latching, int rsOutputId, int rsOutputChannel) {
this();
this.latching = latching;
outputChannel = out;
this.rsOutputChannel = rsOutputChannel;
this.rsOutputId = rsOutputId;
}
@Override
@ -82,8 +82,8 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
nbt.setInteger("lockId", lockID);
nbt.setBoolean(LATCHING, latching);
nbt.setByte(RS_CHANNEL, outputChannel.getColor());
nbt.setInteger(RS_ID, outputChannel.getController());
nbt.setInteger(RS_CHANNEL, rsOutputChannel);
nbt.setInteger(RS_ID, rsOutputId);
}
@Override
@ -99,20 +99,13 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
lockID = nbt.getInteger("lockId");
}
latching = nbt.getBoolean(LATCHING);
int rsController = nbt.getInteger(RS_CHANNEL);
byte rsColor = nbt.getByte(RS_ID);
outputChannel = new RSChannel(rsController, rsColor);
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
net.setOutputs(this, new RSChannelState(outputChannel, (byte) (turned?15:0)));
rsOutputChannel = nbt.getInteger(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
private final static float size = .0625F;
private final static float keyWidth = .125F * size;
private final static float yOffset = size / 2 + Y_DELTA;
private final static float yOffset = size / 2 + .0001F;
private final static float xOffset = (size - keyWidth) / 2;
private final static float[] DARK_GRAY = {.4F, .4F, .4F};
private final static int DARK_GRAY_INT = 0xFF686868;
@ -122,7 +115,6 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>(5);
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(0, 0, 0), new Vector3f(size, size / 2, size), ret, false);
@ -143,7 +135,6 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
return ret;
}
@SideOnly(Side.CLIENT)
private void addKey(List<RawQuad> out, Matrix4 mat) {
PanelUtils.addColoredBox(DARK_GRAY, DARK_GRAY, null, new Vector3f(xOffset, size / 2, zOffsetLowerKey), new Vector3f(keyWidth, keyOffset, size / 2), out, false, mat);
PanelUtils.addColoredBox(DARK_GRAY, DARK_GRAY, null, new Vector3f(xOffset, size / 2 + keyOffset, zOffset), new Vector3f(keyWidth, size, size - 2 * zOffset), out, false, mat);
@ -152,7 +143,7 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
@Override
@Nonnull
public PanelComponent copyOf() {
Lock ret = new Lock(latching, outputChannel);
Lock ret = new Lock(latching, rsOutputId, rsOutputChannel);
ret.turned = turned;
ret.lockID = lockID;
ret.keyNBT = keyNBT == null ? null : keyNBT.copy();
@ -173,7 +164,7 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
@Override
public void interactWith(Vec3d hitRel, EntityPlayerMP player) {
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
boolean update = false;
if (keyNBT == null) {
for (EnumHand hand : EnumHand.values()) {
@ -201,25 +192,32 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
}
if (update) {
setOut();
setOut(tile);
if (!latching && turned) {
ticksTillOff = 10;
}
}
panel.markDirty();
panel.triggerRenderUpdate();
tile.triggerRenderUpdate();
}
@Override
public void update() {
public void update(TileEntityPanel tile) {
if (!latching && ticksTillOff > 0) {
ticksTillOff--;
tile.markDirty();
if (ticksTillOff == 0) {
turned = false;
panel.triggerRenderUpdate();
setOut();
tile.triggerRenderUpdate();
setOut(tile);
}
panel.markDirty();
}
}
@Override
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
super.registerRSOutput(id, out);
out.accept(rsOutputChannel, (byte) (turned ? 15 : 0), this);
}
}
@ -229,7 +227,6 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, GRAY_INT);
AxisAlignedBB aabb = getBlockRelativeAABB();
@ -240,15 +237,21 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
Gui.drawRect(left, top, right, bottom, DARK_GRAY_INT);
}
private void setOut() {
network.setOutputs(this, new RSChannelState(outputChannel, (byte) (turned ? 15 : 0)));
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsOutputChannel, 0);
}
private void setOut(TileEntityPanel tile) {
tile.triggerRenderUpdate();
setOut(rsOutputChannel, turned ? 15 : 0);
}
@Override
public void dropItems() {
super.dropItems();
public void dropItems(TileEntityPanel te) {
super.dropItems(te);
if (keyNBT!=null) {
Block.spawnAsEntity(panel.getWorld(), panel.getBlockPos(), new ItemStack(keyNBT));
Block.spawnAsEntity(te.getWorld(), te.getPos(), new ItemStack(keyNBT));
}
}
@ -262,10 +265,11 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
if (turned != lock.turned) return false;
if (latching != lock.latching) return false;
if (rsOutputId != lock.rsOutputId) return false;
if (rsOutputChannel != lock.rsOutputChannel) return false;
if (ticksTillOff != lock.ticksTillOff) return false;
if (lockID != lock.lockID) return false;
if (keyNBT != null ? !keyNBT.equals(lock.keyNBT) : lock.keyNBT != null) return false;
return outputChannel.equals(lock.outputChannel);
return keyNBT != null ? keyNBT.equals(lock.keyNBT) : lock.keyNBT == null;
}
@Override
@ -274,7 +278,8 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
result = 31 * result + (keyNBT != null ? keyNBT.hashCode() : 0);
result = 31 * result + (turned ? 1 : 0);
result = 31 * result + (latching ? 1 : 0);
result = 31 * result + outputChannel.hashCode();
result = 31 * result + rsOutputId;
result = 31 * result + rsOutputChannel;
result = 31 * result + ticksTillOff;
result = 31 * result + lockID;
return result;
@ -283,28 +288,25 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case BOOL:
if (id == 0) {
latching = ((NBTTagByte) value).getByte() != 0;
}
break;
case RS_CHANNEL:
if (id == 0) {
byte rsColor = ((NBTTagByte) value).getByte();
outputChannel = new RSChannel(outputChannel.getController(), rsColor);
}
break;
case INT:
if (id == 0) {
int rsController = ((NBTTagInt) value).getInt();
outputChannel = new RSChannel(rsController, outputChannel.getColor());
}
break;
case BOOL:
if (id == 0) {
latching = ((NBTTagByte) value).getByte() != 0;
}
break;
case RS_CHANNEL:
if (id == 0) {
rsOutputChannel = ((NBTTagByte) value).getByte();
}
break;
case INT:
if (id == 0) {
rsOutputId = ((NBTTagInt) value).getInt();
}
break;
}
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case BOOL:
@ -318,7 +320,6 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case BOOL:
@ -333,13 +334,13 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{new RSColorConfig("channel", 0, 0, outputChannel.getColor())};
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{new IntConfig("rsId", 0, 50, outputChannel.getController(), 2, false)};
return new IntConfig[]{new IntConfig("rsId", 0, 50, rsOutputId, 2, false)};
}
@Override

View file

@ -1,19 +1,22 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
public enum MessageType {
ADD,

View file

@ -1,61 +1,69 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.IOwner;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.Level;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
public abstract class PanelComponent implements IOwner {
public static final float Y_DELTA = .001F;
protected static final float[] GRAY = {.8F, .8F, .8F};
protected static final int GRAY_INT = 0xFFD0D0D0;
protected static final float[] BLACK = {0, 0, 0, 1};
public abstract class PanelComponent {
protected float panelHeight;
protected AxisAlignedBB aabb = null;
protected float x, y;
private final String type;
protected TileEntityPanel panel;
protected ControlPanelNetwork network;
protected final static float[] GRAY = {.8F, .8F, .8F};
protected final static int GRAY_INT = 0xFFD0D0D0;
private Set<TriConsumer<Integer, Byte, PanelComponent>> outputs = new HashSet<>();
protected PanelComponent(String type) {
this.type = type;
}
public static final Map<String, Supplier<PanelComponent>> baseCreaters = new HashMap<>();
public final static String COLOR = "color";
public final static String RS_CHANNEL = "rsChannel";
public final static String RS_ID = "rsId";
public final static String TEXT = "text";
public static final String HORIZONTAL = "horizontal";
public static final String LENGTH = "length";
public static final String LATCHING = "latching";
public static void init() {
static {
baseCreaters.put("lighted_button", LightedButton::new);
baseCreaters.put("label", Label::new);
baseCreaters.put("indicator_light", IndicatorLight::new);
@ -65,21 +73,6 @@ public abstract class PanelComponent implements IOwner {
baseCreaters.put("toggle_switch_covered", CoveredToggleSwitch::new);
baseCreaters.put("lock", Lock::new);
baseCreaters.put("panel_meter", PanelMeter::new);
baseCreaters.put(SevenSegDisplay.NAME, SevenSegDisplay::new);
baseCreaters.put("rgb_led", RGBIndicator::new);
//Check that all components implement equals+hashCode if in a dev env
boolean isDevEnv = "NBTTagCompound".equals(NBTTagCompound.class.getSimpleName());
if (isDevEnv) {
for (Supplier<PanelComponent> sup:baseCreaters.values()) {
PanelComponent comp = sup.get();
try {
comp.getClass().getDeclaredMethod("equals", Object.class);
comp.getClass().getDeclaredMethod("hashCode");
} catch (NoSuchMethodException e) {
throw new RuntimeException(comp.getClass()+" lacks equals or hasCode! This will break the cache!", e);
}
}
}
}
protected abstract void writeCustomNBT(NBTTagCompound nbt, boolean toItem);
@ -87,7 +80,6 @@ public abstract class PanelComponent implements IOwner {
protected abstract void readCustomNBT(NBTTagCompound nbt);
// DON'T OFFSET BY x, y IN THIS METHOD!
@SideOnly(Side.CLIENT)
public abstract List<RawQuad> getQuads();
@Nonnull
@ -97,19 +89,29 @@ public abstract class PanelComponent implements IOwner {
@Nonnull
public abstract AxisAlignedBB getBlockRelativeAABB();
public abstract void interactWith(Vec3d hitRelative, EntityPlayerMP player);
public abstract void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player);
public abstract void update();
public abstract void update(TileEntityPanel tile);
public abstract int getColor();
public abstract float getHeight();
public void setNetwork(ControlPanelNetwork net) {
this.network = net;
@Nullable
public Consumer<byte[]> getRSInputHandler(int id, TileEntityPanel panel) {
return null;
}
public void dropItems() {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
outputs.add(out);
}
public void unregisterRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
outputs.remove(out);
}
public void dropItems(TileEntityPanel te) {
}
public void invalidate(TileEntityPanel te) {
}
public float getX() {
@ -120,6 +122,8 @@ public abstract class PanelComponent implements IOwner {
return y;
}
public abstract float getHeight();
public void setX(float x) {
this.x = x;
aabb = null;
@ -134,11 +138,6 @@ public abstract class PanelComponent implements IOwner {
this.panelHeight = panelHeight;
}
@Override
public BlockPos getBlockPos() {
return panel.getPos();
}
public void writeToNBT(NBTTagCompound nbt, boolean toItem) {
writeCustomNBT(nbt, toItem);
nbt.setFloat("x", getX());
@ -154,7 +153,7 @@ public abstract class PanelComponent implements IOwner {
ret.readFromNBT(nbt);
return ret;
} else {
IndustrialWires.logger.warn("Unknown panel component: " + type);
FMLLog.log(IndustrialWires.MODID, Level.WARN, "Unknown panel component: " + type);
return null;
}
}
@ -166,6 +165,36 @@ public abstract class PanelComponent implements IOwner {
setPanelHeight(nbt.getFloat("panelHeight"));
}
@SideOnly(Side.CLIENT)
public void renderBox(TileEntityPanel te) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.glLineWidth(2.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
te.getComponents().transformGLForTop(te.getPos());
RenderGlobal.drawSelectionBoundingBox(getBlockRelativeAABB().grow(0.002),
0.0F, 0.0F, 0.0F, 0.4F);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
public abstract void renderInGUI(GuiPanelCreator gui);
public void renderInGUIDefault(GuiPanelCreator gui, int color) {
color |= 0xff000000;
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) (gui.getX0() + aabb.minX * gui.panelSize);
int top = (int) (gui.getY0() + aabb.minZ * gui.panelSize);
int right = (int) (gui.getX0() + aabb.maxX * gui.panelSize);
int bottom = (int) (gui.getY0() + aabb.maxZ * gui.panelSize);
Gui.drawRect(left, top, right, bottom, color);
}
public boolean isValidPos(List<PanelComponent> components, float height, float angle) {
float h = PanelUtils.getHeightWithComponent(this, angle, height);
if (h < 0 || h > 1) {
@ -192,38 +221,12 @@ public abstract class PanelComponent implements IOwner {
return true;
}
@SideOnly(Side.CLIENT)
public void renderBox() {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.glLineWidth(2.0F);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
panel.getComponents().transformGLForTop(panel.getBlockPos());
RenderGlobal.drawSelectionBoundingBox(getBlockRelativeAABB().grow(0.002),
0.0F, 0.0F, 0.0F, 0.4F);
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
void setOut(int channel, int level) {
for (TriConsumer<Integer, Byte, PanelComponent> out : outputs) {
out.accept(channel, (byte) level, this);
}
}
@SideOnly(Side.CLIENT)
public abstract void renderInGUI(GuiPanelCreator gui);
@SideOnly(Side.CLIENT)
public void renderInGUIDefault(GuiPanelCreator gui, int color) {
color |= 0xff000000;
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) (gui.getX0() + aabb.minX * gui.panelSize);
int top = (int) (gui.getY0() + aabb.minZ * gui.panelSize);
int right = (int) (gui.getX0() + aabb.maxX * gui.panelSize);
int bottom = (int) (gui.getY0() + aabb.maxZ * gui.panelSize);
Gui.drawRect(left, top, right, bottom, color);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -245,8 +248,4 @@ public abstract class PanelComponent implements IOwner {
result = 31 * result + type.hashCode();
return result;
}
public void setPanel(TileEntityPanel tile) {
panel = tile;
}
}

View file

@ -1,27 +1,30 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.client.panelmodel.RawModelFontRenderer;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannelState;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.client.panelmodel.RawModelFontRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
@ -29,11 +32,10 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -42,33 +44,29 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import static malte0811.industrialwires.util.NBTKeys.*;
public class PanelMeter extends PanelComponent implements IConfigurableComponent {
@Nonnull
private RSChannel primary = RSChannel.DEFAULT_CHANNEL;
@Nonnull
private RSChannel secondary = RSChannel.INVALID_CHANNEL;
private int rsInput;
public static final String WIDE = "wide";
private int rsInputId;
private byte rsInputChannel;
private byte rsInput;
private boolean wide = true;
public PanelMeter() {
super("panel_meter");
}
public PanelMeter(@Nonnull RSChannel primary, @Nonnull RSChannel secondary, boolean wide) {
public PanelMeter(int rsId, byte rsChannel, boolean wide) {
this();
this.primary = primary;
this.secondary = secondary;
rsInputChannel = rsChannel;
rsInputId = rsId;
this.wide = wide;
}
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
nbt.setInteger(RS_ID, primary.getController());
nbt.setByte(RS_CHANNEL, primary.getColor());
nbt.setInteger(RS_ID2, secondary.getController());
nbt.setByte(RS_CHANNEL2, secondary.getColor());
nbt.setInteger(RS_ID, rsInputId);
nbt.setByte(RS_CHANNEL, rsInputChannel);
nbt.setBoolean(WIDE, wide);
if (!toItem) {
nbt.setInteger("rsInput", rsInput);
@ -77,44 +75,35 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
int rsController = nbt.getInteger(RS_ID);
byte rsColor = nbt.getByte(RS_CHANNEL);
primary = new RSChannel(rsController, rsColor);
rsInput = nbt.getInteger("rsInput");
rsInputId = nbt.getInteger(RS_ID);
rsInputChannel = nbt.getByte(RS_CHANNEL);
rsInput = nbt.getByte("rsInput");
wide = nbt.getBoolean(WIDE);
if (nbt.hasKey(RS_ID2)) {
rsController = nbt.getInteger(RS_ID2);
rsColor = nbt.getByte(RS_CHANNEL2);
secondary = new RSChannel(rsController, rsColor);
} else {
secondary = RSChannel.INVALID_CHANNEL;
}
}
private static final float SIZE = .25F;
private static final float WIDTH = 1.5F*SIZE;
private static final float BORDER = SIZE /20;
private static final float antiZOffset = .0001F;
private static final float[] BLACK = {0, 0, 0, 1};
private static final float[] WHITE = {1, 1, 1, 1};
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
float width = wide?WIDTH:SIZE;
//main panel
PanelUtils.addColoredQuad(ret, new Vector3f(), new Vector3f(0, 0, SIZE), new Vector3f(width, 0, SIZE),
new Vector3f(width, 0, 0), EnumFacing.UP, BLACK);
PanelUtils.addColoredQuad(ret, new Vector3f(BORDER, Y_DELTA, BORDER), new Vector3f(BORDER, Y_DELTA, SIZE-BORDER),
new Vector3f(width-BORDER, Y_DELTA, SIZE-BORDER), new Vector3f(width-BORDER, Y_DELTA, BORDER), EnumFacing.UP, WHITE);
PanelUtils.addColoredQuad(ret, new Vector3f(BORDER, antiZOffset, BORDER), new Vector3f(BORDER, antiZOffset, SIZE-BORDER),
new Vector3f(width-BORDER, antiZOffset, SIZE-BORDER), new Vector3f(width-BORDER, antiZOffset, BORDER), EnumFacing.UP, WHITE);
RawModelFontRenderer r = RawModelFontRenderer.get();
r.setScale(.5F);
RawModelFontRenderer r = fontRenderer();
r.transform = new Matrix4();
for (int i = 0;i<=3;i++) {
transformNumber(r.transform, 5*17*i);
transformNumber(r.transform, (byte)(5*i));
String asString = Integer.toString(5*i);
int lengthHalf = r.getStringWidth(asString)/2;
r.transform.translate(-lengthHalf*r.getScale(), 0, -3.5*r.getScale());
r.transform.translate(-lengthHalf*r.scale, 0, -3.5*r.scale);
r.drawString(asString, 0, 0, 0xff000000);
ret.addAll(r.build());
}
@ -128,30 +117,39 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
return ret;
}
private void transformNumber(Matrix4 mat, int value) {
private RawModelFontRenderer renderer;
private RawModelFontRenderer fontRenderer() {
if (renderer == null) {
renderer = new RawModelFontRenderer(Minecraft.getMinecraft().gameSettings, Label.FONT, Minecraft.getMinecraft().getTextureManager(),
false, .5F);
}
return renderer;
}
private void transformNumber(Matrix4 mat, byte value) {
if (wide) {
transformNeedle(mat, value);
mat.translate(0, 0, getLength()+1.5*BORDER);
mat.scale(-1, 1, -1);
} else {
mat.setIdentity().translate(0, Y_DELTA, SIZE);
mat.setIdentity().translate(0, antiZOffset, SIZE);
mat.translate(SIZE-3*BORDER, 0, -3*BORDER);
float angle = 90*(1-value/255F);
float angle = 90*(1-value/15F);
angle = (float) (angle*Math.PI/180);
float length = getLength()+BORDER;
mat.translate((float)(-Math.sin(angle)*length), 0, (float)(-Math.cos(angle)*length));
}
}
private void transformNeedle(Matrix4 mat, int value) {
mat.setIdentity().translate(0, 2*Y_DELTA, SIZE);
private void transformNeedle(Matrix4 mat, byte value) {
mat.setIdentity().translate(0, 2*antiZOffset, SIZE);
float angle;
if (wide) {
mat.translate(WIDTH/2, 0, -2*BORDER);
angle = 50-(100*(value/255F));
angle = 50-(100*(value/15F));
} else {
mat.translate(SIZE-3*BORDER, 0, -3*BORDER);
angle = 90-(90*(value/255F));
angle = 90-(90*(value/15F));
}
angle = (float) ((180+angle)*Math.PI/180);
mat.rotate(angle, 0, 1, 0);
@ -163,7 +161,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
@Nonnull
@Override
public PanelComponent copyOf() {
PanelMeter ret = new PanelMeter(primary, secondary, wide);
PanelMeter ret = new PanelMeter(rsInputId, rsInputChannel, wide);
ret.rsInput = rsInput;
ret.setX(x);
ret.setY(y);
@ -181,40 +179,30 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
}
@Override
public void interactWith(Vec3d hitRelative, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
}
@Override
public void update() {
public void update(TileEntityPanel tile) {
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
Consumer<RSChannelState> listenerPrimary = (input) -> {
byte strength = input.getStrength();
if (strength != rsInput >> 4) {
if (secondary.isValid()) {
rsInput = (strength << 4) | (rsInput & 0xf);
} else {
rsInput = strength * 17;
}
panel.markDirty();
panel.triggerRenderUpdate();
}
};
net.addListener(this, listenerPrimary, primary);
if (secondary.isValid()) {
Consumer<RSChannelState> listenerSec = (input) -> {
if (input.getStrength() != (rsInput & 0xf)) {
rsInput = (input.getStrength() & 0xf) | (rsInput & 0xf0);
panel.markDirty();
panel.triggerRenderUpdate();
}
};
net.addListener(this, listenerSec, secondary);
private TileEntityPanel panel;
private Consumer<byte[]> handler = (input) -> {
if (input[rsInputChannel] != rsInput) {
rsInput = input[rsInputChannel];
panel.triggerRenderUpdate();
}
};
@Nullable
@Override
public Consumer<byte[]> getRSInputHandler(int id, TileEntityPanel panel) {
if (id == rsInputId) {
this.panel = panel;
return handler;
}
return null;
}
@Override
@ -230,24 +218,23 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
PanelMeter that = (PanelMeter) o;
if (rsInputId != that.rsInputId) return false;
if (rsInputChannel != that.rsInputChannel) return false;
if (rsInput != that.rsInput) return false;
if (wide != that.wide) return false;
if (!primary.equals(that.primary)) return false;
return secondary.equals(that.secondary);
return wide == that.wide;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + primary.hashCode();
result = 31 * result + secondary.hashCode();
result = 31 * result + rsInput;
result = 31 * result + rsInputId;
result = 31 * result + (int) rsInputChannel;
result = 31 * result + (int) rsInput;
result = 31 * result + (wide ? 1 : 0);
return result;
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, 0);
AxisAlignedBB aabb = getBlockRelativeAABB();
@ -259,6 +246,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
GlStateManager.pushMatrix();
int border = (int) Math.ceil(BORDER*gui.panelSize);
int width = right-left;
int height = bottom-top;
if (wide) {
GlStateManager.translate(left+width/2D, bottom-2*border, 0);
GlStateManager.rotate(135, 0, 0, 1);
@ -277,28 +265,19 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
if (id == 0) {
primary = primary.withColor(value);
} else {
secondary = secondary.withColor(value);
}
break;
case INT:
if (id == 0) {
primary = primary.withController(value);
} else {
secondary = secondary.withController(value);
}
break;
case BOOL:
wide = ((NBTTagByte) value).getByte() != 0;
case RS_CHANNEL:
rsInputChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsInputId = ((NBTTagInt) value).getInt();
break;
case BOOL:
wide = ((NBTTagByte)value).getByte()!=0;
}
}
@Nullable
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
@ -314,40 +293,37 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
@Nullable
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case FLOAT:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info"+(id==1?"2":""));
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info"+(id==1?"2":""));
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
default:
return null;
}
}
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{
new RSColorConfig("channel", 0, 0, primary.getColor(), false),
new RSColorConfig("channel2", 60, 0, secondary.getColor(), false)
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsInputChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 60, primary.getController(), 2, false),
new IntConfig("rsId2", 60, 60, secondary.getController(), 2, true)
new IntConfig("rsId", 0, 45, rsInputId, 2, false)
};
}
@Override
public BoolConfig[] getBooleanOptions() {
return new BoolConfig[]{
new BoolConfig("wide", 0, 80, wide)
new BoolConfig("wide", 70, 10, wide)
};
}

View file

@ -1,32 +1,36 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialwires.client.ClientUtilsIW;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.controlpanel.PropertyComponents.PanelRenderProperties;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.BlockPanel;
import malte0811.industrialWires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.panelmodel.SmartLightingQuadIW;
import malte0811.industrialWires.controlpanel.PropertyComponents.PanelRenderProperties;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.EnumDyeColor;
@ -38,7 +42,9 @@ import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.obj.OBJModel;
import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
@ -50,12 +56,14 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiPredicate;
import static malte0811.industrialwires.util.NBTKeys.*;
import static malte0811.industrialWires.controlpanel.PanelComponent.*;
import static malte0811.industrialWires.util.MiscUtils.discoverLocal;
public final class PanelUtils {
public static TextureAtlasSprite PANEL_TEXTURE;
public static Item PANEL_ITEM;
public static final Item PANEL_ITEM = new ItemStack(IndustrialWires.panel).getItem();
private static ItemStack panelBase;
private PanelUtils() {
@ -64,16 +72,8 @@ public final class PanelUtils {
@SideOnly(Side.CLIENT)
public static List<BakedQuad> generateQuads(PanelRenderProperties components) {
if (PANEL_TEXTURE == null) {
TextureMap texMap = Minecraft.getMinecraft().getTextureMapBlocks();
PANEL_TEXTURE = texMap.getAtlasSprite(IndustrialWires.MODID + ":blocks/control_panel");
PANEL_TEXTURE = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(IndustrialWires.MODID + ":blocks/control_panel");
}
ItemStack source = components.getTextureSource();
IBakedModel texModel = null;
if (IndustrialWires.proxy.isValidTextureSource(source)) {
texModel = Minecraft.getMinecraft().getRenderItem().getItemModelWithOverrides(source,
null, null);
}
final TextureAtlasSprite mainTex = texModel != null ? texModel.getParticleTexture() : PANEL_TEXTURE;
List<BakedQuad> ret = new ArrayList<>();
Matrix4 m4 = components.getPanelTopTransform();
Matrix4 m4RotOnly = m4.copy();
@ -83,10 +83,10 @@ public final class PanelUtils {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < components.size(); i++) {
PanelComponent pc = components.get(i);
Matrix4 m4Here = m4.copy().translate(pc.getX(), PanelComponent.Y_DELTA, pc.getY());
Matrix4 m4Here = m4.copy().translate(pc.getX(), .0001, pc.getY());
List<RawQuad> compQuads = pc.getQuads();
for (RawQuad bq : compQuads) {
ret.add(ClientUtilsIW.bakeQuad(bq, m4Here, m4RotOnly));
ret.add(bakeQuad(bq, m4Here, m4RotOnly));
}
}
Matrix4 baseTrans = components.getPanelBaseTransform();
@ -99,56 +99,64 @@ public final class PanelUtils {
float height0 = getLocalHeightFromZ(0, components.getHeight(), components.getAngle());
float vMax1 = 16 * height1;
float vMax0 = 16 * height0;
float xMin = 0;
float xMax = 1;
float zMin = 0;
float zMax = 1;
if (components instanceof PropertyComponents.AABBPanelProperties) {
AxisAlignedBB xzAABB = ((PropertyComponents.AABBPanelProperties) components).getPanelBoundingBox();
xMin = (float) xzAABB.minX;
zMin = (float) xzAABB.minZ;
xMax = (float) xzAABB.maxX;
zMax = (float) xzAABB.maxZ;
}
float uMaxX = 16*(xMax-xMin);
float uMaxZ = 16*(zMax-zMin);
//TOP
rawOut.add(new RawQuad(new Vector3f(xMin, height0, zMin), new Vector3f(xMin, height1, zMax),
new Vector3f(xMax, height1, zMax), new Vector3f(xMax, height0, zMin),
EnumFacing.UP, mainTex, WHITE, null, new float[]{0, 0, uMaxX, uMaxZ}, -1));
rawOut.add(new RawQuad(new Vector3f(0, height0, 0), new Vector3f(0, height1, 1),
new Vector3f(1, height1, 1), new Vector3f(1, height0, 0),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, UV_FULL, -1));
//BOTTOM
rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMin), new Vector3f(xMax, 0, zMin),
new Vector3f(xMax, 0, zMax), new Vector3f(xMin, 0, zMax),
EnumFacing.DOWN, mainTex, WHITE, null, UV_FULL, -1));
rawOut.add(new RawQuad(new Vector3f(0, 0, 0), new Vector3f(1, 0, 0),
new Vector3f(1, 0, 1), new Vector3f(0, 0, 1),
EnumFacing.DOWN, PANEL_TEXTURE, WHITE, null, UV_FULL, -1));
//LEFT
rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMin), new Vector3f(xMin, 0, zMax),
new Vector3f(xMin, height1, zMax), new Vector3f(xMin, height0, zMin),
EnumFacing.UP, mainTex, WHITE, null, new float[][]{
{0, 0}, {0, uMaxZ},
{vMax1, uMaxZ}, {vMax0, 0}
rawOut.add(new RawQuad(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1),
new Vector3f(0, height1, 1), new Vector3f(0, height0, 0),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[][]{
{0, 0}, {0, 16},
{vMax1, 16}, {vMax0, 0}
}, -1));
//RIGHT
rawOut.add(new RawQuad(new Vector3f(xMax, 0, zMin), new Vector3f(xMax, height0, zMin),
new Vector3f(xMax, height1, zMax), new Vector3f(xMax, 0, zMax),
EnumFacing.UP, mainTex, WHITE, null, new float[][]{
rawOut.add(new RawQuad(new Vector3f(1, 0, 0), new Vector3f(1, height0, 0),
new Vector3f(1, height1, 1), new Vector3f(1, 0, 1),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[][]{
{0, 0}, {vMax0, 0},
{vMax1, uMaxZ}, {0, uMaxZ}
{vMax1, 16}, {0, 16}
}, -1));
//BACK
rawOut.add(new RawQuad(new Vector3f(xMax, 0, zMin), new Vector3f(xMin, 0, zMin),
new Vector3f(xMin, height0, zMin), new Vector3f(xMax, height0, zMin),
EnumFacing.UP, mainTex, WHITE, null, new float[]{0, 0, vMax0, uMaxX}, -1));
rawOut.add(new RawQuad(new Vector3f(1, 0, 0), new Vector3f(0, 0, 0),
new Vector3f(0, height0, 0), new Vector3f(1, height0, 0),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMax0, 16}, -1));
//FRONT
rawOut.add(new RawQuad(new Vector3f(xMin, 0, zMax), new Vector3f(xMax, 0, zMax),
new Vector3f(xMax, height1, zMax), new Vector3f(xMin, height1, zMax),
EnumFacing.UP, mainTex, WHITE, null, new float[]{0, 0, vMax1, uMaxX}, -1));
rawOut.add(new RawQuad(new Vector3f(0, 0, 1), new Vector3f(1, 0, 1),
new Vector3f(1, height1, 1), new Vector3f(0, height1, 1),
EnumFacing.UP, PANEL_TEXTURE, WHITE, null, new float[]{0, 0, vMax1, 16}, -1));
for (RawQuad bq : rawOut) {
ret.add(ClientUtilsIW.bakeQuad(bq, baseTrans, baseNorm));
ret.add(bakeQuad(bq, baseTrans, baseNorm));
}
return ret;
}
@SideOnly(Side.CLIENT)
public static BakedQuad bakeQuad(RawQuad raw, Matrix4 transform, Matrix4 transfNormal) {
VertexFormat format = DefaultVertexFormats.ITEM;
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
builder.setQuadOrientation(raw.facing);
builder.setTexture(raw.tex);
Vector3f[] vertices = raw.vertices;
float[][] uvs = raw.uvs;
Vector3f normal = transfNormal.apply(raw.normal);
OBJModel.Normal faceNormal = new OBJModel.Normal(normal.x, normal.y, normal.z);
for (int i = 0; i < 4; i++) {
putVertexData(format, builder, transform.apply(vertices[i]), faceNormal, uvs[i][0], uvs[i][1], raw.tex,
raw.colorA);
}
BakedQuad ret = builder.build();
if (raw.light>0) {
ret = new SmartLightingQuadIW(ret, raw.light);
}
return ret;
}
//mostly copied from IE's ClientUtils, it has protected access there...
@SideOnly(Side.CLIENT)
public static void putVertexData(VertexFormat format, UnpackedBakedQuad.Builder builder, Vector3f pos, OBJModel.Normal faceNormal, double u, double v, TextureAtlasSprite sprite, float[] colorA) {
@ -254,58 +262,57 @@ public final class PanelUtils {
}
}
@SideOnly(Side.CLIENT)
public static void addInfo(ItemStack stack, List<String> list, NBTTagCompound data) {
switch (stack.getMetadata()) {
case 0: //button
addCommonInfo(data, list, true, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 1: //label
if (data.hasKey(TEXT)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.text", data.getString(TEXT)));
}
addCommonInfo(data, list, true, false);
break;
case 2: //indicator light
addCommonInfo(data, list, true, true);
break;
case 3: //slider
addCommonInfo(data, list, true, true);
if (data.hasKey(HORIZONTAL)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(HORIZONTAL) ? "horizontal" : "vertical")));
}
if (data.hasKey(LENGTH)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.length", data.getFloat(LENGTH)));
}
break;
case 4://variac
addCommonInfo(data, list, false, true);
break;
case 5://Toggle switch
addCommonInfo(data, list, false, true);
break;
case 6://Covered toggle switch
addCommonInfo(data, list, true, true);
break;
case 7://Lock
addCommonInfo(data, list, false, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 8://Panel meter
addCommonInfo(data, list, false, true);
if (data.hasKey(WIDE)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(WIDE) ? "wide" : "narrow")));
}
break;
case 0: //button
addCommonInfo(data, list, true, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 1: //label
if (data.hasKey(TEXT)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.text", data.getString(TEXT)));
}
addCommonInfo(data, list, true, false);
break;
case 2: //indicator light
addCommonInfo(data, list, true, true);
break;
case 3: //slider
addCommonInfo(data, list, true, true);
if (data.hasKey(HORIZONTAL)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(HORIZONTAL) ? "horizontal" : "vertical")));
}
if (data.hasKey(LENGTH)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.length", data.getFloat(LENGTH)));
}
break;
case 4://variac
addCommonInfo(data, list, false, true);
break;
case 5://Toggle switch
addCommonInfo(data, list, false, true);
break;
case 6://Covered toggle switch
addCommonInfo(data, list, true, true);
break;
case 7://Lock
addCommonInfo(data, list, false, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 8://Panel meter
addCommonInfo(data, list, false, true);
if (data.hasKey(PanelMeter.WIDE)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(PanelMeter.WIDE) ? "wide" : "narrow")));
}
break;
}
}
@SideOnly(Side.CLIENT)
public static void addCommonInfo(NBTTagCompound data, List<String> list, boolean color, boolean rs) {
if (color && data.hasKey(COLOR)) {
String hexCol = String.format("%6s", Integer.toHexString(data.getInteger(COLOR) & 0xffffff)).replace(' ', '0');
@ -313,8 +320,8 @@ public final class PanelUtils {
}
if (rs && data.hasKey(RS_CHANNEL)) {
EnumDyeColor channColor = EnumDyeColor.byMetadata(data.getInteger(RS_CHANNEL));
String hexCol = Integer.toHexString(channColor.getColorValue());
list.add(I18n.format("desc.immersiveengineering.info.redstoneChannel", "<hexcol=" + hexCol + ":" + channColor.getTranslationKey() + ">"));
String hexCol = Integer.toHexString(channColor.getMapColor().colorValue);
list.add(I18n.format("desc.immersiveengineering.info.redstoneChannel", "<hexcol=" + hexCol + ":" + channColor.getUnlocalizedName() + ">"));
}
if (rs && data.hasKey(RS_ID)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.rsId", data.getInteger(RS_ID)));
@ -371,6 +378,27 @@ public final class PanelUtils {
return panelBase;
}
public static List<BlockPos> discoverPanelParts(World w, BlockPos here, int maxCount) {
BiPredicate<BlockPos, Integer> isValid = (pos, count) -> {
if (pos.equals(here)) {
return true;
}
if (here.distanceSq(pos) > 25 || count > maxCount || !w.isBlockLoaded(pos)) {
return false;
}
IBlockState state = w.getBlockState(pos);
return state.getBlock() == IndustrialWires.panel && state.getValue(BlockPanel.type).isPanelConnector();
};
List<BlockPos> all = discoverLocal(w, here, isValid);
List<BlockPos> ret = new ArrayList<>();
for (BlockPos pos : all) {
if (w.getBlockState(pos).getBlock() == IndustrialWires.panel && w.getBlockState(pos).getValue(BlockPanel.type) != BlockTypes_Panel.DUMMY) {
ret.add(pos);
}
}
return ret;
}
public static float getAngle(ItemStack inv) {
float angle = 0;
NBTTagCompound nbt = inv.getTagCompound();

View file

@ -1,32 +1,28 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -66,7 +62,6 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
private Matrix4 topTransform;
private Matrix4 topTransformInverse;
private Matrix4 baseTransform;
private ItemStack textureSource = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.DUMMY.ordinal());
public PanelRenderProperties() {
@ -92,7 +87,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
@Nonnull
public Matrix4 getPanelTopTransform() {
if (topTransform == null) {
topTransform = getPanelBaseTransform().copy().translate(0, getHeight(), .5)
topTransform = getPanelBaseTransform().copy().translate(0, height, .5)
.rotate(angle, 1, 0, 0).translate(0, 0, -.5);
}
return topTransform;
@ -130,7 +125,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
GlStateManager.rotate(top.getHorizontalAngle(), 0, 0, 1);
break;
}
GlStateManager.translate(-.5, getHeight() - .5, 0);
GlStateManager.translate(-.5, height - .5, 0);
GlStateManager.rotate((float) (angle * 180 / Math.PI), 1, 0, 0);
GlStateManager.translate(0, 0, -.5);
@ -163,7 +158,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
public float getMaxHeight() {
float max = getPanelMaxHeight();
for (PanelComponent pc : this) {
float h = PanelUtils.getHeightWithComponent(pc, angle, getHeight());
float h = PanelUtils.getHeightWithComponent(pc, angle, height);
if (h > max) {
max = h;
}
@ -179,13 +174,11 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
ret.facing = facing;
ret.top = top;
ret.angle = angle;
ret.height = height;
ret.textureSource = textureSource;
return ret;
}
public float getPanelMaxHeight() {
return (float) (getHeight() + Math.abs(Math.tan(angle) / 2));
return (float) (height + Math.abs(Math.tan(angle) / 2));
}
private void resetMatrixes() {
@ -205,14 +198,6 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
}
}
public void setTextureSource(ItemStack textureSource) {
if (textureSource.getItem() instanceof ItemBlock)
this.textureSource = textureSource;
}
public ItemStack getTextureSource() {
return textureSource;
}
public float getHeight() {
return height;
@ -258,8 +243,7 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
if (Float.compare(that.height, height) != 0) return false;
if (Float.compare(that.angle, angle) != 0) return false;
if (facing != that.facing) return false;
if (top != that.top) return false;
return ItemStack.areItemStacksEqual(textureSource, that.textureSource);
return top == that.top;
}
@Override
@ -272,54 +256,4 @@ public class PropertyComponents implements IUnlistedProperty<PropertyComponents.
return result;
}
}
public static class AABBPanelProperties extends PanelRenderProperties {
private AxisAlignedBB aabb;
private int lastHash;
public AABBPanelProperties() {
super(1);
}
public AxisAlignedBB getPanelBoundingBox() {
if (size()<1) {
aabb = Block.FULL_BLOCK_AABB;
} else if (aabb!=null||get(0).hashCode()!=lastHash) {
aabb = getPanelBoundingBox(get(0));
lastHash = get(0).hashCode();
}
return aabb;
}
@Override
public PanelComponent set(int index, PanelComponent pc) {
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
pc.setX((float) ((1-aabb.maxX+aabb.minX)/2));
pc.setY((float) ((1-aabb.maxZ+aabb.minZ)/2));
return super.set(index, pc);
}
@Override
public boolean add(PanelComponent pc) {
AxisAlignedBB aabb = pc.getBlockRelativeAABB();
pc.setX((float) ((1-aabb.maxX+aabb.minX)/2));
pc.setY((float) ((1-aabb.maxZ+aabb.minZ)/2));
return super.add(pc);
}
private AxisAlignedBB getPanelBoundingBox(PanelComponent element) {
AxisAlignedBB compAABB = element.getBlockRelativeAABB();
float height = 6/16F;
double width = 3*(compAABB.maxX-compAABB.minX);
double length = 3*(compAABB.maxZ-compAABB.minZ);
width = MathHelper.clamp(width, 7/16F, 1);
length = MathHelper.clamp(length, 7/16F, 1);
double minX = (1-width)/2;
double minZ = (1-length)/2;
return new AxisAlignedBB(minX, 0, minZ, minX+width, height, minZ+length);
}
@Override
public float getHeight() {
return (float) getPanelBoundingBox().maxY;
}
}
}

View file

@ -1,63 +1,57 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannelState;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.*;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.*;
public class Slider extends PanelComponent implements IConfigurableComponent {
private static final float WIDTH = .0625F;
private float length = .5F;
private int color = 0xffff00;
private boolean horizontal;
private int out;
@Nonnull
private RSChannel primary = RSChannel.DEFAULT_CHANNEL;
@Nonnull
private RSChannel secondary = RSChannel.INVALID_CHANNEL;
private byte out;
private byte rsChannel;
private int rsId;
public Slider(float length, int color, boolean horizontal, @Nonnull RSChannel primary, @Nonnull RSChannel secondary) {
public Slider(float length, int color, boolean horizontal, int rsId, byte rsChannel) {
this();
this.color = color;
this.length = length;
this.horizontal = horizontal;
this.primary = primary;
this.secondary = secondary;
this.rsChannel = rsChannel;
this.rsId = rsId;
}
public Slider() {
@ -69,12 +63,10 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
nbt.setInteger(COLOR, color);
nbt.setFloat(LENGTH, length);
if (!toItem) {
nbt.setInteger("output", out);
nbt.setByte("output", out);
}
nbt.setInteger(RS_ID, primary.getController());
nbt.setByte(RS_CHANNEL, primary.getColor());
nbt.setInteger(RS_ID2, secondary.getController());
nbt.setByte(RS_CHANNEL2, secondary.getColor());
nbt.setByte(RS_CHANNEL, rsChannel);
nbt.setInteger(RS_ID, rsId);
nbt.setBoolean(HORIZONTAL, horizontal);
}
@ -82,38 +74,30 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
protected void readCustomNBT(NBTTagCompound nbt) {
color = nbt.getInteger(COLOR);
length = nbt.getFloat(LENGTH);
out = nbt.getByte("output");
rsChannel = nbt.getByte(RS_CHANNEL);
rsId = nbt.getInteger(RS_ID);
horizontal = nbt.getBoolean(HORIZONTAL);
out = nbt.getInteger("output");
int rsController = nbt.getInteger(RS_ID);
byte rsColor = nbt.getByte(RS_CHANNEL);
primary = new RSChannel(rsController, rsColor);
if (nbt.hasKey(RS_ID2)) {
rsController = nbt.getInteger(RS_ID2);
rsColor = nbt.getByte(RS_CHANNEL2);
secondary = new RSChannel(rsController, rsColor);
} else {
secondary = RSChannel.INVALID_CHANNEL;
}
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
final float yOff = .001F;
float xSize = horizontal ? length : WIDTH;
float ySize = horizontal ? WIDTH : length;
PanelUtils.addColoredQuad(ret, new Vector3f(0, 0, 0), new Vector3f(0, 0, ySize), new Vector3f(xSize, 0, ySize),
new Vector3f(xSize, 0, 0), EnumFacing.UP, GRAY);
PanelUtils.addColoredQuad(ret, new Vector3f(0, yOff, 0), new Vector3f(0, yOff, ySize), new Vector3f(xSize, yOff, ySize), new Vector3f(xSize, yOff, 0),
EnumFacing.UP, GRAY);
float[] color = new float[4];
color[3] = 1;
for (int i = 0; i < 3; i++) {
color[i] = ((this.color >> (8 * (2 - i))) & 255) / 255F * (.5F + out / 255F/2);
color[i] = ((this.color >> (8 * (2 - i))) & 255) / 255F * (.5F + out / 30F);
}
float val;
if (horizontal) {
val = (out / 255F) * (length - .0625F);
val = (out / 15F) * (length - .0625F);
} else {
val = (1 - out / 255F) * (length - .0625F);
val = (1 - out / 15F) * (length - .0625F);
}
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(horizontal ? val : 0, 0, horizontal ? 0 : val),
new Vector3f(.0625F, getHeight(), .0625F), ret, false);
@ -126,7 +110,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Nonnull
@Override
public PanelComponent copyOf() {
Slider ret = new Slider(length, color, horizontal, primary, secondary);
Slider ret = new Slider(length, color, horizontal, rsId, rsChannel);
ret.out = out;
ret.setX(x);
ret.setY(y);
@ -144,24 +128,27 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
public void interactWith(Vec3d hitRelative, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double pos = horizontal ? hitRelative.x : (length - hitRelative.z);
int newLevel = (int) Math.min(pos * 256 / length, 255);
byte newLevel = (byte) (Math.min(pos * 16 / length, 15));
if (newLevel != out) {
setOut(newLevel);
setOut(rsChannel, newLevel);
out = newLevel;
tile.triggerRenderUpdate();
}
}
@Override
public void update() {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsId) {
super.registerRSOutput(id, out);
out.accept((int) rsChannel, this.out, this);
}
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
network.setOutputs(this, new RSChannelState(primary, (byte) (out>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (out&0xf)));
public void update(TileEntityPanel tile) {
}
@Override
@ -170,7 +157,6 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, GRAY_INT);
double middleX = (getX() + (horizontal ? length : .0625) / 2);
@ -182,12 +168,9 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
Gui.drawRect(left, top, right, bottom, 0xff000000 | color);
}
public void setOut(int value) {
network.setOutputs(this, new RSChannelState(primary, (byte) (value>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (value&0xf)));
out = value;
panel.markDirty();
panel.triggerRenderUpdate();
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsChannel, 0);
}
@Override
@ -202,8 +185,8 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
if (color != slider.color) return false;
if (horizontal != slider.horizontal) return false;
if (out != slider.out) return false;
if (!primary.equals(slider.primary)) return false;
return secondary.equals(slider.secondary);
if (rsChannel != slider.rsChannel) return false;
return rsId == slider.rsId;
}
@Override
@ -212,39 +195,31 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
result = 31 * result + (length != +0.0f ? Float.floatToIntBits(length) : 0);
result = 31 * result + color;
result = 31 * result + (horizontal ? 1 : 0);
result = 31 * result + out;
result = 31 * result + primary.hashCode();
result = 31 * result + secondary.hashCode();
result = 31 * result + (int) out;
result = 31 * result + (int) rsChannel;
result = 31 * result + rsId;
return result;
}
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case BOOL:
horizontal = ((NBTTagByte) value).getByte() != 0;
break;
case RS_CHANNEL:
if (id == 0) {
primary = primary.withColor(value);
} else {
secondary = secondary.withColor(value);
}
break;
case INT:
if (id == 0) {
primary = primary.withController(value);
} else {
secondary = secondary.withController(value);
}
break;
case FLOAT:
if (id < 3) {
color = PanelUtils.setColor(color, id, value);
} else {
length = scaleToRangePercent(((NBTTagFloat) value).getFloat(), .125F, 1);
}
break;
case BOOL:
horizontal = ((NBTTagByte) value).getByte() != 0;
break;
case RS_CHANNEL:
rsChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsId = ((NBTTagInt) value).getInt();
break;
case FLOAT:
if (id < 3) {
color = PanelUtils.setColor(color, id, value);
} else {
length = scaleToRangePercent(((NBTTagFloat) value).getFloat(), .125F, 1);
}
break;
}
}
@ -253,7 +228,6 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case BOOL:
@ -269,15 +243,14 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case BOOL:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info"+(id==0?"":"2"));
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info"+(id==0?"":"2"));
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
case FLOAT:
return null;
default:
@ -286,25 +259,23 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{
new RSColorConfig("channel", 0, 0, primary.getColor(), true),
new RSColorConfig("channel2", 30, 0, secondary.getColor(), true)
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 30, primary.getController(), 2, false),
new IntConfig("rsId2", 30, 30, secondary.getController(), 2, true)
new IntConfig("rsId", 0, 50, rsId, 2, false)
};
}
@Override
public BoolConfig[] getBooleanOptions() {
return new BoolConfig[]{
new BoolConfig("horizontal", 0, 40, horizontal)
new BoolConfig("horizontal", 0, 70, horizontal)
};
}

View file

@ -1,62 +1,63 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannelState;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.RS_CHANNEL;
import static malte0811.industrialwires.util.NBTKeys.RS_ID;
public class ToggleSwitch extends PanelComponent implements IConfigurableComponent {
protected boolean active;
@Nonnull
protected RSChannel outputChannel = RSChannel.DEFAULT_CHANNEL;
public boolean active;
public int rsOutputId;
public byte rsOutputChannel;
public ToggleSwitch() {
super("toggle_switch");
}
protected ToggleSwitch(String name) {
public ToggleSwitch(String name) {
super(name);
}
public ToggleSwitch(boolean active, @Nonnull RSChannel outputChannel) {
public ToggleSwitch(boolean active, int rsOutputId, byte rsOutputChannel) {
this();
this.active = active;
this.outputChannel = outputChannel;
this.rsOutputChannel = rsOutputChannel;
this.rsOutputId = rsOutputId;
}
@Override
@ -64,37 +65,30 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
if (!toItem) {
nbt.setBoolean("active", active);
}
nbt.setByte(RS_CHANNEL, outputChannel.getColor());
nbt.setInteger(RS_ID, outputChannel.getController());
nbt.setByte(RS_CHANNEL, rsOutputChannel);
nbt.setInteger(RS_ID, rsOutputId);
}
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
active = nbt.getBoolean("active");
int rsController = nbt.getInteger(RS_ID);
byte rsColor = nbt.getByte(RS_CHANNEL);
outputChannel = new RSChannel(rsController, rsColor);
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
network.setOutputs(this, new RSChannelState(outputChannel, (byte) (active ? 15 : 0)));
rsOutputChannel = nbt.getByte(RS_CHANNEL);
rsOutputId = nbt.getInteger(RS_ID);
}
protected float sizeX = .0625F;
protected float sizeY = 1.5F * sizeX;
protected float rodRadius = sizeX * .25F;
protected float rodLength = 3 / 32F;
protected float yOffset = .0001F;
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, 0, (sizeY - sizeX) / 2),
new Vector3f(0, 0, (sizeY - sizeX) / 2),
new Vector3f(0, 0, (sizeY + sizeX) / 2),
new Vector3f(sizeX, 0, (sizeY + sizeX) / 2), EnumFacing.UP, GRAY);
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY + sizeX) / 2),
new Vector3f(sizeX, yOffset, (sizeY + sizeX) / 2), EnumFacing.UP, GRAY);
Matrix4 rot = new Matrix4();
rot.translate((sizeX) / 2, -.01F, sizeY / 2);
rot.rotate(Math.PI * 1 / 16 * (active ? -1 : 1), 1, 0, 0);
@ -106,7 +100,7 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
@Override
@Nonnull
public PanelComponent copyOf() {
ToggleSwitch ret = new ToggleSwitch(active, outputChannel);
ToggleSwitch ret = new ToggleSwitch(active, rsOutputId, rsOutputChannel);
ret.setX(x);
ret.setY(y);
ret.panelHeight = panelHeight;
@ -123,22 +117,30 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
@Override
public void interactWith(Vec3d hitRel, EntityPlayerMP player) {
setOut(!active);
public void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
setOut(!active, tile);
tile.triggerRenderUpdate();
}
@Override
public void update() {
public void update(TileEntityPanel tile) {
}
@Override
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsOutputId) {
super.registerRSOutput(id, out);
out.accept((int) rsOutputChannel, (byte) (active ? 15 : 0), this);
}
}
@Override
public float getHeight() {
return .0625F * 3 / 2;
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
AxisAlignedBB aabb = getBlockRelativeAABB();
double zOffset = (aabb.maxZ - aabb.minZ - sizeX) / 2;
@ -156,11 +158,15 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
protected void setOut(boolean on) {
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsOutputChannel, 0);
}
protected void setOut(boolean on, TileEntityPanel tile) {
active = on;
network.setOutputs(this, new RSChannelState(outputChannel, (byte) (active ? 15 : 0)));
panel.markDirty();
panel.triggerRenderUpdate();
tile.triggerRenderUpdate();
setOut(rsOutputChannel, active ? 15 : 0);
}
@Override
@ -172,22 +178,16 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
ToggleSwitch that = (ToggleSwitch) o;
if (active != that.active) return false;
if (Float.compare(that.sizeX, sizeX) != 0) return false;
if (Float.compare(that.sizeY, sizeY) != 0) return false;
if (Float.compare(that.rodRadius, rodRadius) != 0) return false;
if (Float.compare(that.rodLength, rodLength) != 0) return false;
return outputChannel.equals(that.outputChannel);
if (rsOutputId != that.rsOutputId) return false;
return rsOutputChannel == that.rsOutputChannel;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (active ? 1 : 0);
result = 31 * result + outputChannel.hashCode();
result = 31 * result + (sizeX != +0.0f ? Float.floatToIntBits(sizeX) : 0);
result = 31 * result + (sizeY != +0.0f ? Float.floatToIntBits(sizeY) : 0);
result = 31 * result + (rodRadius != +0.0f ? Float.floatToIntBits(rodRadius) : 0);
result = 31 * result + (rodLength != +0.0f ? Float.floatToIntBits(rodLength) : 0);
result = 31 * result + rsOutputId;
result = 31 * result + (int) rsOutputChannel;
return result;
}
@ -195,16 +195,19 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
outputChannel = outputChannel.withColor(value);
if (id == 0) {
rsOutputChannel = ((NBTTagByte) value).getByte();
}
break;
case INT:
outputChannel = outputChannel.withController(value);
if (id == 0) {
rsOutputId = ((NBTTagInt) value).getInt();
}
break;
}
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case RS_CHANNEL:
@ -218,7 +221,6 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case RS_CHANNEL:
@ -233,13 +235,13 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{new RSColorConfig("channel", 0, 0, outputChannel.getColor())};
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{new IntConfig("rsId", 0, 50, outputChannel.getController(), 2, false)};
return new IntConfig[]{new IntConfig("rsId", 0, 50, rsOutputId, 2, false)};
}
@Override

View file

@ -1,45 +1,46 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.controlpanel;
package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.client.RawQuad;
import malte0811.industrialwires.client.gui.GuiPanelCreator;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialwires.controlpanel.ControlPanelNetwork.RSChannelState;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.*;
public class Variac extends PanelComponent implements IConfigurableComponent {
private static final float SIZE = 3 / 16F;
private static final float innerSize = (float) (Math.sqrt(2) / 2 * SIZE);
@ -50,16 +51,14 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
private static final float rodOffset = (SIZE - rodDia) / 2;
private static final float arrowSize = .0625F / 2;
private int out;
@Nonnull
private RSChannel primary = RSChannel.DEFAULT_CHANNEL;
@Nonnull
private RSChannel secondary = RSChannel.INVALID_CHANNEL;
private byte out;
private byte rsChannel;
private int rsId;
public Variac(@Nonnull RSChannel primary, @Nonnull RSChannel secondary) {
public Variac(int rsId, byte rsChannel) {
this();
this.primary = primary;
this.secondary = secondary;
this.rsChannel = rsChannel;
this.rsId = rsId;
}
public Variac() {
@ -69,34 +68,23 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
if (!toItem) {
nbt.setInteger("output", out);
nbt.setByte("output", out);
}
nbt.setInteger(RS_ID, primary.getController());
nbt.setByte(RS_CHANNEL, primary.getColor());
nbt.setInteger(RS_ID2, secondary.getController());
nbt.setByte(RS_CHANNEL2, secondary.getColor());
nbt.setByte(RS_CHANNEL, rsChannel);
nbt.setInteger(RS_ID, rsId);
}
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
out = nbt.getInteger("output");
int rsController = nbt.getInteger(RS_ID);
byte rsColor = nbt.getByte(RS_CHANNEL);
primary = new RSChannel(rsController, rsColor);
if (nbt.hasKey(RS_ID2)) {
rsController = nbt.getInteger(RS_ID2);
rsColor = nbt.getByte(RS_CHANNEL2);
secondary = new RSChannel(rsController, rsColor);
} else {
secondary = RSChannel.INVALID_CHANNEL;
}
out = nbt.getByte("output");
rsChannel = nbt.getByte(RS_CHANNEL);
rsId = nbt.getInteger(RS_ID);
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
float angle = -(float) (2 * Math.PI * (8.5 + out) / (17F*16F));
float angle = -(float) (2 * Math.PI * (.5 + out) / 17F);
Matrix4 mat = new Matrix4();
mat.translate(SIZE / 2, 0, SIZE / 2);
mat.rotate(angle, 0, 1, 0);
@ -112,7 +100,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
new Vector3f(innerSize, getHeight() / 2, innerSize), ret, false, mat);
mat.translate(SIZE / 2, 0, SIZE / 2);
mat.rotate(Math.PI / 2, 0, 1, 0);
mat.translate(-SIZE / 2, Y_DELTA, -SIZE / 2);
mat.translate(-SIZE / 2, .0001, -SIZE / 2);
PanelUtils.addColoredQuad(ret, new Vector3f(offset, getHeight(), offset), new Vector3f(offset, getHeight(), offset),
new Vector3f(offset + arrowSize / 2, getHeight(), offset + arrowSize),
new Vector3f(offset + arrowSize, getHeight(), offset + arrowSize / 2), EnumFacing.UP, white, mat);
@ -122,7 +110,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Nonnull
@Override
public PanelComponent copyOf() {
Variac ret = new Variac(primary, secondary);
Variac ret = new Variac(rsId, rsChannel);
ret.out = out;
ret.setX(x);
ret.setY(y);
@ -140,7 +128,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
public void interactWith(Vec3d hitRelative, EntityPlayerMP player) {
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double xRel = hitRelative.x - SIZE / 2;
double yRel = -(hitRelative.z - SIZE / 2);
double angle = 1.5 * Math.PI - Math.atan2(yRel, xRel);
@ -149,33 +137,36 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
} else if (angle > 2 * Math.PI) {
angle -= 2 * Math.PI;
}
angle -= .5 * Math.PI / 17;
angle /= 2 * Math.PI;
int step = (secondary.isValid()&&player.isSneaking())?1:16;
int newLevel = (int) ((angle-1/34F) * 17 * 16);
int diff = Math.abs(newLevel-out);
if (diff>step) {
if (newLevel > out) {
newLevel = out + step;
} else if (newLevel < out) {
newLevel = out - step;
}
if (angle < 0 || angle >= 16 / 17D) {
return;
}
newLevel = Math.max(0, Math.min(newLevel, 255));
byte newLevel = (byte) (angle * 17);
if (newLevel > out) {
newLevel = (byte) (out + 1);
} else if (newLevel < out) {
newLevel = (byte) (out - 1);
}
newLevel = (byte) Math.max(0, Math.min(newLevel, 15));
if (newLevel != out) {
setOut(newLevel);
setOut(rsChannel, newLevel);
out = newLevel;
tile.triggerRenderUpdate();
}
}
@Override
public void update() {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (id == rsId) {
super.registerRSOutput(id, out);
out.accept((int) rsChannel, this.out, this);
}
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
network.setOutputs(this, new RSChannelState(primary, (byte) (out>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (out&0xf)));
public void update(TileEntityPanel tile) {
}
@Override
@ -184,7 +175,6 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) Math.ceil(gui.getX0() + (offset + aabb.minX) * gui.panelSize);
@ -193,23 +183,20 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
int bottom = (int) Math.floor(gui.getY0() + (aabb.maxZ - offset) * gui.panelSize);
GlStateManager.pushMatrix();
GlStateManager.translate((left + right) / 2F, (top + bottom) / 2F, 0);
GlStateManager.translate((left + right) / 2, (top + bottom) / 2, 0);
GlStateManager.rotate(360 / 17F, 0, 0, 1);
GlStateManager.translate(-(left + right) / 2F, -(top + bottom) / 2F, 0);
GlStateManager.translate(-(left + right) / 2, -(top + bottom) / 2, 0);
Gui.drawRect(left, top, right, bottom, 0xff333333);
GlStateManager.translate((left + right) / 2F, (top + bottom) / 2F, 0);
GlStateManager.translate((left + right) / 2, (top + bottom) / 2, 0);
GlStateManager.rotate(45, 0, 0, 1);
GlStateManager.translate(-(left + right) / 2F, -(top + bottom) / 2F, 0);
GlStateManager.translate(-(left + right) / 2, -(top + bottom) / 2, 0);
Gui.drawRect(left, top, right, bottom, 0xff333333);
GlStateManager.popMatrix();
}
public void setOut(int value) {
network.setOutputs(this, new RSChannelState(primary, (byte) (value>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (value&0xf)));
out = value;
panel.markDirty();
panel.triggerRenderUpdate();
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsChannel, 0);
}
@Override
@ -221,36 +208,26 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
Variac variac = (Variac) o;
if (out != variac.out) return false;
if (!primary.equals(variac.primary)) return false;
return secondary.equals(variac.secondary);
return rsChannel == variac.rsChannel;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + out;
result = 31 * result + primary.hashCode();
result = 31 * result + secondary.hashCode();
result = 31 * result + (int) out;
result = 31 * result + (int) rsChannel;
return result;
}
@Override
public void applyConfigOption(IConfigurableComponent.ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
if (id == 0) {
primary = primary.withColor(value);
} else {
secondary = secondary.withColor(value);
}
break;
case INT:
if (id == 0) {
primary = primary.withController(value);
} else {
secondary = secondary.withController(value);
}
break;
case RS_CHANNEL:
rsChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsId = ((NBTTagInt) value).getInt();
break;
}
}
@ -260,31 +237,28 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public String fomatConfigDescription(IConfigurableComponent.ConfigType type, int id) {
switch (type) {
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info" + (id == 1 ? "2" : ""));
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info" + (id == 1 ? "2" : ""));
default:
return "INVALID?";
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
default:
return "INVALID?";
}
}
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{
new RSColorConfig("channel", 0, 0, primary.getColor()),
new RSColorConfig("channel2", 90, 0, secondary.getColor())
public IConfigurableComponent.RSChannelConfig[] getRSChannelOptions() {
return new IConfigurableComponent.RSChannelConfig[]{
new IConfigurableComponent.RSChannelConfig("channel", 0, 0, rsChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 50, primary.getController(), 2, false),
new IntConfig("rsId2", 90, 50, secondary.getController(), 2, true)
public IConfigurableComponent.IntConfig[] getIntegerOptions() {
return new IConfigurableComponent.IntConfig[]{
new IConfigurableComponent.IntConfig("rsId", 0, 50, rsId, 2, false)
};
}

View file

@ -0,0 +1,102 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.crafting;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.items.ItemIC2Coil;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class RecipeCoilLength implements IRecipe {
public final ItemStack coil;
public final ItemStack cable;
private final int maxLength;
public RecipeCoilLength(int meta) {
coil = new ItemStack(IndustrialWires.coil, 1, meta);
cable = ItemIC2Coil.getUninsulatedCable(coil);
maxLength = ItemIC2Coil.getMaxWireLength(coil);
}
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
int l = getLength(inv);
return l > 0;
}
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack ret = new ItemStack(IndustrialWires.coil, 1, coil.getItemDamage());
ItemIC2Coil.setLength(ret, Math.min(maxLength, getLength(inv)));
return ret;
}
@Override
public int getRecipeSize() {
return 1;
}
@Nonnull
@Override
public ItemStack getRecipeOutput() {
return ItemStack.EMPTY;
}
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
int length = Math.min(getLength(inv), maxLength);
for (int i = 0; i < ret.size() && length > 0; i++) {
ItemStack curr = inv.getStackInSlot(i);
if (OreDictionary.itemMatches(curr, coil, false)) {
length -= ItemIC2Coil.getLength(curr);
if (length < 0) {
ItemStack currStack = coil.copy();
ret.set(i, currStack);
ItemIC2Coil.setLength(currStack, -length);
}
} else if (OreDictionary.itemMatches(curr, cable, false)) {
length--;
}
}
return ret;
}
private int getLength(InventoryCrafting inv) {
int cableLength = 0;
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack curr = inv.getStackInSlot(i);
if (OreDictionary.itemMatches(curr, coil, false)) {
cableLength += ItemIC2Coil.getLength(curr);
} else if (OreDictionary.itemMatches(curr, cable, false)) {
cableLength++;
} else if (!curr.isEmpty()) {
return -1;
}
}
return cableLength;
}
}

View file

@ -1,63 +1,57 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.crafting;
package malte0811.industrialWires.crafting;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialwires.controlpanel.PanelComponent;
import malte0811.industrialwires.items.ItemPanelComponent;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class RecipeComponentCopy extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
public class RecipeComponentCopy implements IRecipe {
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nullable World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
boolean found = false;
int foundX = -1;
int foundY = -1;
boolean foundPanel;
for (int x = 0; x < inv.getWidth(); x++) {
for (int y = 0; y < inv.getHeight(); y++) {
ItemStack here = inv.getStackInRowAndColumn(x, y);
PanelComponent pc1 = ItemPanelComponent.componentFromStack(here);
if (pc1 != null || isUnfinishedPanel(here)) {
if (pc1!=null) {
if (x==foundX&&y==foundY) {
continue;
}
if (found) {
return false;
}
foundPanel = pc1 == null;
if (y+1<inv.getHeight()) {
ItemStack below = inv.getStackInRowAndColumn(x, y + 1);
PanelComponent pc2 = ItemPanelComponent.componentFromStack(below);
if (foundPanel) {
if (!isUnfinishedPanel(below)) {
return false;
}
} else if (pc2 == null || pc2.getClass() != pc1.getClass()) {
if (pc2 == null || pc2.getClass() != pc1.getClass()) {
return false;
}
found = true;
@ -84,8 +78,8 @@ public class RecipeComponentCopy extends IForgeRegistryEntry.Impl<IRecipe> imple
}
@Override
public boolean canFit(int width, int height) {
return width>0&&height>1;
public int getRecipeSize() {
return 2;
}
@Nonnull
@ -105,23 +99,11 @@ public class RecipeComponentCopy extends IForgeRegistryEntry.Impl<IRecipe> imple
for (int x = 0; x < inv.getWidth(); x++) {
for (int y = 0; y < inv.getHeight() - 1; y++) {
ItemStack here = inv.getStackInRowAndColumn(x, y);
if (here.getItem() == IndustrialWires.panelComponent
|| isUnfinishedPanel(here)) {
if (!here.isEmpty() && here.getItem() == IndustrialWires.panelComponent) {
return new int[]{x, y};
}
}
}
return null;
}
private boolean isUnfinishedPanel(ItemStack stack) {
return stack.getItem() == Item.getItemFromBlock(IndustrialWires.panel)
&& stack.getMetadata() == BlockTypes_Panel.UNFINISHED.ordinal();
}
@Override
public boolean isDynamic() {
return true;
}
}

View file

@ -1,33 +1,36 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.crafting;
package malte0811.industrialWires.crafting;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.items.ItemPanelComponent;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;
import javax.annotation.Nonnull;
public class RecipeInitPC extends ShapedOreRecipe {
public RecipeInitPC(ShapedOreRecipe factory) {
super(factory.getRegistryName(), factory.getRecipeOutput(), primerFromRecipe(factory));
public RecipeInitPC(ItemStack result, Object... recipe) {
super(result, recipe);
}
@Nonnull
@ -41,12 +44,8 @@ public class RecipeInitPC extends ShapedOreRecipe {
return ret;
}
private static ShapedPrimer primerFromRecipe(ShapedOreRecipe recipe) {
ShapedPrimer ret = new ShapedPrimer();
ret.height = recipe.getHeight();
ret.width = recipe.getWidth();
ret.input = recipe.getIngredients();
ret.mirrored = true;
return ret;
@Override
public boolean matches(InventoryCrafting inv, World world) {
return super.matches(inv, world);
}
}

View file

@ -1,40 +1,40 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.crafting;
package malte0811.industrialWires.crafting;
import blusunrize.immersiveengineering.api.ApiUtils;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.controlpanel.Lock;
import malte0811.industrialwires.controlpanel.PanelComponent;
import malte0811.industrialwires.items.ItemKey;
import malte0811.industrialwires.items.ItemPanelComponent;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.controlpanel.Lock;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class RecipeKeyLock extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
public class RecipeKeyLock implements IRecipe {
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nullable World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
return getLockId(inv) != 0;
}
@ -47,8 +47,8 @@ public class RecipeKeyLock extends IForgeRegistryEntry.Impl<IRecipe> implements
}
@Override
public boolean canFit(int width, int height) {
return width*height>=2;
public int getRecipeSize() {
return 2;
}
@Nonnull
@ -109,13 +109,4 @@ public class RecipeKeyLock extends IForgeRegistryEntry.Impl<IRecipe> implements
}
return ItemStack.EMPTY;
}
@Nonnull
@Override
public NonNullList<Ingredient> getIngredients() {
NonNullList<Ingredient> ret = NonNullList.withSize(2, Ingredient.EMPTY);
ret.set(0, Ingredient.fromStacks(new ItemStack(IndustrialWires.key, 1, 0)));
ret.set(1, Ingredient.fromStacks(new ItemStack(IndustrialWires.panelComponent, 1, 7)));
return ret;
}
}

View file

@ -1,37 +1,37 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.crafting;
package malte0811.industrialWires.crafting;
import malte0811.industrialwires.IWConfig;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static malte0811.industrialwires.util.NBTKeys.*;
import static malte0811.industrialWires.items.ItemKey.*;
public class RecipeKeyRing extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
public class RecipeKeyRing implements IRecipe {
private final boolean addToRing;
public RecipeKeyRing(boolean add) {
@ -39,7 +39,7 @@ public class RecipeKeyRing extends IForgeRegistryEntry.Impl<IRecipe> implements
}
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nullable World worldIn) {
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
return isValid(inv);
}
@ -87,11 +87,10 @@ public class RecipeKeyRing extends IForgeRegistryEntry.Impl<IRecipe> implements
}
@Override
public boolean canFit(int width, int height) {
return width>0&&height>0;
public int getRecipeSize() {
return 1;
}
@Nonnull
@Override
public ItemStack getRecipeOutput() {
@ -168,16 +167,4 @@ public class RecipeKeyRing extends IForgeRegistryEntry.Impl<IRecipe> implements
}
return -1;
}
@Nonnull
@Override
public NonNullList<Ingredient> getIngredients() {
if (addToRing) {
NonNullList<Ingredient> ret = NonNullList.withSize(2, Ingredient.fromStacks(new ItemStack(IndustrialWires.key, 1, 1)));;
ret.set(1, Ingredient.fromStacks(new ItemStack(IndustrialWires.key, 1, 2)));
return ret;
} else {
return NonNullList.withSize(1, Ingredient.fromStacks(new ItemStack(IndustrialWires.key, 1, 2)));
}
}
}

View file

@ -1,19 +1,22 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.items;
package malte0811.industrialWires.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;

View file

@ -0,0 +1,243 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.items;
import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.api.TargetingInfo;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.IWireCoil;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import blusunrize.immersiveengineering.common.IESaveData;
import blusunrize.immersiveengineering.common.util.IEAchievements;
import blusunrize.immersiveengineering.common.util.ItemNBTHelper;
import blusunrize.immersiveengineering.common.util.Utils;
import ic2.api.item.IC2Items;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.wires.IC2Wiretype;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ItemIC2Coil extends Item implements IWireCoil {
public final static String[] subNames = {"tin", "copper", "gold", "hv", "glass"};
public final static String lengthKey = "wireLength";
public ItemIC2Coil() {
setUnlocalizedName(IndustrialWires.MODID + ".ic2_wire_coil");
setHasSubtypes(true);
this.setCreativeTab(IndustrialWires.creativeTab);
setMaxStackSize(64);
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "ic2_wire_coil"));
GameRegistry.register(this);
}
@Override
public void getSubItems(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> subItems) {
for (int i = 0; i < subNames.length; i++) {
ItemStack tmp = new ItemStack(this, 1, i);
setLength(tmp, getMaxWireLength(tmp));
subItems.add(tmp);
}
}
@Nonnull
@Override
public String getUnlocalizedName(ItemStack stack) {
return this.getUnlocalizedName() + "." + subNames[stack.getMetadata()];
}
@Override
public WireType getWireType(ItemStack stack) {
return IC2Wiretype.IC2_TYPES[stack.getMetadata()];
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean adv) {
list.add(I18n.format(IndustrialWires.MODID + ".desc.wireLength", getLength(stack)));
int transferRate = IC2Wiretype.IC2_TYPES[stack.getMetadata()].getTransferRate();
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.transfer_rate", transferRate));
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.input_rate", transferRate / 8));
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("linkingPos")) {
int[] link = stack.getTagCompound().getIntArray("linkingPos");
if (link.length > 3) {
list.add(I18n.format(Lib.DESC_INFO + "attachedToDim", link[1], link[2], link[3], link[0]));
}
}
list.add(I18n.format(IndustrialWires.MODID + ".desc.recipe"));
}
//mostly copied from IE
@Nonnull
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote && !stack.isEmpty()) {
if (stack.getCount() > 1) {
player.sendMessage(new TextComponentTranslation(IndustrialWires.MODID + ".chat.stackSize"));
return EnumActionResult.FAIL;
}
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
WireType wire = getWireType(stack);
BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
tileEntity = world.getTileEntity(masterPos);
if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect()) {
return EnumActionResult.PASS;
}
if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
return EnumActionResult.FAIL;
}
if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
ItemNBTHelper.setIntArray(stack, "linkingPos", new int[]{world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ()});
target.writeToNBT(stack.getTagCompound());
} else {
WireType type = getWireType(stack);
int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
if (array[0] != world.provider.getDimension()) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
} else if (linkPos.equals(masterPos)) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
} else if (distanceSq > (type.getMaxLength() * type.getMaxLength())) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
} else if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(type, TargetingInfo.readFromNBT(stack.getTagCompound()))) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
} else {
IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
boolean connectionExists = false;
Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
if (outputs != null) {
for (Connection con : outputs) {
if (con.end.equals(Utils.toCC(nodeLink))) {
connectionExists = true;
}
}
}
if (connectionExists) {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
} else {
Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
Set<BlockPos> ignore = new HashSet<>();
ignore.addAll(nodeHere.getIgnored(nodeLink));
ignore.addAll(nodeLink.getIgnored(nodeHere));
boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
if (canSee) {
int lengthOnStack = getLength(stack);
int length = (int) Math.sqrt(distanceSq);
if (length <= lengthOnStack) {
TargetingInfo targetLink = TargetingInfo.readFromNBT(stack.getTagCompound());
ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), length, type);
nodeHere.connectCable(type, target, nodeLink);
nodeLink.connectCable(type, targetLink, nodeHere);
IESaveData.setDirty(world.provider.getDimension());
player.addStat(IEAchievements.connectWire);
if (!player.capabilities.isCreativeMode) {
if (length < lengthOnStack) {
setLength(stack, lengthOnStack - length);
} else {
player.setHeldItem(hand, ItemStack.EMPTY);
}
}
((TileEntity) nodeHere).markDirty();
world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
IBlockState state = world.getBlockState(masterPos);
world.notifyBlockUpdate(masterPos, state, state, 3);
((TileEntity) nodeLink).markDirty();
world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
state = world.getBlockState(linkPos);
world.notifyBlockUpdate(linkPos, state, state, 3);
} else {
player.sendMessage(new TextComponentTranslation(IndustrialWires.MODID + ".chat.tooLong"));
}
} else {
player.sendMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
}
}
}
ItemNBTHelper.remove(stack, "linkingPos");
ItemNBTHelper.remove(stack, "side");
ItemNBTHelper.remove(stack, "hitX");
ItemNBTHelper.remove(stack, "hitY");
ItemNBTHelper.remove(stack, "hitZ");
}
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.PASS;
}
public static void setLength(ItemStack i, int blocks) {
i.setTagInfo(lengthKey, new NBTTagInt(blocks));
}
public static int getLength(ItemStack i) {
if (i.getTagCompound() == null) {
setLength(i, 4);
}
return i.getTagCompound().getInteger(lengthKey);
}
public static int getMaxWireLength(ItemStack i) {
return IWConfig.maxLengthOnCoil[i.getItemDamage()];
}
public static ItemStack getUninsulatedCable(ItemStack i) {
switch (i.getMetadata()) {
case 0:
return IC2Items.getItem("cable", "type:tin,insulation:0");
case 1:
return IC2Items.getItem("cable", "type:copper,insulation:0");
case 2:
return IC2Items.getItem("cable", "type:gold,insulation:0");
case 3:
return IC2Items.getItem("cable", "type:iron,insulation:0");
case 4:
return IC2Items.getItem("cable", "type:glass,insulation:0");
}
return null;
}
}

View file

@ -1,23 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.items;
package malte0811.industrialWires.items;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@ -28,31 +30,28 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.*;
public class ItemKey extends Item implements INetGUIItem {
public static final String LOCK_ID = "lockId";
public static final String RING_KEYS = "ringkeys";
public static final String NAME = "name";
public static final String[] types = {"blank_key", "key", "key_ring"};
public static final String ITEM_NAME = "key";
public ItemKey() {
setTranslationKey(IndustrialWires.MODID + "." + ITEM_NAME);
setUnlocalizedName(IndustrialWires.MODID + ".key");
setHasSubtypes(true);
this.setCreativeTab(IndustrialWires.creativeTab);
setMaxStackSize(64);
setRegistryName(new ResourceLocation(IndustrialWires.MODID, ITEM_NAME));
IndustrialWires.items.add(this);
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "key"));
GameRegistry.register(this);
}
@Nonnull
@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
NBTTagCompound nbt = stack.getTagCompound();
if (nbt!=null&&nbt.hasKey(NAME)&&!nbt.getString(NAME).trim().isEmpty()) {
@ -62,9 +61,14 @@ public class ItemKey extends Item implements INetGUIItem {
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn);
public void getSubItems(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> subItems) {
subItems.add(new ItemStack(this, 1, 0));
subItems.add(new ItemStack(this, 1, 2));
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (stack.getMetadata()==2&&stack.getTagCompound()!=null) {
NBTTagList keys = stack.getTagCompound().getTagList(RING_KEYS, 10);
for (int i = 0;i< keys.tagCount()-1;i++) {
@ -73,17 +77,9 @@ public class ItemKey extends Item implements INetGUIItem {
}
}
@Override
public void getSubItems(@Nonnull CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems) {
if (isInCreativeTab(tab)) {
subItems.add(new ItemStack(this, 1, 0));
subItems.add(new ItemStack(this, 1, 2));
}
}
@Nonnull
@Override
public String getTranslationKey(ItemStack stack) {
public String getUnlocalizedName(ItemStack stack) {
return "item."+IndustrialWires.MODID+".key."+types[stack.getMetadata()];
}

View file

@ -1,37 +1,32 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.items;
package malte0811.industrialWires.items;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.client.ClientProxy;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.controlpanel.BlockTypes_Panel;
import malte0811.industrialwires.blocks.controlpanel.TileEntityComponentPanel;
import malte0811.industrialwires.controlpanel.IConfigurableComponent;
import malte0811.industrialwires.controlpanel.PanelComponent;
import malte0811.industrialwires.controlpanel.PanelUtils;
import malte0811.industrialwires.controlpanel.SevenSegDisplay;
import malte0811.industrialwires.util.MiscUtils;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
@ -39,8 +34,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@ -48,27 +43,26 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
import static malte0811.industrialwires.util.NBTKeys.*;
public class ItemPanelComponent extends Item implements INetGUIItem {
public static final String[] types = {
"lighted_button", "label", "indicator_light", "slider", "variac", "toggle_switch", "toggle_switch_covered",
"lock", "panel_meter", SevenSegDisplay.NAME, "rgb_led"
"lock", "panel_meter"
};
public static final String NAME = "panel_component";
public static final String TYPE = "type";
public static final String ID = "cfgId";
public static final String VALUE = "value";
public ItemPanelComponent() {
setTranslationKey(IndustrialWires.MODID + "." + NAME);
setUnlocalizedName(IndustrialWires.MODID + ".panel_component");
setHasSubtypes(true);
this.setCreativeTab(IndustrialWires.creativeTab);
setMaxStackSize(64);
setRegistryName(new ResourceLocation(IndustrialWires.MODID, NAME));
IndustrialWires.items.add(this);
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "panel_component"));
GameRegistry.register(this);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> list, ITooltipFlag flag) {
public void addInformation(ItemStack stack, EntityPlayer player, List<String> list, boolean adv) {
if (GuiScreen.isShiftKeyDown()) {
NBTTagCompound nbt = getTagCompound(stack);
NBTTagCompound data = nbt.getCompoundTag("data");
@ -85,19 +79,16 @@ public class ItemPanelComponent extends Item implements INetGUIItem {
return ClientProxy.itemFont;//TODO non-core-IE solution?
}
@Nonnull
@Override
public String getTranslationKey(ItemStack stack) {
return this.getTranslationKey() + "." + types[stack.getMetadata()];
public String getUnlocalizedName(ItemStack stack) {
return this.getUnlocalizedName() + "." + types[stack.getMetadata()];
}
@Override
public void getSubItems(@Nonnull CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems) {
if (isInCreativeTab(tab)) {
for (int i = 0; i < types.length; i++) {
subItems.add(new ItemStack(this, 1, i));
}
public void getSubItems(@Nonnull Item itemIn, CreativeTabs tab, NonNullList<ItemStack> subItems) {
for (int i = 0; i < types.length; i++) {
subItems.add(new ItemStack(itemIn, 1, i));
}
}
@ -165,50 +156,12 @@ public class ItemPanelComponent extends Item implements INetGUIItem {
@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
if (!worldIn.isRemote&&!playerIn.isSneaking()) {
if (!worldIn.isRemote) {
playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0);
}
return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
}
/**
* mostly copied from {@link net.minecraft.item.ItemBlock}
*/
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (player.isSneaking()) {
IBlockState iblockstate = worldIn.getBlockState(pos);
Block block = iblockstate.getBlock();
if (!block.isReplaceable(worldIn, pos)) {
pos = pos.offset(facing);
}
ItemStack itemstack = player.getHeldItem(hand);
if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(IndustrialWires.panel, pos, false, facing, null)) {
placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ);
SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
itemstack.shrink(1);
return EnumActionResult.SUCCESS;
}
}
return EnumActionResult.FAIL;
}
private void placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
IBlockState state = IndustrialWires.panel.getStateFromMeta(BlockTypes_Panel.SINGLE_COMP.ordinal());
world.setBlockState(pos, state);
TileEntityComponentPanel te = MiscUtils.getLoadedTE(world, pos, TileEntityComponentPanel.class);
if (te!=null) {
EnumFacing dir = te.getFacingForPlacement(player, pos, side, hitX, hitY, hitZ);
te.setFacing(dir);
te.setComponent(componentFromStack(stack));
}
}
@Override
public void onChange(NBTTagCompound data, EntityPlayer player, EnumHand hand) {
ItemStack held = player.getHeldItem(hand);
@ -231,9 +184,4 @@ public class ItemPanelComponent extends Item implements INetGUIItem {
}
}
}
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
return !ItemStack.areItemsEqual(oldStack, newStack);
}
}

View file

@ -1,22 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.network;
package malte0811.industrialWires.network;
import io.netty.buffer.ByteBuf;
import malte0811.industrialwires.blocks.INetGUI;
import malte0811.industrialWires.blocks.INetGUI;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

View file

@ -1,22 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.network;
package malte0811.industrialWires.network;
import io.netty.buffer.ByteBuf;
import malte0811.industrialwires.items.INetGUIItem;
import malte0811.industrialWires.items.INetGUIItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -53,15 +56,12 @@ public class MessageItemSync implements IMessage {
public static class HandlerServer implements IMessageHandler<MessageItemSync, IMessage> {
@Override
public IMessage onMessage(MessageItemSync message, MessageContext ctx) {
ctx.getServerHandler().player.getServerWorld()
.addScheduledTask(()-> {
EntityPlayer player = ctx.getServerHandler().player;
ItemStack held = player.getHeldItem(message.hand);
if (held.getItem() instanceof INetGUIItem) {
ctx.getServerHandler().player.getServerWorld().addScheduledTask(() ->
((INetGUIItem) held.getItem()).onChange(message.data, player, message.hand));
}
});
EntityPlayer player = ctx.getServerHandler().player;
ItemStack held = player.getHeldItem(message.hand);
if (held.getItem() instanceof INetGUIItem) {
ctx.getServerHandler().player.getServerWorld().addScheduledTask(() ->
((INetGUIItem)held.getItem()).onChange(message.data, player, message.hand));
}
return null;
}
}

View file

@ -1,22 +1,25 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.network;
package malte0811.industrialWires.network;
import io.netty.buffer.ByteBuf;
import malte0811.industrialwires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@ -31,7 +34,7 @@ public class MessagePanelInteract implements IMessage {
private Vec3d hitRelative;
public MessagePanelInteract(TileEntityPanel tile, int id, Vec3d hit) {
pos = tile.getBlockPos();
pos = tile.getPos();
pcId = id;
hitRelative = hit;
}

View file

@ -1,24 +1,27 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.network;
package malte0811.industrialWires.network;
import blusunrize.immersiveengineering.common.blocks.TileEntityIEBase;
import io.netty.buffer.ByteBuf;
import malte0811.industrialwires.IndustrialWires;
import malte0811.industrialwires.blocks.ISyncReceiver;
import net.minecraft.client.Minecraft;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.ISyncReceiver;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
@ -33,7 +36,7 @@ public class MessageTileSyncIW implements IMessage {
BlockPos pos;
NBTTagCompound nbt;
public MessageTileSyncIW(TileEntity tile, NBTTagCompound nbt) {
public MessageTileSyncIW(TileEntityIEBase tile, NBTTagCompound nbt) {
this.pos = tile.getPos();
this.nbt = nbt;
}
@ -58,15 +61,13 @@ public class MessageTileSyncIW implements IMessage {
public static class HandlerClient implements IMessageHandler<MessageTileSyncIW, IMessage> {
@Override
public IMessage onMessage(MessageTileSyncIW message, MessageContext ctx) {
Minecraft.getMinecraft().addScheduledTask(()-> {
World world = IndustrialWires.proxy.getClientWorld();
if (world != null) {
TileEntity tile = world.getTileEntity(message.pos);
if (tile instanceof ISyncReceiver) {
((ISyncReceiver) tile).onSync(message.nbt);
}
World world = IndustrialWires.proxy.getClientWorld();
if (world != null) {
TileEntity tile = world.getTileEntity(message.pos);
if (tile instanceof ISyncReceiver) {
((ISyncReceiver) tile).onSync(message.nbt);
}
});
}
return null;
}
}

View file

@ -1,19 +1,22 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.util;
package malte0811.industrialWires.util;
import net.minecraft.util.math.Vec3d;
@ -31,7 +34,7 @@ public final class Beziers {
int n = controls.length - 1;
for (int i = 0; i <= n; i++) {
double coeff = binomialCoeff(n, i) * Math.pow(t, i) * Math.pow(1 - t, n - i);
ret = ret.add(coeff * controls[i].x, coeff * controls[i].y, coeff * controls[i].z);
ret = ret.addVector(coeff * controls[i].x, coeff * controls[i].y, coeff * controls[i].z);
}
return ret;
}

View file

@ -1,21 +1,24 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.util;
package malte0811.industrialWires.util;
import blusunrize.immersiveengineering.common.Config;
import malte0811.industrialwires.IWConfig.MechConversion;
import malte0811.industrialWires.IWConfig.MechConversion;
public class ConversionUtil {
private ConversionUtil() {
@ -29,16 +32,16 @@ public class ConversionUtil {
return Config.IEConfig.Machines.dynamo_output;
}
public static double euPerIf() {
public static double euPerIfIdeal() {
return MechConversion.euPerIf;
}
public static double ifPerEu() {
public static double ifPerEuIdeal() {
return 1 / MechConversion.euPerIf;
}
public static double euPerKin() {
return 1 / kinPerEu();
return 1 / euPerKin();
}
public static double kinPerEu() {
@ -46,26 +49,10 @@ public class ConversionUtil {
}
public static double kinPerRot() {
return kinPerEu() * euPerIf() * ifPerRot();
return kinPerEu() * euPerIfIdeal() * ifPerRot();
}
public static double rotPerKin() {
return 1 / kinPerRot();
}
public static double joulesPerIf() {
return MechConversion.joulesPerRF;
}
public static double ifPerJoule() {
return 1/joulesPerIf();
}
public static double joulesPerEu() {
return joulesPerIf()* ifPerEu();
}
public static double euPerJoule() {
return euPerIf()*ifPerJoule();
}
}

View file

@ -0,0 +1,120 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.util;
import net.minecraft.nbt.NBTTagCompound;
public class DualEnergyStorage {
private double storedEU;
private double maxEU;
private double maxOutEU;
private double maxInEU;
public DualEnergyStorage(double maxEU, double maxInEU, double maxOutEU) {
this(0, maxEU, maxInEU, maxOutEU);
}
public DualEnergyStorage(double storedEU, double maxEU, double maxInEU, double maxOutEU) {
this.maxEU = maxEU;
this.maxInEU = maxInEU;
this.maxOutEU = maxOutEU;
this.storedEU = storedEU;
}
public DualEnergyStorage(double maxEU, double maxIoEU) {
this(maxEU, maxIoEU, maxIoEU);
}
public DualEnergyStorage(double maxEU) {
this(maxEU, maxEU, maxEU);
}
public DualEnergyStorage(int maxIF, int maxInIF, int maxOutIF) {
this(ConversionUtil.euPerIfIdeal() * maxIF, ConversionUtil.euPerIfIdeal() * maxInIF, ConversionUtil.euPerIfIdeal() * maxOutIF);
}
public DualEnergyStorage(int maxIF, int maxIoIF) {
this(maxIF, maxIoIF, maxIoIF);
}
public DualEnergyStorage(int maxIF) {
this(maxIF, maxIF, maxIF);
}
public double extractEU(double extractMax, boolean doExtract) {
double extr = Math.min(storedEU, extractMax);
if (doExtract) {
storedEU -= extr;
}
return extr;
}
public double extractIF(int extractMax, boolean doExtract) {
double eu = extractMax * ConversionUtil.euPerIfIdeal();
return ConversionUtil.ifPerEuIdeal() * extractEU(eu, doExtract);
}
public double insertEU(double insertMax, boolean doInsert) {
double ins = Math.min(insertMax, maxEU - storedEU);
if (doInsert) {
storedEU += ins;
}
return ins;
}
public double insertIF(int insertMax, boolean doInsert) {
double eu = insertMax * ConversionUtil.euPerIfIdeal();
return ConversionUtil.ifPerEuIdeal() * insertEU(eu, doInsert);
}
public double getEnergyStoredEU() {
return storedEU;
}
public double getMaxStoredEU() {
return maxEU;
}
public double getEnergyStoredIF() {
return storedEU * ConversionUtil.ifPerEuIdeal();
}
public double getMaxStoredIF() {
return maxEU * ConversionUtil.ifPerEuIdeal();
}
public double getEURequested() {
return Math.min(maxInEU, maxEU - storedEU);
}
public void writeToNbt(NBTTagCompound nbtOuter, String key) {
NBTTagCompound nbt = key == null ? nbtOuter : new NBTTagCompound();
nbt.setDouble("stored", storedEU);
nbt.setDouble("maxStored", maxEU);
nbt.setDouble("maxIn", maxInEU);
nbt.setDouble("maxOut", maxOutEU);
if (key != null) {
nbtOuter.setTag(key, nbt);
}
}
public static DualEnergyStorage readFromNBT(NBTTagCompound nbt) {
return new DualEnergyStorage(nbt.getDouble("stored"), nbt.getDouble("maxStored"), nbt.getDouble("maxIn"), nbt.getDouble("maxOut"));
}
}

View file

@ -0,0 +1,87 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.util;
import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import com.google.common.collect.ImmutableSet;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiPredicate;
public final class MiscUtils {
private MiscUtils() {
}
public static Set<ImmersiveNetHandler.Connection> genConnBlockstate(Set<ImmersiveNetHandler.Connection> conns, World world) {
if (conns == null)
return ImmutableSet.of();
Set<ImmersiveNetHandler.Connection> ret = new HashSet<ImmersiveNetHandler.Connection>() {
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof HashSet))
return false;
HashSet<ImmersiveNetHandler.Connection> other = (HashSet<ImmersiveNetHandler.Connection>) o;
if (other.size() != this.size())
return false;
for (ImmersiveNetHandler.Connection c : this)
if (!other.contains(c))
return false;
return true;
}
};
for (ImmersiveNetHandler.Connection c : conns) {
IImmersiveConnectable end = ApiUtils.toIIC(c.end, world, false);
if (end == null)
continue;
// generate subvertices
c.getSubVertices(world);
ret.add(c);
}
return ret;
}
public static List<BlockPos> discoverLocal(World w, BlockPos here, BiPredicate<BlockPos, Integer> isValid) {
List<BlockPos> ret = new ArrayList<>();
List<BlockPos> open = new ArrayList<>();
open.add(here);
while (!open.isEmpty()) {
BlockPos curr = open.get(0);
ret.add(curr);
open.remove(0);
for (EnumFacing f : EnumFacing.VALUES) {
BlockPos next = curr.offset(f);
if (!open.contains(next) && !ret.contains(next) && isValid.test(next, ret.size())) {
open.add(next);
}
}
}
return ret;
}
}

View file

@ -1,27 +1,23 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires.blocks.hv;
package malte0811.industrialWires.util;
import net.minecraft.util.IStringSerializable;
public enum BlockTypes_GeneralHV implements IStringSerializable{
DISCHARGE_METER;
@Override
public String getName() {
return name().toLowerCase();
}
public interface TriConsumer<A, B, C> {
void accept(A a, B b, C c);
}

View file

@ -0,0 +1,105 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
*
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.wires;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection;
import blusunrize.immersiveengineering.api.energy.wires.WireType;
import malte0811.industrialWires.IWConfig;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.items.ItemIC2Coil;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class IC2Wiretype extends WireType {
final int type;
final int[] ic2Rates = {32 * 8, 128 * 8, 512 * 8, 2048 * 8, 8192 * 8};
final int[] ic2Colors = {0xa5bcc7, 0xbc7945, 0xfeff73, 0xb9d6d9, 0xf1f1f1};
final String[] ic2Names = {"ic2Tin", "ic2Copper", "ic2Gold", "ic2Hv", "ic2Glass"};
final double[] lossPerBlock = {.2, .2, .4, .8, .025};
final double[] ic2RenderDiameter = {.03125, .03125, .046875, .0625, .75 * .03125};
public static final IC2Wiretype[] IC2_TYPES = {new IC2Wiretype(0), new IC2Wiretype(1), new IC2Wiretype(2), new IC2Wiretype(3), new IC2Wiretype(4)};
public IC2Wiretype(int ordinal) {
super();
this.type = ordinal;
}
/**
* In this case, this does not return the loss RATIO but the loss PER BLOCK
*/
@Override
public double getLossRatio() {
return lossPerBlock[type];
}
@Override
public int getTransferRate() {
return ic2Rates[type];
}
@Override
public int getColour(Connection connection) {
return ic2Colors[type];
}
@Override
public double getSlack() {
return type == 2 ? 1.03 : 1.005;
}
@Override
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getIcon(Connection connection) {
return iconDefaultWire;
}
@Override
public int getMaxLength() {
return IWConfig.maxLengthPerConn[type];
}
@Override
public ItemStack getWireCoil(ImmersiveNetHandler.Connection con) {
ItemStack ret = getWireCoil();
ItemIC2Coil.setLength(ret, con.length);
return ret;
}
@Override
public ItemStack getWireCoil() {
return new ItemStack(IndustrialWires.coil, 1, type);
}
@Override
public String getUniqueName() {
return ic2Names[type];
}
@Override
public double getRenderDiameter() {
return ic2RenderDiameter[type];
}
@Override
public boolean isEnergyWire() {
return true;
}
}

View file

@ -1,68 +0,0 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires;
import malte0811.industrialwires.items.ItemIC2Coil;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod.EventBusSubscriber
public class EventHandler {
@SubscribeEvent
public static void onItemPickup(EntityItemPickupEvent ev) {
if (ev.getItem().getItem().getItem()==IndustrialWires.coil) {
ItemStack stack = ev.getItem().getItem();
InventoryPlayer playerInv = ev.getEntityPlayer().inventory;
boolean changed = false;
int lengthOnEntity = ItemIC2Coil.getLength(stack);
final int lengthPerCoilOrig = lengthOnEntity/stack.getCount();
for (int i = 0;i<playerInv.getSizeInventory();i++) {
ItemStack inInv = playerInv.getStackInSlot(i);
if (ItemStack.areItemsEqual(stack, inInv)) {
int oldLength = ItemIC2Coil.getLength(inInv);
int newLength = Math.min(oldLength+lengthOnEntity, ItemIC2Coil.getMaxWireLength(inInv));
ItemIC2Coil.setLength(inInv, newLength);
lengthOnEntity -= newLength-oldLength;
changed = true;
}
}
if (changed) {
ev.getEntityPlayer().onItemPickup(ev.getItem(), 1);
}
if (lengthOnEntity==0) {
ev.getItem().setDead();
ev.setCanceled(true);
} else if (stack.getCount()>1) {
int coilsRemaining = lengthOnEntity/lengthPerCoilOrig;
stack.setCount(coilsRemaining);
int leftover = lengthOnEntity-lengthPerCoilOrig*coilsRemaining;
if (leftover>0) {
EntityItem old = ev.getItem();
ItemStack leftoverItem = new ItemStack(stack.getItem(), 1, stack.getMetadata());
ItemIC2Coil.setLength(leftoverItem, leftover);
EntityItem newCoil = new EntityItem(old.world, old.posX, old.posY, old.posZ, leftoverItem);
old.world.spawnEntity(newCoil);
}
} else if (stack.getCount()==1) {
ItemIC2Coil.setLength(stack, lengthOnEntity);
}
}
}
}

View file

@ -1,55 +0,0 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires;
import blusunrize.immersiveengineering.ImmersiveEngineering;
import blusunrize.immersiveengineering.common.blocks.BlockIEBase;
import blusunrize.immersiveengineering.common.blocks.BlockTypes_MetalsIE;
import blusunrize.immersiveengineering.common.blocks.metal.*;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class IEObjects {
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":metal_decoration0")
public static BlockIEBase<BlockTypes_MetalDecoration0> blockMetalDecoration0 = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":metal_decoration1")
public static BlockIEBase<BlockTypes_MetalDecoration1> blockMetalDecoration1 = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":metal_decoration2")
public static BlockIEBase<BlockTypes_MetalDecoration2> blockMetalDecoration2 = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":metal_device0")
public static BlockIEBase<BlockTypes_MetalDevice0> blockMetalDevice0 = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":connector")
public static BlockIEBase<BlockTypes_Connector> blockConnectors = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":storage")
public static BlockIEBase<BlockTypes_MetalsIE> blockStorage = nullNotNull();
//ITEMS
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":earmuffs")
public static Item itemEarmuffs = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":material")
public static Item itemMaterial = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":wirecoil")
public static Item itemWireCoil = nullNotNull();
@GameRegistry.ObjectHolder(ImmersiveEngineering.MODID+":tool")
public static Item itemTool = nullNotNull();
// Ugly hack to prevent null warnings
private static <T> T nullNotNull() {
//noinspection ConstantConditions
return null;
}
}

View file

@ -1,33 +0,0 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import malte0811.industrialwires.util.ConversionUtil;
import net.minecraft.entity.Entity;
public interface IMixedConnector extends IImmersiveConnectable {
/**
* @return leftover energy.
*/
double insertEnergy(double joules, boolean simulate);
@Override
default float getDamageAmount(Entity e, ImmersiveNetHandler.Connection c)
{
return (float) Math.ceil(IImmersiveConnectable.super.getDamageAmount(e, c) * ConversionUtil.euPerJoule());//Same as IC2 uses
}
}

View file

@ -1,29 +0,0 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2018 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialwires;
import net.minecraft.util.DamageSource;
public class IWDamageSources {
public static class MarxDamage extends DamageSource {
public MarxDamage() {
super("industrialwires.marx");
setDamageBypassesArmor();
}
}
public static final MarxDamage dmg_marx = new MarxDamage();
public static final DamageSource dmg_jacobs = new DamageSource("industrialwires.jacobs_ladder");
}

Some files were not shown because too many files have changed in this diff Show more