Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented disguise state system, to make disguise appearance more c…
…ustomizable
- Loading branch information
Showing
16 changed files
with
438 additions
and
12 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/slimeknights/tmechworks/api/disguisestate/BasicDisguiseState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package slimeknights.tmechworks.api.disguisestate; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.state.IProperty; | ||
|
||
import java.util.Collection; | ||
|
||
public abstract class BasicDisguiseState<T extends Comparable<T>> extends DisguiseState<T> { | ||
private final IProperty<T> property; | ||
private final T defaultValue; | ||
|
||
public BasicDisguiseState(IProperty<T> property, T defaultValue) { | ||
this.property = property; | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
@Override | ||
public boolean canApplyTo(BlockState state) { | ||
return state.has(property); | ||
} | ||
|
||
@Override | ||
public BlockState apply(BlockState state, String value) { | ||
return state.with(property, getValueFrom(value)); | ||
} | ||
|
||
@Override | ||
public Collection<T> getAllowedValues() { | ||
return property.getAllowedValues(); | ||
} | ||
|
||
@Override | ||
public T getValueFrom(String value) { | ||
return property.parseValue(value).orElse(defaultValue); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/slimeknights/tmechworks/api/disguisestate/DisguiseState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package slimeknights.tmechworks.api.disguisestate; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.api.distmarker.OnlyIn; | ||
import slimeknights.tmechworks.TMechworks; | ||
|
||
import java.util.Collection; | ||
|
||
public abstract class DisguiseState<T extends Comparable<T>> { | ||
public abstract boolean canApplyTo(BlockState state); | ||
|
||
public abstract BlockState apply(BlockState state, String value); | ||
|
||
public abstract Collection<T> getAllowedValues(); | ||
public abstract T getValueFrom(String state); | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public ResourceLocation getIconSheet() { | ||
return new ResourceLocation(TMechworks.modId, "textures/gui/disguise_states.png"); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public final int unsafeGetIconFor(Object value) { | ||
return getIconFor((T) value); | ||
} | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public abstract int getIconFor(T value); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/slimeknights/tmechworks/api/disguisestate/DisguiseStates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package slimeknights.tmechworks.api.disguisestate; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.state.properties.BlockStateProperties; | ||
|
||
import java.util.ArrayList; | ||
|
||
public final class DisguiseStates { | ||
public static ArrayList<DisguiseState<?>> disguiseStates = new ArrayList<>(); | ||
|
||
public static final SlabTypeDisguiseState SLAB_TYPE = new SlabTypeDisguiseState(); | ||
|
||
public static DisguiseState<?> getForState(BlockState state) { | ||
for(DisguiseState<?> ds : DisguiseStates.disguiseStates) { | ||
if(ds.canApplyTo(state)) | ||
return ds; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static BlockState processDisguiseStates(BlockState state, String disguiseState) { | ||
if (state.has(BlockStateProperties.FACING)) | ||
state = state.with(BlockStateProperties.FACING, state.get(BlockStateProperties.FACING)); | ||
|
||
DisguiseState<?> ds = getForState(state); | ||
if(ds != null) { | ||
return ds.apply(state, disguiseState); | ||
} | ||
|
||
return state; | ||
} | ||
|
||
static { | ||
disguiseStates.add(SLAB_TYPE); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/slimeknights/tmechworks/api/disguisestate/SlabTypeDisguiseState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package slimeknights.tmechworks.api.disguisestate; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import net.minecraft.state.properties.BlockStateProperties; | ||
import net.minecraft.state.properties.SlabType; | ||
|
||
import java.util.Collection; | ||
|
||
public class SlabTypeDisguiseState extends BasicDisguiseState<SlabType> { | ||
public SlabTypeDisguiseState() { | ||
super(BlockStateProperties.SLAB_TYPE, SlabType.BOTTOM); | ||
} | ||
|
||
@Override | ||
public int getIconFor(SlabType value) { | ||
switch(value) { | ||
case BOTTOM: | ||
return 1; | ||
case TOP: | ||
return 2; | ||
case DOUBLE: | ||
return 3; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
@Override | ||
public Collection<SlabType> getAllowedValues() { | ||
// Overridden for specific order | ||
return ImmutableSet.of(SlabType.TOP, SlabType.DOUBLE, SlabType.BOTTOM); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.