Generify mod and identifier holder into ModIdentifier

This commit is contained in:
Bixilon 2020-11-20 14:27:59 +01:00
parent f44cf53268
commit a0b7bdeeee
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
10 changed files with 118 additions and 140 deletions

View File

@ -13,17 +13,13 @@
package de.bixilon.minosoft.data.mappings;
public record BlockId(String mod, String identifier) {
public String getMod() {
return mod;
public class BlockId extends ModIdentifier {
public BlockId(String mod, String identifier) {
super(mod, identifier);
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", getMod(), getIdentifier());
public BlockId(String fullIdentifier) {
super(fullIdentifier);
}
}

View File

@ -13,39 +13,18 @@
package de.bixilon.minosoft.data.mappings;
public class Dimension {
final String mod;
final String identifier;
public class Dimension extends ModIdentifier {
final boolean hasSkyLight;
public Dimension(String mod, String identifier, boolean hasSkyLight) {
this.mod = mod;
this.identifier = identifier;
super(mod, identifier);
this.hasSkyLight = hasSkyLight;
}
public String getMod() {
return mod;
}
public String getIdentifier() {
return identifier;
}
public boolean hasSkyLight() {
return hasSkyLight;
}
@Override
public String toString() {
return String.format("%s:%s", getMod(), getIdentifier());
}
@Override
public int hashCode() {
return mod.hashCode() * identifier.hashCode();
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {

View File

@ -13,17 +13,13 @@
package de.bixilon.minosoft.data.mappings;
public record Enchantment(String mod, String identifier) {
public String getMod() {
return mod;
public class Enchantment extends ModIdentifier {
public Enchantment(String mod, String identifier) {
super(mod, identifier);
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", mod, identifier);
public Enchantment(String fullIdentifier) {
super(fullIdentifier);
}
}

View File

@ -13,48 +13,13 @@
package de.bixilon.minosoft.data.mappings;
public class Item {
final String mod;
final String identifier;
public class Item extends ModIdentifier {
public Item(String fullIdentifier) {
String[] split = fullIdentifier.split(":");
this.mod = split[0];
this.identifier = split[1];
super(fullIdentifier);
}
public Item(String mod, String identifier) {
this.mod = mod;
this.identifier = identifier;
}
public String getMod() {
return mod;
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", getMod(), getIdentifier());
}
@Override
public int hashCode() {
return mod.hashCode() * identifier.hashCode();
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
return true;
}
if (hashCode() != obj.hashCode()) {
return false;
}
Item their = (Item) obj;
return getIdentifier().equals(their.getIdentifier()) && getMod().equals(their.getMod());
super(mod, identifier);
}
}

View File

@ -13,17 +13,13 @@
package de.bixilon.minosoft.data.mappings;
public record MobEffect(String mod, String identifier) {
public String getMod() {
return mod;
public class MobEffect extends ModIdentifier {
public MobEffect(String mod, String identifier) {
super(mod, identifier);
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", getMod(), getIdentifier());
public MobEffect(String fullIdentifier) {
super(fullIdentifier);
}
}

View File

@ -0,0 +1,66 @@
/*
* Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program 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.
*
* This program 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 this program.If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.mappings;
public class ModIdentifier {
public static final String DEFAULT_MOD = "minecraft";
protected final String mod;
protected final String identifier;
public ModIdentifier(String mod, String identifier) {
this.mod = mod;
this.identifier = identifier;
}
public ModIdentifier(String fullIdentifier) {
String[] split = fullIdentifier.split(":");
if (split.length == 1) {
this.mod = DEFAULT_MOD;
this.identifier = fullIdentifier;
return;
}
this.mod = split[0];
this.identifier = split[1];
}
public String getMod() {
return mod;
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", mod, identifier);
}
@Override
public int hashCode() {
return mod.hashCode() * identifier.hashCode();
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
return true;
}
if (hashCode() != obj.hashCode()) {
return false;
}
Item their = (Item) obj;
return getIdentifier().equals(their.getIdentifier()) && getMod().equals(their.getMod());
}
}

View File

@ -13,17 +13,13 @@
package de.bixilon.minosoft.data.mappings;
public record Motive(String mod, String identifier) {
public String getMod() {
return mod;
public class Motive extends ModIdentifier {
public Motive(String mod, String identifier) {
super(mod, identifier);
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", getMod(), getIdentifier());
public Motive(String fullIdentifier) {
super(fullIdentifier);
}
}

View File

@ -13,50 +13,38 @@
package de.bixilon.minosoft.data.mappings.blocks;
import de.bixilon.minosoft.data.mappings.ModIdentifier;
import java.util.HashSet;
public class Block {
final String mod;
final String identifier;
public class Block extends ModIdentifier {
final BlockRotations rotation;
final HashSet<BlockProperties> properties;
public Block(String mod, String identifier, HashSet<BlockProperties> properties, BlockRotations rotation) {
this.mod = mod;
this.identifier = identifier;
super(mod, identifier);
this.properties = properties;
this.rotation = rotation;
}
public Block(String mod, String identifier, HashSet<BlockProperties> properties) {
this.mod = mod;
this.identifier = identifier;
super(mod, identifier);
this.properties = properties;
this.rotation = BlockRotations.NONE;
}
public Block(String mod, String identifier, BlockRotations rotation) {
this.mod = mod;
this.identifier = identifier;
super(mod, identifier);
this.properties = new HashSet<>();
this.rotation = rotation;
}
public Block(String mod, String identifier) {
this.mod = mod;
this.identifier = identifier;
super(mod, identifier);
this.properties = new HashSet<>();
this.rotation = BlockRotations.NONE;
}
public String getMod() {
return mod;
}
public String getIdentifier() {
return identifier;
}
public BlockRotations getRotation() {
return rotation;
}

View File

@ -13,17 +13,15 @@
package de.bixilon.minosoft.data.mappings.particle;
public record Particle(String mod, String identifier) {
public String getMod() {
return mod;
import de.bixilon.minosoft.data.mappings.ModIdentifier;
public class Particle extends ModIdentifier {
public Particle(String mod, String identifier) {
super(mod, identifier);
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", mod, identifier);
public Particle(String fullIdentifier) {
super(fullIdentifier);
}
}

View File

@ -13,17 +13,15 @@
package de.bixilon.minosoft.data.mappings.statistics;
public record Statistic(String mod, String identifier) {
public String getMod() {
return mod;
import de.bixilon.minosoft.data.mappings.ModIdentifier;
public class Statistic extends ModIdentifier {
public Statistic(String mod, String identifier) {
super(mod, identifier);
}
public String getIdentifier() {
return identifier;
}
@Override
public String toString() {
return String.format("%s:%s", mod, identifier);
public Statistic(String fullIdentifier) {
super(fullIdentifier);
}
}