Porting to Fabric/Yarn/1.14 part 1

This commit is contained in:
Sollace 2020-01-16 12:35:46 +01:00
parent f5f232241a
commit 2670d5cdb6
376 changed files with 8747 additions and 11478 deletions

View file

@ -1,106 +1,85 @@
buildscript { // Fabric build script
repositories { // 03/06/2019
jcenter() // https://github.com/FabricMC/fabric-example-mod/blob/master/build.gradle
maven {
name 'forge'
url 'http://files.minecraftforge.net/maven/'
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
name = 'sponge'
url = 'http://repo.spongepowered.org/maven'
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:' + project.forgeGradleVersion
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
def ver = "${project.buildType}${project.buildVersion}.${project.buildRevision}" plugins {
id 'java-library'
id 'fabric-loom' version '0.2.5-SNAPSHOT'
id 'maven-publish'
}
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
version = "${project.minecraft_version}-${project.version}"
if (project.release != 'RELEASE') {
version += "-${project.release}"
}
version = ver
group = project.group group = project.group
description = project.description description = project.displayname
archivesBaseName = project.name
minecraft { minecraft {
version = project.mcVersion + '-' + project.mcfVersion refmapName = 'unicopia.mixin.refmap.json'
mappings = project.mcMappings
runDir = 'run'
replace '@MODID@', project.modid
replace '@NAME@', project.name
replace '@AUTHOR@', project.author
replace '@VERSION@', ver
replace '@DESCRIPTION@', project.description
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
jei {
compileClasspath += main.compileClasspath
compileClasspath += main.output
}
external {
compileClasspath += main.compileClasspath
}
main {
compileClasspath += external.output
ext.refMap = project.refCore
}
} }
repositories { repositories {
flatDir { maven {
dir 'lib' name = 'minelp'
url = 'http://repo.minelittlepony-mod.com/maven/snapshot'
} }
maven { maven {
// location of the maven that hosts JEI files name = 'minelp-release'
name = "Progwml6 maven" url = 'http://repo.minelittlepony-mod.com/maven/release'
url = "http://dvs1.progwml6.com/files/maven"
}
maven {
// location of a maven mirror for JEI files, as a fallback
name = "ModMaven"
url = "modmaven.k-4u.nl"
} }
} }
// check for updates every build when on CI
if (System.env.CI) {
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
dependencies { dependencies {
deobfCompile('com.minelittlepony:jumpingcastle:1.12.2.1.0.0:universal') minecraft "com.mojang:minecraft:${project.minecraft_version}"
// compile against the JEI API but do not include it at runtime mappings "net.fabricmc:yarn:${project.yarn_mappings}"
deobfProvided "mezz.jei:jei_${project.mcVersion}:${project.jeiVersion}:api" modApi "net.fabricmc:fabric-loader:${project.loader_version}"
// at runtime, use the full JEI jar
runtime "mezz.jei:jei_${project.mcVersion}:${project.jeiVersion}" compileOnly "com.google.code.findbugs:jsr305:3.0.2"
//modApi "net.fabricmc.fabric-api:fabric-api-base:0.1.0+"
//modApi "net.fabricmc.fabric-api:fabric-events-lifecycle-v0:0.1.0+"
//modApi "net.fabricmc.fabric-api:fabric-resource-loader-v0:0.1.0+"
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modApi "com.minelittlepony:Kirin:${project.kirin_version}"
include "com.minelittlepony:Kirin:${project.kirin_version}"
modImplementation "io.github.prospector.modmenu:ModMenu:1.6.2-93"
} }
processResources { processResources {
def props = [ inputs.property "version", project.version
modid: project.modid,
name: project.title,
description: project.description,
version: ver,
revision: project.buildRevision,
mcversion: project.mcVersion,
author: project.author
]
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info' include "fabric.mod.json"
expand props expand "version": project.version
} }
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info' exclude "fabric.mod.json"
} }
} }
jar { tasks.withType(JavaCompile) {
from sourceSets.main.output options.encoding = "UTF-8"
from sourceSets.external.output }
from sourceSets.jei.output
baseName = "Unicopia-mc${project.mcVersion}" task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
} }

View file

@ -1,15 +1,20 @@
modid=unicopia org.gradle.jvmargs=-Xmx3G
title=Unicopia Redux org.gradle.daemon=false
group=com.minelittlepony.unicopia
author=Sollace # Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.14.4
yarn_mappings=1.14.4+build.2
loader_version=0.4.8+
# Mod Properties
group=com.minelittlepony
displayname=Unicopia Redux
authors=Sollace
description=Magical Abilities for Mine Little Pony! description=Magical Abilities for Mine Little Pony!
buildType=inDev version=3
buildVersion=2 release=SNAPSHOT
buildRevision=11
mcVersion=1.12.2 # Dependencies
mcfVersion=14.23.5.2824 fabric_version=0.3.0+
jeiVersion=4.15.0.268 kirin_version=1.14.4-1.4.4
mcMappings=stable_39
refCore=mixins.unicopia.refmap.json
forgeGradleVersion=2.3-SNAPSHOT
mixinGradleVersion=0.6-SNAPSHOT

Binary file not shown.

View file

@ -1,5 +1,6 @@
#Mon Apr 15 20:00:20 CAT 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip

11
settings.gradle Normal file
View file

@ -0,0 +1,11 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}
rootProject.name = 'Unicopia'

View file

@ -1,14 +0,0 @@
package baubles.api;
import org.apache.commons.lang3.NotImplementedException;
/*
* stub
*/
public enum BaubleType {
AMULET, RING, BELT, TRINKET, HEAD, BODY, CHARM;
public int[] getValidSlots() {
throw new NotImplementedException("getValidSlots");
}
}

View file

@ -1,20 +0,0 @@
package baubles.api;
import org.apache.commons.lang3.NotImplementedException;
import baubles.api.cap.IBaublesItemHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
/*
* stub
*/
public class BaublesApi {
public static IBaublesItemHandler getBaublesHandler(EntityPlayer player) {
throw new NotImplementedException("getBaublesHandler");
}
public static int isBaubleEquipped(EntityPlayer player, Item bauble) {
throw new NotImplementedException("isBaubleEquipped");
}
}

View file

@ -1,60 +0,0 @@
package baubles.api;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
/**
*
* This interface should be extended by items that can be worn in bauble slots
*
* @author Azanor
*/
public interface IBauble {
/**
* This method return the type of bauble this is.
* Type is used to determine the slots it can go into.
*/
public BaubleType getBaubleType(ItemStack itemstack);
/**
* This method is called once per tick if the bauble is being worn by a player
*/
public default void onWornTick(ItemStack itemstack, EntityLivingBase player) {
}
/**
* This method is called when the bauble is equipped by a player
*/
public default void onEquipped(ItemStack itemstack, EntityLivingBase player) {
}
/**
* This method is called when the bauble is unequipped by a player
*/
public default void onUnequipped(ItemStack itemstack, EntityLivingBase player) {
}
/**
* can this bauble be placed in a bauble slot
*/
public default boolean canEquip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
/**
* Can this bauble be removed from a bauble slot
*/
public default boolean canUnequip(ItemStack itemstack, EntityLivingBase player) {
return true;
}
/**
* Will bauble automatically sync to client if a change is detected in its NBT or damage values?
* Default is off, so override and set to true if you want to auto sync.
* This sync is not instant, but occurs every 10 ticks (.5 seconds).
*/
public default boolean willAutoSync(ItemStack itemstack, EntityLivingBase player) {
return false;
}
}

View file

@ -1,12 +0,0 @@
package baubles.api.cap;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
/*
* stub
*/
public interface IBaublesItemHandler extends IItemHandlerModifiable {
boolean isItemValidForSlot(int slot, ItemStack stack, EntityLivingBase player);
}

View file

@ -1,11 +0,0 @@
package com.minelittlepony;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class MineLittlePony {
public static MineLittlePony getInstance() {
throw new RuntimeException();
}
}

View file

@ -1,17 +0,0 @@
package com.minelittlepony.pony.data;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
// Stub
@SideOnly(Side.CLIENT)
public interface IPony {
static IPony forPlayer(AbstractClientPlayer player) {
return null;
}
PonyRace getRace(boolean ignorePony);
}

View file

@ -1,33 +0,0 @@
package com.minelittlepony.pony.data;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
// Stub
@SideOnly(Side.CLIENT)
public enum PonyRace {
HUMAN,
EARTH,
PEGASUS,
UNICORN,
ALICORN,
CHANGELING,
ZEBRA,
REFORMED_CHANGELING,
GRIFFIN,
HIPPOGRIFF,
BATPONY,
SEAPONY;
public boolean hasHorn() {
return false;
}
public boolean hasWings() {
return false;
}
public boolean isHuman() {
return this == HUMAN;
}
}

View file

@ -1,32 +0,0 @@
package com.minelittlepony.unicopia.jei;
import mezz.jei.api.gui.IDrawable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
class BlendedDrawable implements IDrawable {
private final IDrawable wrapped;
public BlendedDrawable(IDrawable wrapped) {
this.wrapped = wrapped;
}
@Override
public int getWidth() {
return wrapped.getWidth();
}
@Override
public int getHeight() {
return wrapped.getHeight();
}
@Override
public void draw(Minecraft minecraft, int xOffset, int yOffset) {
GlStateManager.enableBlend();
wrapped.draw(minecraft, xOffset, yOffset);
GlStateManager.disableBlend();
}
}

View file

@ -1,42 +0,0 @@
package com.minelittlepony.unicopia.jei;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.enchanting.SpecialRecipe;
import com.minelittlepony.unicopia.enchanting.SpellRecipe;
import com.minelittlepony.unicopia.init.UItems;
import com.minelittlepony.unicopia.spell.SpellRegistry;
import mezz.jei.api.IGuiHelper;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.IModRegistry;
import mezz.jei.api.ISubtypeRegistry;
import mezz.jei.api.JEIPlugin;
import mezz.jei.api.recipe.IRecipeCategoryRegistration;
@JEIPlugin
public class JEIUnicopia implements IModPlugin {
static IGuiHelper GUI_HELPER;
static final String RECIPE_UID = "unicopia:spellbook_2";
@Override
public void registerItemSubtypes(ISubtypeRegistry registry) {
registry.registerSubtypeInterpreter(UItems.spell, SpellRegistry::getKeyFromStack);
registry.registerSubtypeInterpreter(UItems.curse, SpellRegistry::getKeyFromStack);
}
@Override
public void registerCategories(IRecipeCategoryRegistration registry) {
registry.addRecipeCategories(new SpellbookCategory());
}
@Override
public void register(IModRegistry registry) {
GUI_HELPER = registry.getJeiHelpers().getGuiHelper();
registry.handleRecipes(SpellRecipe.class, SpellRecipeWrapper::new, RECIPE_UID);
registry.handleRecipes(SpecialRecipe.class, SpellRecipeWrapper::new, RECIPE_UID);
registry.addRecipes(Unicopia.getCraftingManager().getRecipes(), RECIPE_UID);
}
}

View file

@ -1,37 +0,0 @@
package com.minelittlepony.unicopia.jei;
import java.util.List;
import java.util.stream.Collectors;
import com.minelittlepony.unicopia.enchanting.AbstractSpecialRecipe;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.ingredients.VanillaTypes;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.item.ItemStack;
public class SpellRecipeWrapper implements IRecipeWrapper {
private final AbstractSpecialRecipe recipe;
public SpellRecipeWrapper(AbstractSpecialRecipe recipe) {
this.recipe = recipe;
}
public AbstractSpecialRecipe getRecipe() {
return recipe;
}
@Override
public void getIngredients(IIngredients ingredients) {
List<List<ItemStack>> ingreds = recipe.getSpellIngredients().stream().map(ingredient -> {
return ingredient.getStacks().collect(Collectors.toList());
}).collect(Collectors.toList());
ingredients.setInputLists(VanillaTypes.ITEM, ingreds);
ingredients.setOutput(VanillaTypes.ITEM, recipe.getRecipeOutput());
}
}

View file

@ -1,66 +0,0 @@
package com.minelittlepony.unicopia.jei;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.ingredients.VanillaTypes;
import mezz.jei.api.recipe.IRecipeCategory;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.util.ResourceLocation;
public class SpellbookCategory implements IRecipeCategory<IRecipeWrapper> {
@Override
public String getUid() {
return JEIUnicopia.RECIPE_UID;
}
@Override
public String getTitle() {
return "Spellbook";
}
@Override
public IDrawable getIcon() {
return JEIUnicopia.GUI_HELPER.drawableBuilder(
new ResourceLocation(Unicopia.MODID, "textures/items/spellbook.png"), 0, 0, 16, 16)
.setTextureSize(16, 16)
.build();
}
@Override
public String getModName() {
return "Unicopia";
}
@Override
public IDrawable getBackground() {
return new BlendedDrawable(
JEIUnicopia.GUI_HELPER.drawableBuilder(GuiSpellBook.spellBookGuiTextures, 405, 0, 105, 108)
.setTextureSize(512, 256)
.build());
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, IRecipeWrapper recipeWrapper, @Deprecated IIngredients unused) {
recipeLayout.setShapeless();
IGuiItemStackGroup stacks = recipeLayout.getItemStacks();
stacks.init(0, true, 29, 3);
stacks.init(1, true, 3, 46);
stacks.init(2, true, 30, 86);
stacks.init(3, true, 80, 72);
stacks.init(4, true, 82, 15);
stacks.init(5, false, 46, 44);
stacks.set(unused);
stacks.set(5, unused.getOutputs(VanillaTypes.ITEM).get(0));
}
}

View file

@ -1,64 +0,0 @@
package com.minelittlepony.gui;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
public class Button extends GuiButton implements IGuiTooltipped<Button> {
private int tipX = 0;
private int tipY = 0;
protected IGuiAction<Button> action;
private List<String> tooltip = null;
@SuppressWarnings("unchecked")
public Button(int x, int y, int width, int height, String label, IGuiAction<? extends Button> callback) {
super(5000, x, y, width, height, GameGui.format(label));
action = (IGuiAction<Button>)callback;
}
public Button setEnabled(boolean enable) {
enabled = enable;
return this;
}
@Override
public Button setTooltip(List<String> tooltip) {
this.tooltip = tooltip;
return this;
}
protected List<String> getTooltip() {
return tooltip;
}
@Override
public void renderToolTip(Minecraft mc, int mouseX, int mouseY) {
List<String> tooltip = getTooltip();
if (visible && isMouseOver() && tooltip != null) {
mc.currentScreen.drawHoveringText(tooltip, mouseX + tipX, mouseY + tipY);
}
}
@Override
public Button setTooltipOffset(int x, int y) {
tipX = x;
tipY = y;
return this;
}
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
if (super.mousePressed(mc, mouseX, mouseY)) {
action.perform(this);
return true;
}
return false;
}
}

View file

@ -1,62 +0,0 @@
package com.minelittlepony.gui;
import org.apache.commons.lang3.text.WordUtils;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.SoundEvent;
public abstract class GameGui extends GuiScreen {
protected static String format(String string, Object... pars) {
return string == null ? null : I18n.format(string, pars);
}
/**
* Formats a translation string and returns it in a list wrapped to a given width.
* This can be safely used in initGui, where the fontRenderer is often still null.
*/
protected List<String> formatMultiLine(String string, int width, Object...pars) {
FontRenderer fr = fontRenderer;
if (fr == null) {
fr = Minecraft.getMinecraft().fontRenderer;
}
return fr.listFormattedStringToWidth(format(string, pars), width);
}
protected void playSound(SoundEvent event) {
mc.getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(event, 1));
}
/**
* Converts a given string to title case regardless of initial case.
*/
protected static String toTitleCase(String string) {
return WordUtils.capitalize(string.toLowerCase());
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawContents(mouseX, mouseY, partialTicks);
postDrawContents(mouseX, mouseY, partialTicks);
}
protected void drawContents(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
}
protected void postDrawContents(int mouseX, int mouseY, float partialTicks) {
buttonList.forEach(button -> {
if (button instanceof IGuiTooltipped) {
((IGuiTooltipped<?>)button).renderToolTip(mc, mouseX, mouseY);
}
});
}
}

View file

@ -1,15 +0,0 @@
package com.minelittlepony.gui;
/**
* Response actions for UI events.
*/
@FunctionalInterface
public interface IGuiAction<T> {
/**
* Performs this action now.
*
* @param value New Value of the field being changed
* @return Adjusted value the field must take on
*/
void perform(T sender);
}

View file

@ -1,15 +0,0 @@
package com.minelittlepony.gui;
/**
* Response actions for UI events.
*/
@FunctionalInterface
public interface IGuiCallback<T> {
/**
* Performs this action now.
*
* @param value New Value of the field being changed
* @return Adjusted value the field must take on
*/
T perform(T value);
}

View file

@ -1,20 +0,0 @@
package com.minelittlepony.gui;
import net.minecraft.client.Minecraft;
import com.google.common.base.Splitter;
import java.util.List;
public interface IGuiTooltipped<T extends IGuiTooltipped<T>> {
T setTooltip(List<String> tooltip);
T setTooltipOffset(int x, int y);
default T setTooltip(String tooltip) {
return setTooltip(Splitter.onPattern("\r?\n|\\\\n").splitToList(GameGui.format(tooltip)));
}
void renderToolTip(Minecraft mc, int mouseX, int mouseY);
}

View file

@ -1,44 +0,0 @@
package com.minelittlepony.gui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
/**
* A simple label for drawing text to a gui screen.
*
* @author Sollace
*
*/
public class Label extends GuiButton {
private boolean center;
private int color;
private String text;
public Label(int x, int y, String translationString, int color) {
this(x, y, translationString, color, false);
}
public Label(int x, int y, String translationString, int color, boolean center) {
super(0, x, y, "");
this.color = color;
this.center = center;
this.text = translationString;
}
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
return false;
}
@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
if (center) {
drawCenteredString(mc.fontRenderer, GameGui.format(text), x, y, color);
} else {
drawString(mc.fontRenderer, GameGui.format(text), x, y, color);
}
}
}

View file

@ -1,44 +0,0 @@
package com.minelittlepony.gui;
import net.minecraft.client.gui.GuiSlider;
import net.minecraft.client.gui.GuiPageButtonList.GuiResponder;
/**
* A slider for sliding.
*
* @author Sollace
*
*/
public class Slider extends GuiSlider {
private static Responder callback;
public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, IGuiCallback<Float> action) {
super(callback = new Responder(action), 0, x, y, "", minIn, maxIn, defaultValue, formatter);
callback.owner = this;
callback = null;
}
private static final class Responder implements GuiResponder {
private final IGuiCallback<Float> action;
private Slider owner;
private Responder(IGuiCallback<Float> callback) {
action = callback;
}
@Override
public void setEntryValue(int id, boolean value) { }
@Override
public void setEntryValue(int id, float value) {
owner.setSliderValue(action.perform(value), false);
}
@Override
public void setEntryValue(int id, String value) { }
}
}

View file

@ -1,32 +0,0 @@
package com.minelittlepony.render.model;
import java.util.ArrayList;
import java.util.List;
import com.minelittlepony.util.render.Box;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.PositionTextureVertex;
import net.minecraft.client.model.TexturedQuad;
import net.minecraft.client.renderer.BufferBuilder;
public class ModelQuads extends Box<ModelRenderer> {
public ModelQuads(ModelRenderer renderer) {
super(renderer, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
protected List<TexturedQuad> quadList = new ArrayList<TexturedQuad>();
public ModelQuads addFace(PositionTextureVertex... vertices) {
quadList.add(new TexturedShape2d(vertices));
return this;
}
public void render(BufferBuilder renderer, float scale) {
for (TexturedQuad i : quadList) {
i.draw(renderer, scale);
}
}
}

View file

@ -1,50 +0,0 @@
package com.minelittlepony.render.model;
import net.minecraft.client.model.PositionTextureVertex;
import net.minecraft.client.model.TexturedQuad;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.Vec3d;
public class TexturedShape2d extends TexturedQuad {
protected boolean invertNormal;
public TexturedShape2d(PositionTextureVertex... vertices) {
super(vertices);
}
public TexturedShape2d(PositionTextureVertex[] vertices, int texcoordU1, int texcoordV1, int texcoordU2, int texcoordV2, float textureWidth, float textureHeight) {
super(vertices, texcoordU1, texcoordV1, texcoordU2, texcoordV2, textureWidth, textureHeight);
}
public TexturedShape2d setInvertNormal() {
invertNormal = true;
return this;
}
public void drawQuad(BufferBuilder renderer, float scale) {
Vec3d vec3d = vertexPositions[1].vector3D.subtractReverse(vertexPositions[0].vector3D);
Vec3d vec3d1 = vertexPositions[1].vector3D.subtractReverse(vertexPositions[2].vector3D);
Vec3d vec3d2 = vec3d1.crossProduct(vec3d).normalize();
float f = (float)vec3d2.x;
float f1 = (float)vec3d2.y;
float f2 = (float)vec3d2.z;
if (invertNormal) {
f = -f;
f1 = -f1;
f2 = -f2;
}
renderer.begin(7, DefaultVertexFormats.OLDMODEL_POSITION_TEX_NORMAL);
for (int i = 0; i < nVertices; ++i) {
PositionTextureVertex positiontexturevertex = vertexPositions[i];
renderer.pos(positiontexturevertex.vector3D.x * (double)scale, positiontexturevertex.vector3D.y * (double)scale, positiontexturevertex.vector3D.z * (double)scale).tex((double)positiontexturevertex.texturePositionX, (double)positiontexturevertex.texturePositionY).normal(f, f1, f2).endVertex();
}
Tessellator.getInstance().draw();
}
}

View file

@ -1,88 +1,63 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.forgebullshit.FUF; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.hud.UHud; import com.minelittlepony.unicopia.client.gui.UHud;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.entity.player.ICamera;
import com.minelittlepony.unicopia.player.IView; import com.mojang.blaze3d.platform.GlStateManager;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.client.Minecraft; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.GuiShareToLan;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.client.event.EntityViewRenderEvent;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.relauncher.Side;
@EventBusSubscriber(value = Side.CLIENT, modid = Unicopia.MODID)
class ClientHooks { class ClientHooks {
// This fixes lighting errors on the armour slots. // This fixes lighting errors on the armour slots.
// #MahjongPls // #MahjongPls
@FUF(reason = "Forge should fix this. Cancelling their event skips neccessary state resetting at the end of the render method") public static void postEntityRender() {
@SubscribeEvent GlStateManager.enableAlphaTest();
public static void postEntityRender(RenderLivingEvent.Post<?> event) {
GlStateManager.enableAlpha();
UClient.instance().postRenderEntity(event.getEntity()); UClient.instance().postRenderEntity(event.getEntity());
} }
@SubscribeEvent public static void preEntityRender() {
public static void preEntityRender(RenderLivingEvent.Pre<?> event) {
if (UClient.instance().renderEntity(event.getEntity(), event.getPartialRenderTick())) { if (UClient.instance().renderEntity(event.getEntity(), event.getPartialRenderTick())) {
event.setCanceled(true); event.setCanceled(true);
} }
} }
@SubscribeEvent
public static void onDisplayGui(GuiScreenEvent.InitGuiEvent.Post event) { public static void onDisplayGui(GuiScreenEvent.InitGuiEvent.Post event) {
if (event.getGui() instanceof GuiOptions || event.getGui() instanceof GuiShareToLan) { if (event.getGui() instanceof GuiOptions || event.getGui() instanceof GuiShareToLan) {
UnicopiaClient.addUniButton(event.getButtonList()); UnicopiaClient.addUniButton(event.getButtonList());
} }
} }
@SubscribeEvent
public static void onGameTick(TickEvent.ClientTickEvent event) { public static void onGameTick(TickEvent.ClientTickEvent event) {
if (event.phase == Phase.END) { if (event.phase == Phase.END) {
UClient.instance().tick(); UClient.instance().tick();
} }
} }
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void beforePreRenderHud(RenderGameOverlayEvent.Pre event) { public static void beforePreRenderHud(RenderGameOverlayEvent.Pre event) {
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
if (event.getType() != ElementType.ALL) { if (event.getType() != ElementType.ALL) {
IPlayer player = UClient.instance().getIPlayer(); IPlayer player = UClient.instance().getIPlayer();
if (player != null && Minecraft.getMinecraft().world != null) { if (player != null && MinecraftClient.getInstance().world != null) {
UHud.instance.repositionElements(player, event.getResolution(), event.getType(), true); UHud.instance.repositionElements(player, event.getResolution(), event.getType(), true);
} }
} }
} }
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public static void afterPreRenderHud(RenderGameOverlayEvent.Pre event) { public static void afterPreRenderHud(RenderGameOverlayEvent.Pre event) {
if (event.isCanceled()) { if (event.isCanceled()) {
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
} }
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void postRenderHud(RenderGameOverlayEvent.Post event) { public static void postRenderHud(RenderGameOverlayEvent.Post event) {
if (event.getType() == ElementType.ALL) { if (event.getType() == ElementType.ALL) {
IPlayer player = UClient.instance().getIPlayer(); IPlayer player = UClient.instance().getIPlayer();
if (player != null && Minecraft.getMinecraft().world != null) { if (player != null && MinecraftClient.getInstance().world != null) {
UHud.instance.renderHud(player, event.getResolution()); UHud.instance.renderHud(player, event.getResolution());
} }
} }
@ -90,18 +65,21 @@ class ClientHooks {
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@SubscribeEvent public static void registerItemColours(ColorHandlerEvent.Item event) {
public static void modifyFOV(FOVUpdateEvent event) { UItems.registerColors(event.getItemColors());
event.setNewfov(PlayerSpeciesList.instance().getPlayer(event.getEntity()).getCamera().calculateFieldOfView(event.getFov())); UBlocks.registerColors(event.getItemColors(), event.getBlockColors());
}
public static void modifyFOV(FOVUpdateEvent event) {
event.setNewfov(SpeciesList.instance().getPlayer(event.getEntity()).getCamera().calculateFieldOfView(event.getFov()));
} }
@SubscribeEvent
public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) { public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) {
IPlayer player = UClient.instance().getIPlayer(); IPlayer player = UClient.instance().getIPlayer();
if (player != null) { if (player != null) {
IView view = player.getCamera(); ICamera view = player.getCamera();
event.setRoll(view.calculateRoll()); event.setRoll(view.calculateRoll());
event.setPitch(view.calculatePitch(event.getPitch())); event.setPitch(view.calculatePitch(event.getPitch()));

View file

@ -3,8 +3,8 @@ package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.entity.EntityCloud; import com.minelittlepony.unicopia.entity.EntityCloud;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
public enum CloudType { public enum CloudType {
NORMAL, NORMAL,
@ -20,22 +20,22 @@ public enum CloudType {
return true; return true;
} }
if (e instanceof EntityPlayer) { if (e instanceof PlayerEntity) {
if (this == PACKED) { if (this == PACKED) {
return true; return true;
} }
return Predicates.INTERACT_WITH_CLOUDS.test((EntityPlayer)e) return Predicates.INTERACT_WITH_CLOUDS.test((PlayerEntity)e)
|| (Predicates.MAGI.test(e) && EntityCloud.getFeatherEnchantStrength((EntityPlayer)e) > 0); || (Predicates.MAGI.test(e) && EntityCloud.getFeatherEnchantStrength((PlayerEntity)e) > 0);
} }
if (e instanceof EntityItem) { if (e instanceof ItemEntity) {
return Predicates.ITEM_INTERACT_WITH_CLOUDS.test((EntityItem)e); return Predicates.ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)e);
} }
if (e instanceof EntityCloud && e.isRiding()) { if (e instanceof EntityCloud && e.hasVehicle()) {
return canInteract(e.getRidingEntity()); return canInteract(e.getVehicle());
} }
return false; return false;

View file

@ -1,151 +0,0 @@
package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.init.UBlocks;
import com.minelittlepony.util.fixers.BlockFixer;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.IFixableData;
import net.minecraftforge.common.util.CompoundDataFixer;
import net.minecraftforge.common.util.ModFixs;
public class Fixes {
static void init(DataFixer fixer) {
CompoundDataFixer forgeDataFixer = (CompoundDataFixer)fixer;
try {
ModFixs modfix = forgeDataFixer.init(Unicopia.MODID, 1343);
modfix.registerFix(FixTypes.CHUNK, new FixCloudBlocks());
modfix.registerFix(FixTypes.ITEM_INSTANCE, new FixCloudItems());
modfix.registerFix(FixTypes.ITEM_INSTANCE, new FixItems());
} catch (Throwable ignored) {
// no way to check if our fixer is already registered.
// so just do it anyway and ignore the error.
// @FUF(reason = "FUF")
}
}
static class FixItems implements IFixableData {
private final String[] cloud_spawners = new String[] {
"unicopia:racing_cloud_spawner",
"unicopia:construction_cloud_spawner",
"unicopia:wild_cloud_spawner"
};
@Override
public int getFixVersion() {
return 1343;
}
@Override
public NBTTagCompound fixTagCompound(NBTTagCompound compound) {
if (compound.hasKey("id", 8)) {
String id = compound.getString("id");
int damage = compound.hasKey("Damage", 3) ? compound.getInteger("Damage") : 0;
if (id == "unicopia:cloud") {
id = cloud_spawners[damage % cloud_spawners.length];
damage = 0;
}
if (id == "unicopia:tomato" && damage == 1) {
id = "unicopia:rotten_tomato";
damage = 0;
}
if (id == "unicopia:cloudsdale_tomato" && damage == 1) {
id = "unicopia:rotten_cloudsdale_tomato";
damage = 0;
}
compound.setString("id", id);
compound.setInteger("Damage", 0);
}
return compound;
}
}
static class FixCloudItems implements IFixableData {
@Override
public int getFixVersion() {
return 1342;
}
@Override
public NBTTagCompound fixTagCompound(NBTTagCompound compound) {
if (compound.hasKey("id", 8) && compound.hasKey("Damage", 3)) {
String id = compound.getString("id");
int damage = compound.getInteger("Damage");
if (id == "unicopia:cloud_block") {
if (damage == 1) {
damage = 0;
id = "unicopia:packed_cloud_block";
} else if (damage == 2) {
damage = 0;
id = "unicopia:enchanted_cloud_block";
}
}
if (id == "unicopia:cloud_slab") {
if (damage == 1) {
damage = 0;
id = "unicopia:packed_cloud_slab";
} else if (damage == 2) {
damage = 0;
id = "unicopia:enchanted_cloud_slab";
}
}
compound.setString("id", id);
compound.setInteger("Damage", 0);
}
return compound;
}
}
static class FixCloudBlocks extends BlockFixer {
@Override
public int getFixVersion() {
return 1342;
}
@Override
protected IBlockState fixBlockState(int id, int metadata) {
if (id == Block.getIdFromBlock(UBlocks.normal_cloud) && metadata != 0) {
if (metadata == 1) {
return UBlocks.packed_cloud.getDefaultState();
}
if (metadata == 2) {
return UBlocks.enchanted_cloud.getDefaultState();
}
}
int shifted = metadata % 8;
if (id == Block.getIdFromBlock(UBlocks.cloud_slab) && shifted != 0) {
if (shifted == 1) {
return UBlocks.packed_cloud_slab.getStateFromMeta(metadata - shifted);
}
if (shifted == 2) {
return UBlocks.enchanted_cloud_slab.getStateFromMeta(metadata - shifted);
}
}
return null;
}
}
}

View file

@ -1,11 +1,6 @@
package com.minelittlepony.unicopia.extern; package com.minelittlepony.unicopia;
import com.minelittlepony.MineLittlePony; import net.minecraft.client.MinecraftClient;
import com.minelittlepony.pony.data.IPony;
import com.minelittlepony.pony.data.PonyRace;
import com.minelittlepony.unicopia.Race;
import net.minecraft.client.Minecraft;
public final class MineLP { public final class MineLP {
private static boolean checkComplete; private static boolean checkComplete;
@ -34,7 +29,7 @@ public final class MineLP {
return Race.HUMAN; return Race.HUMAN;
} }
switch (IPony.forPlayer(Minecraft.getMinecraft().player).getRace(false)) { switch (IPony.forPlayer(MinecraftClient.getInstance().player).getRace(false)) {
case ALICORN: case ALICORN:
return Race.ALICORN; return Race.ALICORN;
case CHANGELING: case CHANGELING:

View file

@ -1,50 +1,49 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
public final class Predicates { public final class Predicates {
public static final Predicate<EntityPlayer> INTERACT_WITH_CLOUDS = player -> { public static final Predicate<PlayerEntity> INTERACT_WITH_CLOUDS = player -> {
return player != null && PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canInteractWithClouds(); return player != null && SpeciesList.instance().getPlayer(player).getSpecies().canInteractWithClouds();
}; };
public static final Predicate<Entity> MAGI = entity -> { public static final Predicate<Entity> MAGI = entity -> {
return entity instanceof EntityPlayer && PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).getPlayerSpecies().canCast(); return entity instanceof PlayerEntity && SpeciesList.instance().getPlayer((PlayerEntity)entity).getSpecies().canCast();
}; };
public static final Predicate<Entity> ITEMS = entity -> { public static final Predicate<Entity> ITEMS = entity -> {
return entity instanceof EntityItem && entity.isEntityAlive() && entity.ticksExisted > 1; return entity instanceof ItemEntity && entity.isAlive() && entity.age > 1;
}; };
public static final Predicate<EntityItem> ITEM_INTERACT_WITH_CLOUDS = item -> { public static final Predicate<ItemEntity> ITEM_INTERACT_WITH_CLOUDS = item -> {
return ITEMS.test(item) && PlayerSpeciesList.instance().getEntity(item).getPlayerSpecies().canInteractWithClouds(); return ITEMS.test(item) && SpeciesList.instance().getEntity(item).getSpecies().canInteractWithClouds();
}; };
public static final Predicate<Entity> ENTITY_INTERACT_WITH_CLOUDS = entity -> { public static final Predicate<Entity> ENTITY_INTERACT_WITH_CLOUDS = entity -> {
return entity != null && ( return entity != null && (
(entity instanceof EntityPlayer && INTERACT_WITH_CLOUDS.test((EntityPlayer)entity)) (entity instanceof PlayerEntity && INTERACT_WITH_CLOUDS.test((PlayerEntity)entity))
|| (entity instanceof EntityItem && ITEM_INTERACT_WITH_CLOUDS.test((EntityItem)entity)) || (entity instanceof ItemEntity && ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)entity))
); );
}; };
public static final Predicate<Entity> BUGGY = entity -> { public static final Predicate<Entity> BUGGY = entity -> {
return entity instanceof EntityPlayer return entity instanceof PlayerEntity
&& PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity).getPlayerSpecies() == Race.CHANGELING; && SpeciesList.instance().getPlayer((PlayerEntity)entity).getSpecies() == Race.CHANGELING;
}; };
public static EntityPlayer getPlayerFromEntity(Entity entity) { public static PlayerEntity getPlayerFromEntity(Entity entity) {
if (entity instanceof EntityPlayer) { if (entity instanceof PlayerEntity) {
return (EntityPlayer) entity; return (PlayerEntity) entity;
} }
if (entity instanceof EntityItem) { if (entity instanceof ItemEntity) {
EntityItem item = (EntityItem)entity; ItemEntity item = (ItemEntity)entity;
if (item.getOwner() != null) { if (item.getOwner() != null) {
return item.getEntityWorld().getPlayerEntityByName(item.getOwner()); return item.getEntityWorld().getPlayerByUuid(item.getOwner());
} }
} }

View file

@ -0,0 +1,83 @@
package com.minelittlepony.unicopia;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.UConfig;
import com.minelittlepony.unicopia.ducks.IRaceContainerHolder;
import com.minelittlepony.unicopia.entity.IEntity;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
public class SpeciesList {
private static final SpeciesList instance = new SpeciesList();
public static SpeciesList instance() {
return instance;
}
public boolean whiteListRace(Race race) {
boolean result = UConfig.instance().getSpeciesWhiteList().add(race);
UConfig.instance().save();
return result;
}
public boolean unwhiteListRace(Race race) {
boolean result = UConfig.instance().getSpeciesWhiteList().remove(race);
UConfig.instance().save();
return result;
}
public boolean speciesPermitted(Race race, PlayerEntity sender) {
if (race.isOp() && (sender == null || !sender.abilities.creativeMode)) {
return false;
}
return race.isDefault() || UConfig.instance().getSpeciesWhiteList().isEmpty() || UConfig.instance().getSpeciesWhiteList().contains(race);
}
public Race validate(Race race, PlayerEntity sender) {
if (!speciesPermitted(race, sender)) {
race = Race.EARTH;
if (!speciesPermitted(race, sender)) {
race = Race.HUMAN;
}
}
return race;
}
@Nullable
public IPlayer getPlayer(@Nullable PlayerEntity player) {
return this.<IPlayer>getEntity(player);
}
@Nullable
public IPlayer getPlayer(UUID playerId) {
return getPlayer(IPlayer.fromServer(playerId));
}
@Nullable
public <T extends IEntity> T getEntity(Entity entity) {
return this.<Entity, T>getForEntity(entity)
.map(IRaceContainerHolder::getRaceContainer)
.orElse(null);
}
@SuppressWarnings("unchecked")
public <E extends Entity, T extends IEntity> Optional<IRaceContainerHolder<T>> getForEntity(Entity entity) {
if (entity instanceof IRaceContainerHolder) {
return Optional.of(((IRaceContainerHolder<T>)entity));
}
return Optional.empty();
}
}

View file

@ -0,0 +1,124 @@
package com.minelittlepony.unicopia;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.BlockAlfalfa;
import com.minelittlepony.unicopia.block.ChiselledChitinBlock;
import com.minelittlepony.unicopia.block.ChitinBlock;
import com.minelittlepony.unicopia.block.FruitLeavesBlock;
import com.minelittlepony.unicopia.block.GlowingGemBlock;
import com.minelittlepony.unicopia.block.BlockGrowingCuccoon;
import com.minelittlepony.unicopia.block.HiveWallBlock;
import com.minelittlepony.unicopia.block.IColourful;
import com.minelittlepony.unicopia.block.SlimeLayerBlock;
import com.minelittlepony.unicopia.block.StickBlock;
import com.minelittlepony.unicopia.block.BlockCloudAnvil;
import com.minelittlepony.unicopia.block.BlockCloudBanister;
import com.minelittlepony.unicopia.block.BlockCloudSlab;
import com.minelittlepony.unicopia.block.BlockCloudStairs;
import com.minelittlepony.unicopia.block.BlockDutchDoor;
import com.minelittlepony.unicopia.block.SugarBlock;
import com.minelittlepony.unicopia.block.UPot;
import com.minelittlepony.unicopia.block.USapling;
import com.minelittlepony.unicopia.block.BlockTomatoPlant;
import com.minelittlepony.unicopia.item.ItemApple;
import com.minelittlepony.unicopia.block.BlockCloudDoor;
import com.minelittlepony.unicopia.block.BlockDiamondDoor;
import com.minelittlepony.unicopia.block.BlockCloudFarm;
import com.minelittlepony.unicopia.block.BlockCloudFence;
import com.minelittlepony.unicopia.block.BlockCloud;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.Material;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
public class UBlocks {
public static final BlockCloud normal_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.NORMAL, Unicopia.MODID, "cloud_block"));
public static final BlockCloud enchanted_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.ENCHANTED, Unicopia.MODID, "enchanted_cloud_block"));
public static final BlockCloud packed_cloud = register(new BlockCloud(UMaterials.cloud, CloudType.PACKED, Unicopia.MODID, "packed_cloud_block"));
public static final BlockCloudStairs cloud_stairs = register(new BlockCloudStairs(normal_cloud.getDefaultState(), Unicopia.MODID, "cloud_stairs"));
public static final BlockCloudSlab.Single<?> cloud_slab = register(new BlockCloudSlab.Single<>(normal_cloud, UMaterials.cloud, Unicopia.MODID, "cloud_slab"));
public static final BlockCloudSlab.Single<?> enchanted_cloud_slab = register(new BlockCloudSlab.Single<>(enchanted_cloud, UMaterials.cloud, Unicopia.MODID, "enchanted_cloud_slab"));
public static final BlockCloudSlab.Single<?> packed_cloud_slab = register(new BlockCloudSlab.Single<>(enchanted_cloud, UMaterials.cloud, Unicopia.MODID, "packed_cloud_slab"));
public static final BlockCloudDoor mist_door = register(new BlockCloudDoor(UMaterials.cloud, Unicopia.MODID, "mist_door", () -> UItems.mist_door));
public static final Block library_door = register(new BlockDutchDoor(Material.WOOD, Unicopia.MODID, "library_door", () -> UItems.library_door)
.setSoundType(SoundType.WOOD)
.setHardness(3));
public static final Block bakery_door = register(new BlockDutchDoor(Material.WOOD, Unicopia.MODID, "bakery_door", () -> UItems.bakery_door)
.setSoundType(SoundType.WOOD)
.setHardness(3));
public static final Block diamond_door = register(new BlockDiamondDoor(Unicopia.MODID, "diamond_door", () -> UItems.diamond_door));
public static final GlowingGemBlock enchanted_torch = register(new GlowingGemBlock(Unicopia.MODID, "enchanted_torch"));
public static final BlockCloudAnvil anvil = register(new BlockCloudAnvil(Unicopia.MODID, "anvil"));
public static final BlockCloudFence cloud_fence = register(new BlockCloudFence(UMaterials.cloud, CloudType.NORMAL, Unicopia.MODID, "cloud_fence"));
public static final BlockCloudBanister cloud_banister = register(new BlockCloudBanister(UMaterials.cloud, Unicopia.MODID, "cloud_banister"));
public static final BlockAlfalfa alfalfa = register(new BlockAlfalfa(Unicopia.MODID, "alfalfa"));
public static final StickBlock stick = register(new StickBlock(Unicopia.MODID, "stick"));
public static final BlockTomatoPlant tomato_plant = register(new BlockTomatoPlant(Unicopia.MODID, "tomato_plant"));
public static final BlockCloudFarm cloud_farmland = register(new BlockCloudFarm(Unicopia.MODID, "cloud_farmland"));
public static final HiveWallBlock hive = register(new HiveWallBlock(Unicopia.MODID, "hive"));
public static final ChitinBlock chitin = register(new ChitinBlock(Unicopia.MODID, "chitin_block"));
public static final Block chissled_chitin = register(new ChiselledChitinBlock(Unicopia.MODID, "chissled_chitin"));
public static final BlockGrowingCuccoon cuccoon = register(new BlockGrowingCuccoon(Unicopia.MODID, "cuccoon"));
public static final SlimeLayerBlock slime_layer = register(new SlimeLayerBlock(Unicopia.MODID, "slime_layer"));
public static final Block sugar_block = register(new SugarBlock(Unicopia.MODID, "sugar_block"));
public static final UPot flower_pot = register(new UPot(), "flower_pot");
public static final USapling apple_tree = register(new USapling(Unicopia.MODID, "apple_sapling")
.setTreeGen((w, s, m) -> new WorldGenTrees(true, 5, Blocks.LOG.getDefaultState(), UBlocks.apple_leaves.getDefaultState(), false));
public static final Block apple_leaves = register(new FruitLeavesBlock()
.growthChance(1200)
.tint(0xFFEE81)
.fruit(ItemApple::getRandomItemStack)
.compost(w -> new ItemStack(UItems.rotten_apple))), "apple_leaves");
private static <T extends Block> T register(T block) {
return block;
}
static void registerColors(ItemColors items, BlockColors blocks) {
items.register((stack, tint) -> {
@SuppressWarnings("deprecation")
BlockState state = ((BlockItem)stack.getItem()).getBlock().getStateFromMeta(stack.getMetadata());
return blocks.getColorMultiplier(state, null, null, tint);
}, apple_leaves);
blocks.register((state, world, pos, tint) -> {
Block block = state.getBlock();
if (block instanceof IColourful) {
return ((IColourful)block).getCustomTint(state, tint);
}
if (world != null && pos != null) {
return BiomeColors.getGrassColor(world, pos);
}
return GrassColors.getColor(0.5D, 1);
}, apple_leaves);
}
static void bootstrap() { }
}

View file

@ -6,25 +6,20 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.entity.EntityFakeServerPlayer; import com.minelittlepony.unicopia.entity.EntityFakeServerPlayer;
import com.minelittlepony.unicopia.forgebullshit.FUF; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.IInteractionObject;
import net.minecraft.world.WorldServer;
public class UClient { public class UClient {
private static UClient instance; private static UClient instance;
public static boolean isClientSide() { public static boolean isClientSide() {
return net.minecraftforge.fml.common.FMLCommonHandler.instance().getSide().isClient(); return false;
} }
@FUF(reason = "Forced client Separation")
public static UClient instance() { public static UClient instance() {
if (instance == null) { if (instance == null) {
if (isClientSide()) { if (isClientSide()) {
@ -37,30 +32,26 @@ public class UClient {
return instance; return instance;
} }
@FUF(reason = "Forced client Separation") public void displayGuiToPlayer(PlayerEntity player, InteractionObject inventory) {
public void displayGuiToPlayer(EntityPlayer player, IInteractionObject inventory) {
player.displayGui(inventory); player.displayGui(inventory);
} }
@FUF(reason = "Forced client Separation")
@Nullable @Nullable
public EntityPlayer getPlayer() { public PlayerEntity getPlayer() {
return null; return null;
} }
@Nullable @Nullable
public IPlayer getIPlayer() { public IPlayer getIPlayer() {
return PlayerSpeciesList.instance().getPlayer(getPlayer()); return SpeciesList.instance().getPlayer(getPlayer());
} }
@FUF(reason = "Forced client Separation")
@Nullable @Nullable
public EntityPlayer getPlayerByUUID(UUID playerId) { public PlayerEntity getPlayerByUUID(UUID playerId) {
return null; return null;
} }
@FUF(reason = "Forced client Separation") public boolean isClientPlayer(@Nullable PlayerEntity player) {
public boolean isClientPlayer(@Nullable EntityPlayer player) {
return false; return false;
} }
@ -74,7 +65,7 @@ public class UClient {
* Returns an implementation of EntityPlayer appropriate to the side being called on. * Returns an implementation of EntityPlayer appropriate to the side being called on.
*/ */
@Nonnull @Nonnull
public EntityPlayer createPlayer(Entity observer, GameProfile profile) { public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
return new EntityFakeServerPlayer((WorldServer)observer.world, profile); return new EntityFakeServerPlayer((WorldServer)observer.world, profile);
} }

View file

@ -0,0 +1,31 @@
package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.Unicopia;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.potion.Potion;
public class UEffects {
public static final DamageSource food_poisoning = new DamageSource("food_poisoning").bypassesArmor();
public static final StatusEffect FOOD_POISONING = new UPotion(Unicopia.MODID, "food_poisoning", true, 3484199)
.setIconIndex(3, 1)
.setSilent()
.setEffectiveness(0.25)
.setApplicator((p, e, i) -> {
StatusEffectInstance nausea = e.getActivePotionEffect(StatusEffects.NAUSEA);
if (nausea == null) {
StatusEffect foodEffect = e.getActivePotionEffect(p);
nausea = new StatusEffectInstance(StatusEffects.NAUSEA, foodEffect.getDuration(), foodEffect.getAmplifier(), foodEffect.getIsAmbient(), foodEffect.doesShowParticles());
e.addPotionEffect(nausea);
}
e.attackEntityFrom(food_poisoning, i);
});
}

View file

@ -1,6 +1,14 @@
package com.minelittlepony.unicopia.init; package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.render.entity.ButterflyEntityRenderer;
import com.minelittlepony.unicopia.client.render.entity.RenderCloud;
import com.minelittlepony.unicopia.client.render.entity.RenderCuccoon;
import com.minelittlepony.unicopia.client.render.entity.RenderGem;
import com.minelittlepony.unicopia.client.render.entity.RenderProjectile;
import com.minelittlepony.unicopia.client.render.entity.RenderRainbow;
import com.minelittlepony.unicopia.client.render.entity.RenderSpear;
import com.minelittlepony.unicopia.client.render.entity.RenderSpellbook;
import com.minelittlepony.unicopia.entity.EntityButterfly; import com.minelittlepony.unicopia.entity.EntityButterfly;
import com.minelittlepony.unicopia.entity.EntityCloud; import com.minelittlepony.unicopia.entity.EntityCloud;
import com.minelittlepony.unicopia.entity.EntityConstructionCloud; import com.minelittlepony.unicopia.entity.EntityConstructionCloud;
@ -8,20 +16,12 @@ import com.minelittlepony.unicopia.entity.EntityCuccoon;
import com.minelittlepony.unicopia.entity.EntityRacingCloud; import com.minelittlepony.unicopia.entity.EntityRacingCloud;
import com.minelittlepony.unicopia.entity.EntityRainbow; import com.minelittlepony.unicopia.entity.EntityRainbow;
import com.minelittlepony.unicopia.entity.EntitySpear; import com.minelittlepony.unicopia.entity.EntitySpear;
import com.minelittlepony.unicopia.entity.EntitySpell; import com.minelittlepony.unicopia.entity.SpellcastEntity;
import com.minelittlepony.unicopia.entity.EntitySpellbook; import com.minelittlepony.unicopia.entity.EntitySpellbook;
import com.minelittlepony.unicopia.entity.EntityProjectile;
import com.minelittlepony.unicopia.entity.EntityWildCloud; import com.minelittlepony.unicopia.entity.EntityWildCloud;
import com.minelittlepony.unicopia.entity.item.AdvancedProjectileEntity;
import com.minelittlepony.unicopia.forgebullshit.BiomeBS; import com.minelittlepony.unicopia.forgebullshit.BiomeBS;
import com.minelittlepony.unicopia.forgebullshit.EntityType; import com.minelittlepony.unicopia.forgebullshit.EntityType;
import com.minelittlepony.unicopia.render.RenderButterfly;
import com.minelittlepony.unicopia.render.RenderCloud;
import com.minelittlepony.unicopia.render.RenderCuccoon;
import com.minelittlepony.unicopia.render.RenderGem;
import com.minelittlepony.unicopia.render.RenderProjectile;
import com.minelittlepony.unicopia.render.RenderRainbow;
import com.minelittlepony.unicopia.render.RenderSpear;
import com.minelittlepony.unicopia.render.RenderSpellbook;
import net.minecraft.entity.EnumCreatureType; import net.minecraft.entity.EnumCreatureType;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
@ -45,24 +45,24 @@ public class UEntities {
builder.creature(EntityWildCloud.class, "wild_cloud"), builder.creature(EntityWildCloud.class, "wild_cloud"),
builder.creature(EntityRacingCloud.class, "racing_cloud"), builder.creature(EntityRacingCloud.class, "racing_cloud"),
builder.creature(EntityConstructionCloud.class, "construction_cloud"), builder.creature(EntityConstructionCloud.class, "construction_cloud"),
builder.creature(EntitySpell.class, "magic_spell"), builder.creature(SpellcastEntity.class, "magic_spell"),
builder.creature(EntitySpellbook.class, "spellbook"), builder.creature(EntitySpellbook.class, "spellbook"),
builder.creature(EntityRainbow.Spawner.class, "rainbow_spawner"), builder.creature(EntityRainbow.Spawner.class, "rainbow_spawner"),
builder.creature(EntityCuccoon.class, "cuccoon"), builder.creature(EntityCuccoon.class, "cuccoon"),
builder.creature(EntityButterfly.class, "butterfly").withEgg(0x222200, 0xaaeeff), builder.creature(EntityButterfly.class, "butterfly").withEgg(0x222200, 0xaaeeff),
builder.projectile(EntityRainbow.class, "rainbow", 500, 5), builder.projectile(EntityRainbow.class, "rainbow", 500, 5),
builder.projectile(EntityProjectile.class, "thrown_item", 100, 10), builder.projectile(AdvancedProjectileEntity.class, "thrown_item", 100, 10),
builder.projectile(EntitySpear.class, "spear", 100, 10) builder.projectile(EntitySpear.class, "spear", 100, 10)
); );
} }
public static void preInit() { public static void preInit() {
RenderingRegistry.registerEntityRenderingHandler(EntityCloud.class, RenderCloud::new); RenderingRegistry.registerEntityRenderingHandler(EntityCloud.class, RenderCloud::new);
RenderingRegistry.registerEntityRenderingHandler(EntitySpell.class, RenderGem::new); RenderingRegistry.registerEntityRenderingHandler(SpellcastEntity.class, RenderGem::new);
RenderingRegistry.registerEntityRenderingHandler(EntityProjectile.class, RenderProjectile::new); RenderingRegistry.registerEntityRenderingHandler(AdvancedProjectileEntity.class, RenderProjectile::new);
RenderingRegistry.registerEntityRenderingHandler(EntitySpellbook.class, RenderSpellbook::new); RenderingRegistry.registerEntityRenderingHandler(EntitySpellbook.class, RenderSpellbook::new);
RenderingRegistry.registerEntityRenderingHandler(EntityRainbow.class, RenderRainbow::new); RenderingRegistry.registerEntityRenderingHandler(EntityRainbow.class, RenderRainbow::new);
RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, RenderButterfly::new); RenderingRegistry.registerEntityRenderingHandler(EntityButterfly.class, ButterflyEntityRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(EntityCuccoon.class, RenderCuccoon::new); RenderingRegistry.registerEntityRenderingHandler(EntityCuccoon.class, RenderCuccoon::new);
RenderingRegistry.registerEntityRenderingHandler(EntitySpear.class, RenderSpear::new); RenderingRegistry.registerEntityRenderingHandler(EntitySpear.class, RenderSpear::new);
} }

View file

@ -1,4 +1,4 @@
package com.minelittlepony.unicopia.init; package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.item.ItemAlicornAmulet; import com.minelittlepony.unicopia.item.ItemAlicornAmulet;
import com.minelittlepony.unicopia.item.ItemApple; import com.minelittlepony.unicopia.item.ItemApple;
@ -43,7 +43,7 @@ import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemSeedFood; import net.minecraft.item.ItemSeedFood;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.Identifier;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistry;
@ -288,12 +288,12 @@ public class UItems {
record_crusade, record_pet, record_popular, record_funk); record_crusade, record_pet, record_popular, record_funk);
if (UClient.isClientSide()) { if (UClient.isClientSide()) {
BuildInTexturesBakery.getBuiltInTextures().add(new ResourceLocation(Unicopia.MODID, "items/empty_slot_gem")); BuildInTexturesBakery.getBuiltInTextures().add(new Identifier(Unicopia.MODID, "items/empty_slot_gem"));
} }
FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(zap_apple), new ItemStack(cooked_zap_apple), 0.1F); FurnaceRecipes.getInstance().addSmeltingRecipe(new ItemStack(zap_apple), new ItemStack(cooked_zap_apple), 0.1F);
FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(juice), new ItemStack(burned_juice), 0); FurnaceRecipes.getInstance().addSmeltingRecipe(new ItemStack(juice), new ItemStack(burned_juice), 0);
FurnaceRecipes.instance().addSmeltingRecipe(new ItemStack(cuccoon), new ItemStack(chitin_shell), 0.3F); FurnaceRecipes.getInstance().addSmeltingRecipe(new ItemStack(cuccoon), new ItemStack(chitin_shell), 0.3F);
} }
public static void fixRecipes() { public static void fixRecipes() {
@ -305,8 +305,8 @@ public class UItems {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
static void registerColors(ItemColors registry) { static void registerColors(ItemColors registry) {
registry.registerItemColorHandler((stack, tint) -> { registry.registerItemColorHandler((stack, tint) -> {
if (MAGI.test(Minecraft.getMinecraft().player)) { if (MAGI.test(MinecraftClient.getInstance().player)) {
return SpellRegistry.instance().getSpellTintFromStack(stack); return SpellRegistry.getInstance().getSpellTintFromStack(stack);
} }
return 0xffffff; return 0xffffff;

View file

@ -0,0 +1,9 @@
package com.minelittlepony.unicopia;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
public class UMaterials {
public static final Material cloud = new Material.Builder(MaterialColor.WHITE).build();
public static final Material hive = new Material.Builder(MaterialColor.NETHER).build();
}

View file

@ -0,0 +1,33 @@
package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.client.particle.ParticleChangelingMagic;
import com.minelittlepony.unicopia.client.particle.ParticleDisk;
import com.minelittlepony.unicopia.client.particle.ParticleRaindrops;
import com.minelittlepony.unicopia.client.particle.ParticleSphere;
import com.minelittlepony.unicopia.client.particle.ParticleUnicornMagic;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.particles.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.particles.ParticleTypeRegistry;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.util.Identifier;
public class UParticles {
public static final DefaultParticleType UNICORN_MAGIC = ParticleTypeRegistry.getTnstance().register(new Identifier("unicopia", "unicorn_magic"));
public static final DefaultParticleType CHANGELING_MAGIC = ParticleTypeRegistry.getTnstance().register(new Identifier("unicopia", "changeling_magic"));
public static final DefaultParticleType RAIN_DROPS = ParticleTypeRegistry.getTnstance().register(new Identifier("unicopia", "rain_drops"));
public static final DefaultParticleType SPHERE = ParticleTypeRegistry.getTnstance().register(new Identifier("unicopia", "sphere"));
public static final DefaultParticleType DISK = ParticleTypeRegistry.getTnstance().register(new Identifier("unicopia", "disk"));
@Environment(EnvType.CLIENT)
public void onInitializeClient() {
ParticleFactoryRegistry.getInstance().register(UNICORN_MAGIC, ParticleUnicornMagic::new);
ParticleFactoryRegistry.getInstance().register(CHANGELING_MAGIC, ParticleChangelingMagic::new);
ParticleFactoryRegistry.getInstance().register(RAIN_DROPS, ParticleRaindrops::new);
ParticleFactoryRegistry.getInstance().register(SPHERE, ParticleSphere::new);
ParticleFactoryRegistry.getInstance().register(DISK, ParticleDisk::new);
}
}

View file

@ -1,12 +1,12 @@
package com.minelittlepony.unicopia.potion; package com.minelittlepony.unicopia;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.potion.Potion; import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
public class UPotion extends Potion { public class UPotion extends StatusEffect {
private boolean isSilent; private boolean isSilent;
private int tickDelay = 40; private int tickDelay = 40;
@ -69,7 +69,7 @@ public class UPotion extends Potion {
} }
@Override @Override
public void performEffect(EntityLivingBase entity, int amplifier) { public void performEffect(LivingEntity entity, int amplifier) {
applicator.performEffect(this, entity, amplifier); applicator.performEffect(this, entity, amplifier);
} }
@ -95,6 +95,6 @@ public class UPotion extends Potion {
public interface IEffectApplicator { public interface IEffectApplicator {
IEffectApplicator NONE = (p, e, i) -> {}; IEffectApplicator NONE = (p, e, i) -> {};
void performEffect(Potion effect, EntityLivingBase target, int amplifier); void performEffect(Potion effect, LivingEntity target, int amplifier);
} }
} }

View file

@ -0,0 +1,29 @@
package com.minelittlepony.unicopia;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
public class USounds {
public static final SoundEvent WING_FLAP = register("wing_flap");
public static final SoundEvent WIND_RUSH = register("wind_rush");
public static final SoundEvent INSECT = register("insect");
public static final SoundEvent CHANGELING_BUZZ = register("changeling_buzz");
public static final SoundEvent SLIME_ADVANCE = register("slime_advance");
public static final SoundEvent SLIME_RETRACT = register("slime_retract");
public static final SoundEvent RECORD_CRUSADE = register("record.crusade");
public static final SoundEvent RECORD_PET = register("record.pet");
public static final SoundEvent RECORD_POPULAR = register("record.popular");
public static final SoundEvent RECORD_FUNK = register("record.funk");
private static SoundEvent register(String name) {
Identifier id = new Identifier(Unicopia.MODID, name);
return Registry.register(Registry.SOUND_EVENT, id, new SoundEvent(id));
}
static void bootstrap() {}
}

View file

@ -1,20 +1,8 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
@ -22,33 +10,22 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.minelittlepony.jumpingcastle.api.IChannel; import com.minelittlepony.unicopia.ability.powers.PowersRegistry;
import com.minelittlepony.jumpingcastle.api.JumpingCastle;
import com.minelittlepony.unicopia.advancements.UAdvancements; import com.minelittlepony.unicopia.advancements.UAdvancements;
import com.minelittlepony.unicopia.command.Commands; import com.minelittlepony.unicopia.command.Commands;
import com.minelittlepony.unicopia.enchanting.AffineIngredients; import com.minelittlepony.unicopia.enchanting.AffineIngredients;
import com.minelittlepony.unicopia.enchanting.Pages; import com.minelittlepony.unicopia.enchanting.Pages;
import com.minelittlepony.unicopia.enchanting.SpecialRecipe; import com.minelittlepony.unicopia.enchanting.SpecialRecipe;
import com.minelittlepony.unicopia.enchanting.SpellRecipe; import com.minelittlepony.unicopia.enchanting.SpellRecipe;
import com.minelittlepony.unicopia.forgebullshit.FBS; import com.minelittlepony.unicopia.inventory.gui.SpellBookContainer;
import com.minelittlepony.unicopia.init.UEntities;
import com.minelittlepony.unicopia.init.UItems;
import com.minelittlepony.unicopia.inventory.gui.ContainerSpellBook;
import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook; import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook;
import com.minelittlepony.unicopia.network.MsgPlayerAbility; import com.minelittlepony.unicopia.network.MsgPlayerAbility;
import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
import com.minelittlepony.unicopia.network.MsgRequestCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
import com.minelittlepony.unicopia.power.PowersRegistry;
import com.minelittlepony.unicopia.util.crafting.CraftingManager; import com.minelittlepony.unicopia.util.crafting.CraftingManager;
import com.minelittlepony.unicopia.world.Hooks; import com.minelittlepony.unicopia.world.Hooks;
import com.minelittlepony.unicopia.world.UWorld; import com.minelittlepony.unicopia.world.UWorld;
@Mod(
modid = Unicopia.MODID,
name = Unicopia.NAME,
version = Unicopia.VERSION,
dependencies = "required-after:jumpingcastle;after:baubles"
)
public class Unicopia implements IGuiHandler { public class Unicopia implements IGuiHandler {
public static final String MODID = "unicopia"; public static final String MODID = "unicopia";
public static final String NAME = "@NAME@"; public static final String NAME = "@NAME@";
@ -78,26 +55,20 @@ public class Unicopia implements IGuiHandler {
return channel; return channel;
} }
@EventHandler
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
UConfig.init(event.getModConfigurationDirectory()); UConfig.init(event.getModConfigurationDirectory());
UClient.instance().preInit(); UClient.instance().preInit();
UWorld.instance().init(); UWorld.instance().init();
MinecraftForge.TERRAIN_GEN_BUS.register(Hooks.class);
} }
@EventHandler
public void onServerCreated(FMLServerAboutToStartEvent event) { public void onServerCreated(FMLServerAboutToStartEvent event) {
Fixes.init(event.getServer().getDataFixer()); Fixes.init(event.getServer().getDataFixer());
} }
@EventHandler
public void onServerStart(FMLServerStartingEvent event) { public void onServerStart(FMLServerStartingEvent event) {
Commands.init(event); Commands.init(event);
} }
@EventHandler
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
channel = JumpingCastle.subscribeTo(MODID, () -> {}) channel = JumpingCastle.subscribeTo(MODID, () -> {})
.listenFor(MsgRequestCapabilities.class) .listenFor(MsgRequestCapabilities.class)
@ -115,7 +86,6 @@ public class Unicopia implements IGuiHandler {
UClient.instance().init(); UClient.instance().init();
} }
@EventHandler
public void postInit(FMLPostInitializationEvent event) { public void postInit(FMLPostInitializationEvent event) {
craftingManager.load(); craftingManager.load();
@ -130,7 +100,7 @@ public class Unicopia implements IGuiHandler {
@Override @Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) { switch (ID) {
case 0: return new ContainerSpellBook(player.inventory, world, new BlockPos(x, y, z)); case 0: return new SpellBookContainer(player.inventory, world, new BlockPos(x, y, z));
default: return null; default: return null;
} }
} }

View file

@ -6,35 +6,20 @@ import java.util.UUID;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.gui.Button; import com.minelittlepony.unicopia.ability.powers.render.DisguiseRenderer;
import com.minelittlepony.jumpingcastle.api.Target; import com.minelittlepony.unicopia.client.gui.SettingsScreen;
import com.minelittlepony.unicopia.entity.EntityFakeClientPlayer; import com.minelittlepony.unicopia.client.input.Keyboard;
import com.minelittlepony.unicopia.extern.MineLP; import com.minelittlepony.unicopia.client.input.MouseControl;
import com.minelittlepony.unicopia.gui.GuiScreenSettings; import com.minelittlepony.unicopia.client.input.InversionAwareKeyboardInput;
import com.minelittlepony.unicopia.init.UEntities; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.init.UParticles;
import com.minelittlepony.unicopia.input.Keyboard;
import com.minelittlepony.unicopia.input.MouseControl;
import com.minelittlepony.unicopia.input.MovementControl;
import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding;
import com.minelittlepony.unicopia.network.MsgRequestCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.render.DisguiseRenderer;
import com.minelittlepony.util.gui.ButtonGridLayout;
import com.minelittlepony.util.lang.ClientLocale;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.input.Input;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.MovementInput;
import net.minecraft.world.IInteractionObject;
import static com.minelittlepony.util.gui.ButtonGridLayout.*;
public class UnicopiaClient extends UClient { public class UnicopiaClient extends UClient {
@ -50,7 +35,7 @@ public class UnicopiaClient extends UClient {
private static Race getclientPlayerRace() { private static Race getclientPlayerRace() {
if (!UConfig.instance().ignoresMineLittlePony() if (!UConfig.instance().ignoresMineLittlePony()
&& Minecraft.getMinecraft().player != null) { && MinecraftClient.getInstance().player != null) {
Race race = MineLP.getPlayerPonyRace(); Race race = MineLP.getPlayerPonyRace();
if (!race.isDefault()) { if (!race.isDefault()) {
@ -62,40 +47,11 @@ public class UnicopiaClient extends UClient {
return UConfig.instance().getPrefferedRace(); return UConfig.instance().getPrefferedRace();
} }
static void addUniButton(List<GuiButton> buttons) {
ButtonGridLayout layout = new ButtonGridLayout(buttons);
GuiButton uni = new Button(0, 0, 150, 20, ClientLocale.format("gui.unicopia"), b -> {
Minecraft mc = Minecraft.getMinecraft();
mc.displayGuiScreen(new GuiScreenSettings(mc.currentScreen));
});
List<Integer> possibleXCandidates = list(layout.getColumns());
List<Integer> possibleYCandidates = list(layout.getRows());
uni.y = last(possibleYCandidates, 1);
if (layout.getRows()
.filter(y -> layout.getRow(y).size() == 1).count() < 2) {
uni.y += 25;
uni.x = first(possibleXCandidates, 0);
layout.getRow(last(possibleYCandidates, 0)).forEach(button -> {
button.y = Math.max(button.y, uni.y + uni.height + 13);
});
} else {
uni.x = first(possibleXCandidates, 2);
}
layout.getElements().add(uni);
}
@Override @Override
public void displayGuiToPlayer(EntityPlayer player, IInteractionObject inventory) { public void displayGuiToPlayer(EntityPlayer player, IInteractionObject inventory) {
if (player instanceof EntityPlayerSP) { if (player instanceof EntityPlayerSP) {
if ("unicopia:itemofholding".equals(inventory.getGuiID())) { if ("unicopia:itemofholding".equals(inventory.getGuiID())) {
Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory)); MinecraftClient.getInstance().displayGuiScreen(new GuiOfHolding(inventory));
} }
} else { } else {
super.displayGuiToPlayer(player, inventory); super.displayGuiToPlayer(player, inventory);
@ -105,13 +61,13 @@ public class UnicopiaClient extends UClient {
@Override @Override
@Nullable @Nullable
public EntityPlayer getPlayer() { public EntityPlayer getPlayer() {
return Minecraft.getMinecraft().player; return MinecraftClient.getInstance().player;
} }
@Override @Override
@Nullable @Nullable
public EntityPlayer getPlayerByUUID(UUID playerId) { public EntityPlayer getPlayerByUUID(UUID playerId) {
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = MinecraftClient.getInstance();
if (mc.player.getUniqueID().equals(playerId)) { if (mc.player.getUniqueID().equals(playerId)) {
return mc.player; return mc.player;
@ -120,6 +76,7 @@ public class UnicopiaClient extends UClient {
return mc.world.getPlayerEntityByUUID(playerId); return mc.world.getPlayerEntityByUUID(playerId);
} }
@Override
@Nonnull @Nonnull
public EntityPlayer createPlayer(Entity observer, GameProfile profile) { public EntityPlayer createPlayer(Entity observer, GameProfile profile) {
return new EntityFakeClientPlayer(observer.world, profile); return new EntityFakeClientPlayer(observer.world, profile);
@ -140,13 +97,13 @@ public class UnicopiaClient extends UClient {
@Override @Override
public int getViewMode() { public int getViewMode() {
return Minecraft.getMinecraft().gameSettings.thirdPersonView; return MinecraftClient.getInstance().gameSettings.thirdPersonView;
} }
@Override @Override
public void postRenderEntity(Entity entity) { public void postRenderEntity(Entity entity) {
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity); IPlayer iplayer = SpeciesList.instance().getPlayer((EntityPlayer)entity);
if (iplayer.getGravity().getGravitationConstant() < 0) { if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.translate(0, entity.height, 0); GlStateManager.translate(0, entity.height, 0);
@ -160,12 +117,12 @@ public class UnicopiaClient extends UClient {
@Override @Override
public boolean renderEntity(Entity entity, float renderPartialTicks) { public boolean renderEntity(Entity entity, float renderPartialTicks) {
if (DisguiseRenderer.instance().renderDisguise(entity, renderPartialTicks)) { if (DisguiseRenderer.getInstance().renderDisguise(entity, renderPartialTicks)) {
return true; return true;
} }
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity); IPlayer iplayer = SpeciesList.instance().getPlayer((EntityPlayer)entity);
if (iplayer.getGravity().getGravitationConstant() < 0) { if (iplayer.getGravity().getGravitationConstant() < 0) {
GlStateManager.scale(1, -1, 1); GlStateManager.scale(1, -1, 1);
@ -174,7 +131,7 @@ public class UnicopiaClient extends UClient {
entity.rotationPitch *= -1; entity.rotationPitch *= -1;
} }
if (DisguiseRenderer.instance().renderDisguiseToGui(iplayer)) { if (DisguiseRenderer.getInstance().renderDisguiseToGui(iplayer)) {
return true; return true;
} }
@ -197,10 +154,11 @@ public class UnicopiaClient extends UClient {
clientPlayerRace = getclientPlayerRace(); clientPlayerRace = getclientPlayerRace();
} }
@Override
public void tick() { public void tick() {
EntityPlayer player = UClient.instance().getPlayer(); PlayerEntity player = UClient.instance().getPlayer();
if (player != null && !player.isDead) { if (player != null && !player.removed) {
Race newRace = getclientPlayerRace(); Race newRace = getclientPlayerRace();
if (newRace != clientPlayerRace) { if (newRace != clientPlayerRace) {
@ -212,20 +170,20 @@ public class UnicopiaClient extends UClient {
Keyboard.getKeyHandler().onKeyInput(); Keyboard.getKeyHandler().onKeyInput();
if (player instanceof EntityPlayerSP) { MinecraftClient client = MinecraftClient.getInstance();
EntityPlayerSP sp = (EntityPlayerSP)player;
MovementInput movement = sp.movementInput; if (player instanceof ClientPlayerEntity) {
ClientPlayerEntity sp = (ClientPlayerEntity)player;
if (!(movement instanceof MovementControl)) { Input movement = sp.input;
sp.movementInput = new MovementControl(movement);
if (!(movement instanceof InversionAwareKeyboardInput)) {
sp.input = new InversionAwareKeyboardInput(client, movement);
} }
} }
Minecraft mc = Minecraft.getMinecraft(); if (!(client.mouse instanceof MouseControl)) {
client.mouse = new MouseControl(client);
if (!(mc.mouseHelper instanceof MouseControl)) {
mc.mouseHelper = new MouseControl();
} }
} }
} }

View file

@ -0,0 +1,5 @@
package com.minelittlepony.unicopia.ability;
public class Hit implements IData {
}

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.player; package com.minelittlepony.unicopia.ability;
import com.minelittlepony.unicopia.power.IPower; import com.minelittlepony.unicopia.ability.IPower;
public interface IAbilityReceiver { public interface IAbilityReceiver {

View file

@ -0,0 +1,5 @@
package com.minelittlepony.unicopia.ability;
public interface IData {
}

View file

@ -1,4 +1,6 @@
package com.minelittlepony.unicopia.player; package com.minelittlepony.unicopia.ability;
import com.minelittlepony.unicopia.entity.player.IPlayer;
/** /**
* Predicate for abilities to control whether a player can fly. * Predicate for abilities to control whether a player can fly.

View file

@ -1,11 +1,13 @@
package com.minelittlepony.unicopia.player; package com.minelittlepony.unicopia.ability;
import com.minelittlepony.unicopia.entity.player.IPlayer;
/** /**
* Predicate for abilities to control what the player's physical height is. * Predicate for abilities to control what the player's physical height is.
* *
* This overrides the default. * This overrides the default.
*/ */
public interface IPlayerHeightPredicate { public interface IHeightPredicate {
float getTargetEyeHeight(IPlayer player); float getTargetEyeHeight(IPlayer player);
float getTargetBodyHeight(IPlayer player); float getTargetBodyHeight(IPlayer player);

View file

@ -1,36 +1,14 @@
package com.minelittlepony.unicopia.power; package com.minelittlepony.unicopia.ability;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.input.IKeyBind; import com.minelittlepony.unicopia.client.input.IKeyBindingHandler;
import com.minelittlepony.unicopia.particle.Particles; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.shape.Sphere;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface IPower<T extends IData> extends IKeyBind { public interface IPower<T extends IData> extends IKeyBindingHandler.IKeyBinding {
static void spawnParticles(int particleId, Entity entity, int count, int...args) {
double halfDist = entity.getEyeHeight() / 1.5;
double middle = entity.getEntityBoundingBox().minY + halfDist;
IShape shape = new Sphere(false, (float)halfDist + entity.width);
for (int i = 0; i < count; i++) {
Vec3d point = shape.computePoint(entity.getEntityWorld().rand);
Particles.instance().spawnParticle(particleId, false,
entity.posX + point.x,
middle + point.y,
entity.posZ + point.z,
0, 0, 0, args);
}
}
@Override @Override
default String getKeyCategory() { default String getKeyCategory() {

View file

@ -1,7 +1,6 @@
package com.minelittlepony.unicopia.power.data; package com.minelittlepony.unicopia.ability;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.minelittlepony.unicopia.power.IData;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;

View file

@ -1,7 +1,6 @@
package com.minelittlepony.unicopia.power.data; package com.minelittlepony.unicopia.ability;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.minelittlepony.unicopia.power.IData;
public class Numeric implements IData { public class Numeric implements IData {

View file

@ -1,18 +1,18 @@
package com.minelittlepony.unicopia.power; package com.minelittlepony.unicopia.ability.powers;
import org.lwjgl.input.Keyboard; import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.entity.EntityCloud; import com.minelittlepony.unicopia.ability.Hit;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.power.data.Hit; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.util.vector.VecHelper; import com.minelittlepony.util.VecHelper;
import net.minecraft.client.network.packet.EntityPassengersSetS2CPacket;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.network.play.server.SPacketSetPassengers;
import net.minecraft.world.World; import net.minecraft.world.World;
public class PowerCarry implements IPower<Hit> { public class PowerCarry implements IPower<Hit> {
@ -24,7 +24,7 @@ public class PowerCarry implements IPower<Hit> {
@Override @Override
public int getKeyCode() { public int getKeyCode() {
return Keyboard.KEY_K; return GLFW.GLFW_KEY_K;
} }
@Override @Override
@ -47,12 +47,12 @@ public class PowerCarry implements IPower<Hit> {
return new Hit(); return new Hit();
} }
protected EntityLivingBase findRider(EntityPlayer player, World w) { protected LivingEntity findRider(PlayerEntity player, World w) {
Entity hit = VecHelper.getLookedAtEntity(player, 10); Entity hit = VecHelper.getLookedAtEntity(player, 10);
if (hit instanceof EntityLivingBase && !player.isRidingOrBeingRiddenBy(hit)) { if (hit instanceof LivingEntity && !player.isConnectedThroughVehicle(hit)) {
if (!(hit instanceof EntityCloud)) { if (!(hit instanceof IPickupImmuned)) {
return (EntityLivingBase)hit; return (LivingEntity)hit;
} }
} }
@ -66,17 +66,17 @@ public class PowerCarry implements IPower<Hit> {
@Override @Override
public void apply(IPlayer iplayer, Hit data) { public void apply(IPlayer iplayer, Hit data) {
EntityPlayer player = iplayer.getOwner(); PlayerEntity player = iplayer.getOwner();
EntityLivingBase rider = findRider(player, iplayer.getWorld()); LivingEntity rider = findRider(player, iplayer.getWorld());
if (rider != null) { if (rider != null) {
rider.startRiding(player, true); rider.startRiding(player, true);
} else { } else {
player.removePassengers(); player.removeAllPassengers();
} }
if (player instanceof EntityPlayerMP) { if (player instanceof ServerPlayerEntity) {
((EntityPlayerMP)player).getServerWorld().getEntityTracker().sendToTrackingAndSelf(player, new SPacketSetPassengers(player)); ((ServerPlayerEntity)player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player));
} }
} }
@ -87,4 +87,8 @@ public class PowerCarry implements IPower<Hit> {
@Override @Override
public void postApply(IPlayer player) { public void postApply(IPlayer player) {
} }
public interface IPickupImmuned {
}
} }

View file

@ -1,13 +1,17 @@
package com.minelittlepony.unicopia.power; package com.minelittlepony.unicopia.ability.powers;
import org.lwjgl.input.Keyboard; import java.util.Optional;
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.entity.EntityCloud; import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.init.UParticles; import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.ability.Numeric;
import com.minelittlepony.unicopia.power.data.Numeric; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.util.vector.VecHelper; import com.minelittlepony.util.VecHelper;
import net.minecraft.entity.Entity;
public class PowerCloudBase implements IPower<Numeric> { public class PowerCloudBase implements IPower<Numeric> {
@ -18,7 +22,7 @@ public class PowerCloudBase implements IPower<Numeric> {
@Override @Override
public int getKeyCode() { public int getKeyCode() {
return Keyboard.KEY_J; return GLFW.GLFW_KEY_J;
} }
@Override @Override
@ -38,16 +42,12 @@ public class PowerCloudBase implements IPower<Numeric> {
@Override @Override
public Numeric tryActivate(IPlayer player) { public Numeric tryActivate(IPlayer player) {
EntityCloud cloud = findTarget(player); return findTarget(player).map(cloud -> {
Numeric data = new Numeric(player.getOwner().inventory.selectedSlot + 1);
if (cloud != null) {
Numeric data = new Numeric(player.getOwner().inventory.currentItem + 1);
cloud.handlePegasusInteration(data.type); cloud.handlePegasusInteration(data.type);
return data; return data;
} }).orElse(null);
return null;
} }
@Override @Override
@ -57,25 +57,23 @@ public class PowerCloudBase implements IPower<Numeric> {
@Override @Override
public void apply(IPlayer player, Numeric data) { public void apply(IPlayer player, Numeric data) {
EntityCloud cloud = findTarget(player); findTarget(player).ifPresent(cloud -> {
if (cloud != null) {
cloud.handlePegasusInteration(data.type); cloud.handlePegasusInteration(data.type);
} });
} }
protected EntityCloud findTarget(IPlayer player) { protected Optional<ICloudEntity> findTarget(IPlayer player) {
if (player.getOwner().isRiding() && player.getOwner().getRidingEntity() instanceof EntityCloud) { if (player.getOwner().hasVehicle() && player.getOwner().getVehicle() instanceof ICloudEntity) {
return (EntityCloud)player.getOwner().getRidingEntity(); return Optional.ofNullable((ICloudEntity)player.getOwner().getVehicle());
} }
Object e = VecHelper.getLookedAtEntity(player.getOwner(), 18); Entity e = VecHelper.getLookedAtEntity(player.getOwner(), 18);
if (e instanceof EntityCloud) { if (e instanceof ICloudEntity) {
return (EntityCloud)e; return Optional.of((ICloudEntity)e);
} }
return null; return Optional.empty();
} }
@Override @Override
@ -87,4 +85,8 @@ public class PowerCloudBase implements IPower<Numeric> {
public void postApply(IPlayer player) { public void postApply(IPlayer player) {
player.spawnParticles(UParticles.RAIN_DROPS, 5); player.spawnParticles(UParticles.RAIN_DROPS, 5);
} }
public interface ICloudEntity {
void handlePegasusInteration(int interationType);
}
} }

View file

@ -0,0 +1,101 @@
package com.minelittlepony.unicopia.ability.powers;
import javax.annotation.Nullable;
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.ability.Hit;
import com.minelittlepony.unicopia.entity.IInAnimate;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.magic.spells.SpellDisguise;
import com.minelittlepony.util.VecHelper;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
public class PowerDisguise extends PowerFeed {
@Override
public String getKeyName() {
return "unicopia.power.disguise";
}
@Override
public int getKeyCode() {
return GLFW.GLFW_KEY_P;
}
@Nullable
@Override
public Hit tryActivate(IPlayer player) {
return new Hit();
}
@Override
public void apply(IPlayer iplayer, Hit data) {
PlayerEntity player = iplayer.getOwner();
HitResult trace = VecHelper.getObjectMouseOver(player, 10, 1);
Entity looked = null;
if (trace.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult)trace).getBlockPos();
if (!iplayer.getWorld().isAir(pos)) {
BlockState state = iplayer.getWorld().getBlockState(pos);
looked = new FallingBlockEntity(player.getEntityWorld(), 0, 0, 0, state);
}
} else if (trace.getType() == HitResult.Type.ENTITY) {
looked = ((EntityHitResult)trace).getEntity();
if (looked instanceof PlayerEntity) {
looked = SpeciesList.instance().getPlayer((PlayerEntity)looked)
.getEffect(SpellDisguise.class)
.map(SpellDisguise::getDisguise)
.orElse(looked);
}
if (looked instanceof LightningEntity
|| (looked instanceof IInAnimate && !((IInAnimate)looked).canInteract(Race.CHANGELING))) {
looked = null;
}
}
player.getEntityWorld().playSound(null, player.getBlockPos(), SoundEvents.ENTITY_PARROT_IMITATE_POLAR_BEAR, SoundCategory.PLAYERS, 1.4F, 0.4F);
iplayer.getEffect(SpellDisguise.class).orElseGet(() -> {
SpellDisguise disc = new SpellDisguise();
iplayer.setEffect(disc);
return disc;
}).setDisguise(looked);
iplayer.sendCapabilities(true);
}
@Override
public void preApply(IPlayer player) {
player.addEnergy(2);
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
}
@Override
public void postApply(IPlayer player) {
player.setEnergy(0);
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
}
}

View file

@ -1,14 +1,13 @@
package com.minelittlepony.unicopia.power; package com.minelittlepony.unicopia.ability.powers;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.lwjgl.input.Keyboard; import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.ability.Hit;
import com.minelittlepony.unicopia.power.data.Hit; import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.spell.ITossedEffect; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.spell.SpellChangelingTrap; import com.minelittlepony.unicopia.magic.spells.SpellChangelingTrap;
public class PowerEngulf implements IPower<Hit> { public class PowerEngulf implements IPower<Hit> {
@ -19,7 +18,7 @@ public class PowerEngulf implements IPower<Hit> {
@Override @Override
public int getKeyCode() { public int getKeyCode() {
return Keyboard.KEY_L; return GLFW.GLFW_KEY_L;
} }
@Override @Override
@ -50,9 +49,7 @@ public class PowerEngulf implements IPower<Hit> {
@Override @Override
public void apply(IPlayer player, Hit data) { public void apply(IPlayer player, Hit data) {
ITossedEffect effect = new SpellChangelingTrap(); new SpellChangelingTrap().toss(player);
effect.toss(player);
} }
@Override @Override
@ -64,5 +61,4 @@ public class PowerEngulf implements IPower<Hit> {
public void postApply(IPlayer player) { public void postApply(IPlayer player) {
} }
} }

View file

@ -0,0 +1,166 @@
package com.minelittlepony.unicopia.ability.powers;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.Hit;
import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.VecHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.passive.AbstractTraderEntity;
import net.minecraft.entity.passive.CowEntity;
import net.minecraft.entity.passive.PigEntity;
import net.minecraft.entity.passive.SheepEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
public class PowerFeed implements IPower<Hit> {
@Override
public String getKeyName() {
return "unicopia.power.feed";
}
@Override
public int getKeyCode() {
return GLFW.GLFW_KEY_O;
}
@Override
public int getWarmupTime(IPlayer player) {
return 5;
}
@Override
public int getCooldownTime(IPlayer player) {
return canFeed(player) ? 15 : 80;
}
@Override
public boolean canUse(Race playerSpecies) {
return playerSpecies == Race.CHANGELING;
}
@Nullable
@Override
public Hit tryActivate(IPlayer player) {
if (canFeed(player)) {
if (!getTargets(player).isEmpty()) {
return new Hit();
}
}
return null;
}
private boolean canFeed(IPlayer player) {
return player.getOwner().getHealth() < player.getOwner().getHealthMaximum() || player.getOwner().canConsume(false);
}
private boolean canDrain(Entity e) {
return (e instanceof LivingEntity)
&& (e instanceof CowEntity
|| e instanceof AbstractTraderEntity
|| e instanceof PlayerEntity
|| e instanceof SheepEntity
|| e instanceof PigEntity
|| e instanceof HostileEntity);
}
@Override
public Class<Hit> getPackageType() {
return Hit.class;
}
protected List<LivingEntity> getTargets(IPlayer player) {
List<Entity> list = VecHelper.getWithinRange(player.getOwner(), 3, this::canDrain);
Entity looked = VecHelper.getLookedAtEntity(player.getOwner(), 17);
if (looked != null && !list.contains(looked) && canDrain(looked)) {
list.add(looked);
}
return list.stream().map(i -> (LivingEntity)i).collect(Collectors.toList());
}
@Override
public void apply(IPlayer iplayer, Hit data) {
PlayerEntity player = iplayer.getOwner();
float maximumHealthGain = player.getHealthMaximum() - player.getHealth();
int maximumFoodGain = player.canConsume(false) ? (20 - player.getHungerManager().getFoodLevel()) : 0;
if (maximumHealthGain > 0 || maximumFoodGain > 0) {
float healAmount = 0;
for (LivingEntity i : getTargets(iplayer)) {
healAmount += drainFrom(player, i);
}
int foodAmount = (int)Math.floor(Math.min(healAmount / 3, maximumFoodGain));
if (foodAmount > 0) {
healAmount -= foodAmount;
player.getHungerManager().add(foodAmount, 0.125f);
}
if (healAmount > 0) {
player.heal(Math.min(healAmount, maximumHealthGain));
}
}
}
public float drainFrom(PlayerEntity changeling, LivingEntity living) {
DamageSource d = MagicalDamageSource.causePlayerDamage("feed", changeling);
float damage = living.getHealth()/2;
if (damage > 0) {
living.damage(d, damage);
}
// TODO:
//ParticleTypeRegistry.spawnParticles(UParticles.CHANGELING_MAGIC, living, 7);
if (changeling.hasStatusEffect(StatusEffects.NAUSEA)) {
living.addPotionEffect(changeling.removePotionEffect(StatusEffects.NAUSEA));
} else if (changeling.getEntityWorld().random.nextInt(2300) == 0) {
living.addPotionEffect(new StatusEffectInstance(StatusEffects.WITHER, 20, 1));
}
if (living instanceof PlayerEntity) {
damage ++;
damage *= 1.6F;
if (!changeling.hasStatusEffect(StatusEffects.HEALTH_BOOST)) {
changeling.addPotionEffect(new StatusEffectInstance(StatusEffects.HEALTH_BOOST, 13000, 1));
}
}
return damage;
}
@Override
public void preApply(IPlayer player) {
player.addExertion(6);
}
@Override
public void postApply(IPlayer player) {
player.spawnParticles(ParticleTypes.HEART, 1);
}
}

View file

@ -0,0 +1,105 @@
package com.minelittlepony.unicopia.ability.powers;
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.ability.Location;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.util.VecHelper;
import net.minecraft.block.BlockState;
import net.minecraft.item.BoneMealItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public class PowerGrow implements IPower<Location> {
@Override
public String getKeyName() {
return "unicopia.power.grow";
}
@Override
public int getKeyCode() {
return GLFW.GLFW_KEY_N;
}
@Override
public int getWarmupTime(IPlayer player) {
return 10;
}
@Override
public int getCooldownTime(IPlayer player) {
return 50;
}
@Override
public boolean canUse(Race playerSpecies) {
return playerSpecies == Race.EARTH;
}
@Override
public Location tryActivate(IPlayer player) {
HitResult ray = VecHelper.getObjectMouseOver(player.getOwner(), 3, 1);
if (ray instanceof BlockHitResult && ray.getType() == HitResult.Type.BLOCK) {
return new Location(((BlockHitResult)ray).getBlockPos());
}
return null;
}
@Override
public Class<Location> getPackageType() {
return Location.class;
}
@Override
public void apply(IPlayer player, Location data) {
int count = 0;
for (BlockPos pos : BlockPos.iterate(
new BlockPos(data.x - 2, data.y - 2, data.z - 2),
new BlockPos(data.x + 2, data.y + 2, data.z + 2))) {
count += applySingle(player.getWorld(), player.getWorld().getBlockState(pos), pos);
}
if (count > 0) {
player.subtractEnergyCost(count * 5);
}
}
protected int applySingle(World w, BlockState state, BlockPos pos) {
ItemStack stack = new ItemStack(Items.BONE_MEAL);
if (BoneMealItem.useOnFertilizable(stack, w, pos)
|| BoneMealItem.useOnGround(stack, w, pos, Direction.UP)) {
return 1;
}
return 0;
}
@Override
public void preApply(IPlayer player) {
player.addExertion(3);
if (player.getWorld().isClient()) {
player.spawnParticles(UParticles.UNICORN_MAGIC, 1);
}
}
@Override
public void postApply(IPlayer player) {
}
}

View file

@ -1,12 +1,12 @@
package com.minelittlepony.unicopia.power; package com.minelittlepony.unicopia.ability.powers;
import org.lwjgl.input.Keyboard;
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.init.UParticles; import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.ability.Hit;
import com.minelittlepony.unicopia.power.data.Hit; import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.spell.SpellShield; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.magic.spells.SpellShield;
public class PowerMagic implements IPower<Hit> { public class PowerMagic implements IPower<Hit> {
@ -17,7 +17,7 @@ public class PowerMagic implements IPower<Hit> {
@Override @Override
public int getKeyCode() { public int getKeyCode() {
return Keyboard.KEY_P; return GLFW.GLFW_KEY_P;
} }
@Override @Override

View file

@ -1,54 +1,55 @@
package com.minelittlepony.unicopia.power; package com.minelittlepony.unicopia.ability.powers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.lwjgl.input.Keyboard; import org.lwjgl.glfw.GLFW;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.ability.Location;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.item.ItemApple; import com.minelittlepony.unicopia.item.ItemApple;
import com.minelittlepony.unicopia.particle.Particles;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.unicopia.power.data.Location;
import com.minelittlepony.unicopia.world.UWorld; import com.minelittlepony.unicopia.world.UWorld;
import com.minelittlepony.util.MagicalDamageSource; import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.PosHelper; import com.minelittlepony.util.PosHelper;
import com.minelittlepony.util.VecHelper;
import com.minelittlepony.util.WorldEvent; import com.minelittlepony.util.WorldEvent;
import com.minelittlepony.util.shape.IShape; import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.shape.Sphere; import com.minelittlepony.util.shape.Sphere;
import com.minelittlepony.util.vector.VecHelper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockState;
import net.minecraft.block.BlockLog; import net.minecraft.block.Blocks;
import net.minecraft.block.material.Material; import net.minecraft.block.LeavesBlock;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.LogBlock;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityContext;
import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.init.Blocks; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.util.EnumFacing; import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.state.property.Property;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import static net.minecraft.util.EnumFacing.*;
public class PowerStomp implements IPower<PowerStomp.Data> { public class PowerStomp implements IPower<PowerStomp.Data> {
private final double rad = 4; private final double rad = 4;
private final AxisAlignedBB areaOfEffect = new AxisAlignedBB( private final Box areaOfEffect = new Box(
-rad, -rad, -rad, -rad, -rad, -rad,
rad, rad, rad rad, rad, rad
); );
@ -60,7 +61,7 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
@Override @Override
public int getKeyCode() { public int getKeyCode() {
return Keyboard.KEY_M; return GLFW.GLFW_KEY_M;
} }
@Override @Override
@ -80,12 +81,13 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
@Override @Override
public PowerStomp.Data tryActivate(IPlayer player) { public PowerStomp.Data tryActivate(IPlayer player) {
RayTraceResult mop = VecHelper.getObjectMouseOver(player.getOwner(), 6, 1); HitResult mop = VecHelper.getObjectMouseOver(player.getOwner(), 6, 1);
if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) { if (mop instanceof BlockHitResult && mop.getType() == HitResult.Type.BLOCK) {
BlockPos pos = mop.getBlockPos(); BlockPos pos = ((BlockHitResult)mop).getBlockPos();
IBlockState state = player.getWorld().getBlockState(pos); BlockState state = player.getWorld().getBlockState(pos);
if (state.getBlock() instanceof BlockLog) {
if (state.getBlock() instanceof LogBlock) {
pos = getBaseOfTree(player.getWorld(), state, pos); pos = getBaseOfTree(player.getWorld(), state, pos);
if (measureTree(player.getWorld(), state, pos) > 0) { if (measureTree(player.getWorld(), state, pos) > 0) {
return new Data(pos.getX(), pos.getY(), pos.getZ(), 1); return new Data(pos.getX(), pos.getY(), pos.getZ(), 1);
@ -93,7 +95,7 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
} }
} }
if (!player.getOwner().onGround && !player.getOwner().capabilities.isFlying) { if (!player.getOwner().onGround && !player.getOwner().abilities.flying) {
player.getOwner().addVelocity(0, -6, 0); player.getOwner().addVelocity(0, -6, 0);
return new Data(0, 0, 0, 0); return new Data(0, 0, 0, 0);
} }
@ -106,9 +108,10 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
} }
public static BlockPos getSolidBlockBelow(BlockPos pos, World w) { public static BlockPos getSolidBlockBelow(BlockPos pos, World w) {
while (w.isValid(pos)) { while (World.isValid(pos)) {
pos = pos.down(); pos = pos.down();
if (w.getBlockState(pos).isSideSolid(w, pos, EnumFacing.UP)) {
if (Block.isFaceFullSquare(w.getBlockState(pos).getCollisionShape(w, pos, EntityContext.absent()), Direction.UP)) {
return pos; return pos;
} }
} }
@ -119,30 +122,30 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
@Override @Override
public void apply(IPlayer iplayer, Data data) { public void apply(IPlayer iplayer, Data data) {
EntityPlayer player = iplayer.getOwner(); PlayerEntity player = iplayer.getOwner();
if (data.hitType == 0) { if (data.hitType == 0) {
BlockPos ppos = player.getPosition(); BlockPos ppos = player.getBlockPos();
BlockPos pos = getSolidBlockBelow(ppos, player.getEntityWorld()); BlockPos pos = getSolidBlockBelow(ppos, player.getEntityWorld());
player.addVelocity(0, -(ppos.distanceSq(pos)), 0); player.addVelocity(0, -(ppos.getSquaredDistance(pos)), 0);
iplayer.getWorld().getEntitiesWithinAABBExcludingEntity(player, areaOfEffect.offset(iplayer.getOriginVector())).forEach(i -> { iplayer.getWorld().getEntities(player, areaOfEffect.offset(iplayer.getOriginVector())).forEach(i -> {
double dist = Math.sqrt(i.getDistanceSq(pos)); double dist = Math.sqrt(pos.getSquaredDistance(i.getBlockPos()));
if (dist <= rad + 3) { if (dist <= rad + 3) {
double force = dist / 5; double force = dist / 5;
i.addVelocity( i.addVelocity(
-(player.posX - i.posX) / force, -(player.x - i.x) / force,
-(player.posY - i.posY - 2) / force + (dist < 1 ? dist : 0), -(player.y - i.y - 2) / force + (dist < 1 ? dist : 0),
-(player.posZ - i.posZ) / force); -(player.z - i.z) / force);
DamageSource damage = MagicalDamageSource.causePlayerDamage("smash", player); DamageSource damage = MagicalDamageSource.causePlayerDamage("smash", player);
double amount = (4 * player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()) / (float)dist; double amount = (4 * player.getAttributeInstance(EntityAttributes.ATTACK_DAMAGE).getValue()) / (float)dist;
if (i instanceof EntityPlayer) { if (i instanceof PlayerEntity) {
Race race = PlayerSpeciesList.instance().getPlayer((EntityPlayer)i).getPlayerSpecies(); Race race = SpeciesList.instance().getPlayer((PlayerEntity)i).getSpecies();
if (race.canUseEarth()) { if (race.canUseEarth()) {
amount /= 3; amount /= 3;
} }
@ -152,12 +155,12 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
} }
} }
i.attackEntityFrom(damage, (float)amount); i.damage(damage, (float)amount);
} }
}); });
BlockPos.getAllInBoxMutable(pos.add(-rad, -rad, -rad), pos.add(rad, rad, rad)).forEach(i -> { BlockPos.iterate(pos.add(-rad, -rad, -rad), pos.add(rad, rad, rad)).forEach(i -> {
if (i.distanceSqToCenter(player.posX, player.posY, player.posZ) <= rad*rad) { if (i.getSquaredDistance(player.x, player.y, player.z, true) <= rad*rad) {
spawnEffect(player.world, i); spawnEffect(player.world, i);
} }
}); });
@ -169,16 +172,16 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
iplayer.subtractEnergyCost(rad); iplayer.subtractEnergyCost(rad);
} else if (data.hitType == 1) { } else if (data.hitType == 1) {
boolean harmed = player.getHealth() < player.getMaxHealth(); boolean harmed = player.getHealth() < player.getHealthMaximum();
if (harmed && player.world.rand.nextInt(30) == 0) { if (harmed && player.world.random.nextInt(30) == 0) {
iplayer.subtractEnergyCost(3); iplayer.subtractEnergyCost(3);
return; return;
} }
if (harmed || player.world.rand.nextInt(5) == 0) { if (harmed || player.world.random.nextInt(5) == 0) {
if (!harmed || player.world.rand.nextInt(30) == 0) { if (!harmed || player.world.random.nextInt(30) == 0) {
UWorld.enqueueTask(w -> removeTree(w, data.pos())); UWorld.enqueueTask(w -> removeTree(w, data.pos()));
} }
@ -194,36 +197,34 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
} }
private void spawnEffect(World w, BlockPos pos) { private void spawnEffect(World w, BlockPos pos) {
IBlockState state = w.getBlockState(pos); BlockState state = w.getBlockState(pos);
if (state.getBlock() != Blocks.AIR) { if (!state.isAir() && w.getBlockState(pos.up()).isAir()) {
if (w.getBlockState(pos.up()).getBlock() == Blocks.AIR) {
WorldEvent.DESTROY_BLOCK.play(w, pos, state); WorldEvent.DESTROY_BLOCK.play(w, pos, state);
} }
} }
}
@Override @Override
public void preApply(IPlayer player) { public void preApply(IPlayer player) {
player.addExertion(40); player.addExertion(40);
player.getOwner().spawnRunningParticles(); player.getOwner().attemptSprintingParticles();
} }
@Override @Override
public void postApply(IPlayer player) { public void postApply(IPlayer player) {
int timeDiff = getCooldownTime(player) - player.getAbilities().getRemainingCooldown(); int timeDiff = getCooldownTime(player) - player.getAbilities().getRemainingCooldown();
if (player.getOwner().getEntityWorld().getWorldTime() % 1 == 0 || timeDiff == 0) { if (player.getOwner().getEntityWorld().getTime() % 1 == 0 || timeDiff == 0) {
spawnParticleRing(player.getOwner(), timeDiff, 1); spawnParticleRing(player.getOwner(), timeDiff, 1);
} }
} }
private void spawnParticleRing(EntityPlayer player, int timeDiff) { private void spawnParticleRing(PlayerEntity player, int timeDiff) {
spawnParticleRing(player, timeDiff, 0); spawnParticleRing(player, timeDiff, 0);
} }
private void spawnParticleRing(EntityPlayer player, int timeDiff, double yVel) { private void spawnParticleRing(PlayerEntity player, int timeDiff, double yVel) {
int animationTicks = (int)(timeDiff / 10); int animationTicks = timeDiff / 10;
if (animationTicks < 6) { if (animationTicks < 6) {
IShape shape = new Sphere(true, animationTicks, 1, 0, 1); IShape shape = new Sphere(true, animationTicks, 1, 0, 1);
@ -232,28 +233,28 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
yVel *= y * 5; yVel *= y * 5;
for (int i = 0; i < shape.getVolumeOfSpawnableSpace(); i++) { for (int i = 0; i < shape.getVolumeOfSpawnableSpace(); i++) {
Vec3d point = shape.computePoint(player.getEntityWorld().rand); Vec3d point = shape.computePoint(player.getEntityWorld().random);
Particles.instance().spawnParticle(EnumParticleTypes.BLOCK_CRACK.getParticleID(), false, player.world.addParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, Blocks.DIRT.getDefaultState()),
player.posX + point.x, player.x + point.x,
player.posY + y + point.y, player.y + y + point.y,
player.posZ + point.z, player.z + point.z,
0, yVel, 0, 0, yVel, 0
Block.getStateId(Blocks.DIRT.getDefaultState())); );
} }
} }
} }
private void removeTree(World w, BlockPos pos) { private void removeTree(World w, BlockPos pos) {
IBlockState log = w.getBlockState(pos); BlockState log = w.getBlockState(pos);
int size = measureTree(w, log, pos); int size = measureTree(w, log, pos);
if (size > 0) { if (size > 0) {
pos = ascendTrunk(new ArrayList<BlockPos>(), w, pos, log, 0); removeTreePart( w, log, ascendTrunk(new ArrayList<BlockPos>(), w, pos, log, 0), 0);
removeTreePart( w, log, pos, 0);
} }
} }
private BlockPos ascendTrunk(List<BlockPos> done, World w, BlockPos pos, IBlockState log, int level) { private BlockPos ascendTrunk(List<BlockPos> done, World w, BlockPos pos, BlockState log, int level) {
if (level < 3 && !done.contains(pos)) { if (level < 3 && !done.contains(pos)) {
done.add(pos); done.add(pos);
@ -280,26 +281,25 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
return pos; return pos;
} }
private void removeTreePart(World w, IBlockState log, BlockPos pos, int level) { private void removeTreePart(World w, BlockState log, BlockPos pos, int level) {
if (level < 10 && isWoodOrLeaf(w, log, pos)) { if (level < 10 && isWoodOrLeaf(w, log, pos)) {
if (level < 5) { if (level < 5) {
w.destroyBlock(pos, true); w.breakBlock(pos, true);
} else { } else {
IBlockState state = w.getBlockState(pos); Block.dropStacks(w.getBlockState(pos), w, pos);
state.getBlock().dropBlockAsItem(w, pos, state, 0);
w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3); w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
} }
PosHelper.all(pos, p -> { PosHelper.all(pos, p -> {
removeTreePart(w, log, p, level + 1); removeTreePart(w, log, p, level + 1);
}, UP, NORTH, SOUTH, EAST, WEST); }, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
} }
} }
private BlockPos ascendTree(World w, IBlockState log, BlockPos pos, boolean remove) { private BlockPos ascendTree(World w, BlockState log, BlockPos pos, boolean remove) {
int breaks = 0; int breaks = 0;
IBlockState state; BlockState state;
while (variantAndBlockEquals(w.getBlockState(pos.up()), log)) { while (variantAndBlockEquals(w.getBlockState(pos.up()), log)) {
if (PosHelper.some(pos, p -> isLeaves(w.getBlockState(p), log), HORIZONTALS)) { if (PosHelper.some(pos, p -> isLeaves(w.getBlockState(p), log), HORIZONTALS)) {
break; break;
@ -307,10 +307,10 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
if (remove) { if (remove) {
if (breaks < 10) { if (breaks < 10) {
w.destroyBlock(pos, true); w.breakBlock(pos, true);
} else { } else {
state = w.getBlockState(pos); state = w.getBlockState(pos);
state.getBlock().dropBlockAsItem(w, pos, state, 0); Block.dropStacks(state, w, pos);
w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3); w.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
} }
breaks++; breaks++;
@ -321,17 +321,17 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
} }
private int dropApples(World w, BlockPos pos) { private int dropApples(World w, BlockPos pos) {
IBlockState log = w.getBlockState(pos); BlockState log = w.getBlockState(pos);
int size = measureTree(w, log, pos); int size = measureTree(w, log, pos);
if (size > 0) { if (size > 0) {
List<EntityItem> capturedDrops = Lists.newArrayList(); List<ItemEntity> capturedDrops = Lists.newArrayList();
dropApplesPart(capturedDrops, new ArrayList<BlockPos>(), w, log, pos, 0); dropApplesPart(capturedDrops, new ArrayList<BlockPos>(), w, log, pos, 0);
UWorld.enqueueTask(wo -> { UWorld.enqueueTask(wo -> {
capturedDrops.forEach(item -> { capturedDrops.forEach(item -> {
item.setNoPickupDelay(); item.setToDefaultPickupDelay();
wo.spawnEntity(item); wo.spawnEntity(item);
}); });
}); });
@ -342,48 +342,48 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
return 0; return 0;
} }
private void dropApplesPart(List<EntityItem> drops, List<BlockPos> done, World w, IBlockState log, BlockPos pos, int level) { private void dropApplesPart(List<ItemEntity> drops, List<BlockPos> done, World w, BlockState log, BlockPos pos, int level) {
if (!done.contains(pos)) { if (!done.contains(pos)) {
done.add(pos); done.add(pos);
pos = ascendTree(w, log, pos, false); pos = ascendTree(w, log, pos, false);
if (level < 10 && isWoodOrLeaf(w, log, pos)) { if (level < 10 && isWoodOrLeaf(w, log, pos)) {
IBlockState state = w.getBlockState(pos); BlockState state = w.getBlockState(pos);
if (state.getBlock() instanceof BlockLeaves && w.getBlockState(pos.down()).getMaterial() == Material.AIR) { if (state.getBlock() instanceof LeavesBlock && w.getBlockState(pos.down()).isAir()) {
WorldEvent.DESTROY_BLOCK.play(w, pos, state); WorldEvent.DESTROY_BLOCK.play(w, pos, state);
EntityItem item = new EntityItem(w); ItemEntity item = new ItemEntity(EntityType.ITEM, w);
item.setPosition(pos.getX() + w.rand.nextFloat(), pos.getY() - 0.5, pos.getZ() + w.rand.nextFloat()); item.setPosition(pos.getX() + w.random.nextFloat(), pos.getY() - 0.5, pos.getZ() + w.random.nextFloat());
item.setItem(getApple(w, log)); item.setStack(getApple(w, log));
drops.add(item); drops.add(item);
} }
PosHelper.all(pos, p -> { PosHelper.all(pos, p -> {
dropApplesPart(drops, done, w, log, p, level + 1); dropApplesPart(drops, done, w, log, p, level + 1);
}, UP, NORTH, SOUTH, EAST, WEST); }, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
} }
} }
} }
private ItemStack getApple(World w, IBlockState log) { private ItemStack getApple(World w, BlockState log) {
return ItemApple.getRandomItemStack(getVariant(log)); return ItemApple.getRandomItemStack(getVariant(log));
} }
private int measureTree(World w, IBlockState log, BlockPos pos) { private int measureTree(World w, BlockState log, BlockPos pos) {
List<BlockPos> logs = new ArrayList<BlockPos>(); List<BlockPos> logs = new ArrayList<>();
List<BlockPos> leaves = new ArrayList<BlockPos>(); List<BlockPos> leaves = new ArrayList<>();
countParts(logs, leaves, w, log, pos); countParts(logs, leaves, w, log, pos);
return logs.size() <= (leaves.size() / 2) ? logs.size() + leaves.size() : 0; return logs.size() <= (leaves.size() / 2) ? logs.size() + leaves.size() : 0;
} }
private BlockPos getBaseOfTree(World w, IBlockState log, BlockPos pos) { private BlockPos getBaseOfTree(World w, BlockState log, BlockPos pos) {
return getBaseOfTreePart(new ArrayList<BlockPos>(), w, log, pos); return getBaseOfTreePart(new ArrayList<BlockPos>(), w, log, pos);
} }
private BlockPos getBaseOfTreePart(List<BlockPos> done, World w, IBlockState log, BlockPos pos) { private BlockPos getBaseOfTreePart(List<BlockPos> done, World w, BlockState log, BlockPos pos) {
if (done.contains(pos) || !variantAndBlockEquals(w.getBlockState(pos), log)) { if (done.contains(pos) || !variantAndBlockEquals(w.getBlockState(pos), log)) {
return null; return null;
} }
@ -421,20 +421,20 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
return pos; return pos;
} }
private boolean isWoodOrLeaf(World w, IBlockState log, BlockPos pos) { private boolean isWoodOrLeaf(World w, BlockState log, BlockPos pos) {
IBlockState state = w.getBlockState(pos); BlockState state = w.getBlockState(pos);
return variantAndBlockEquals(state, log) || (isLeaves(state, log) && ((Boolean)state.getValue(BlockLeaves.DECAYABLE)).booleanValue()); return variantAndBlockEquals(state, log) || (isLeaves(state, log) && state.get(LeavesBlock.PERSISTENT));
} }
private void countParts(List<BlockPos> logs, List<BlockPos> leaves, World w, IBlockState log, BlockPos pos) { private void countParts(List<BlockPos> logs, List<BlockPos> leaves, World w, BlockState log, BlockPos pos) {
if (logs.contains(pos) || leaves.contains(pos)) { if (logs.contains(pos) || leaves.contains(pos)) {
return; return;
} }
IBlockState state = w.getBlockState(pos); BlockState state = w.getBlockState(pos);
boolean yay = false; boolean yay = false;
if (state.getBlock() instanceof BlockLeaves && ((Boolean)state.getValue(BlockLeaves.DECAYABLE)).booleanValue() && variantEquals(state, log)) { if (state.getBlock() instanceof LeavesBlock && state.get(LeavesBlock.PERSISTENT) && variantEquals(state, log)) {
leaves.add(pos); leaves.add(pos);
yay = true; yay = true;
} else if (variantAndBlockEquals(state, log)) { } else if (variantAndBlockEquals(state, log)) {
@ -445,33 +445,31 @@ public class PowerStomp implements IPower<PowerStomp.Data> {
if (yay) { if (yay) {
PosHelper.all(pos, p -> { PosHelper.all(pos, p -> {
countParts(logs, leaves, w, log, p); countParts(logs, leaves, w, log, p);
}, UP, NORTH, SOUTH, EAST, WEST); }, Direction.UP, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST);
} }
} }
private boolean isLeaves(IBlockState state, IBlockState log) { private boolean isLeaves(BlockState state, BlockState log) {
return state.getBlock() instanceof BlockLeaves && variantEquals(state, log); return state.getBlock() instanceof LeavesBlock && variantEquals(state, log);
} }
private boolean variantAndBlockEquals(IBlockState one, IBlockState two) { private boolean variantAndBlockEquals(BlockState one, BlockState two) {
return (one.getBlock() == two.getBlock()) && variantEquals(one, two); return (one.getBlock() == two.getBlock()) && variantEquals(one, two);
} }
private boolean variantEquals(IBlockState one, IBlockState two) { private boolean variantEquals(BlockState one, BlockState two) {
return getVariant(one) == getVariant(two); return getVariant(one) == getVariant(two);
} }
private Object getVariant(IBlockState state) { private Object getVariant(BlockState state) {
if (state.getBlock() instanceof BlockLeaves) { if (state.getBlock() instanceof LeavesBlock) {
return ((BlockLeaves)state.getBlock()).getWoodType(state.getBlock().getMetaFromState(state)); return ((LeavesBlock)state.getBlock()).getWoodType(state);
} }
for (Entry<IProperty<?>, ?> i : state.getProperties().entrySet()) { return state.getEntries().entrySet().stream()
if (i.getKey().getName().contentEquals("variant")) { .filter(i -> i.getKey().getName().contentEquals("variant"))
return i.getValue(); .map(i -> i.getValue())
} .findFirst().orElse(null);
}
return null;
} }
protected static class Data extends Location { protected static class Data extends Location {

View file

@ -0,0 +1,174 @@
package com.minelittlepony.unicopia.ability.powers;
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.ability.Location;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.util.VecHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.FenceBlock;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.WallBlock;
import net.minecraft.client.network.packet.EntityPassengersSetS2CPacket;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
public class PowerTeleport implements IPower<Location> {
@Override
public String getKeyName() {
return "unicopia.power.teleport";
}
@Override
public int getKeyCode() {
return GLFW.GLFW_KEY_O;
}
@Override
public int getWarmupTime(IPlayer player) {
return 20;
}
@Override
public int getCooldownTime(IPlayer player) {
return 50;
}
@Override
public boolean canUse(Race playerSpecies) {
return playerSpecies.canCast();
}
@Override
public Location tryActivate(IPlayer player) {
HitResult ray = VecHelper.getObjectMouseOver(player.getOwner(), 100, 1);
World w = player.getWorld();
if (ray.getType() == HitResult.Type.MISS) {
return null;
}
BlockPos pos;
if (ray.getType() == HitResult.Type.ENTITY) {
pos = new BlockPos(ray.getPos());
} else {
pos = ((BlockHitResult)ray).getBlockPos();
}
boolean airAbove = enterable(w, pos.up()) && enterable(w, pos.up(2));
if (exception(w, pos, player.getOwner())) {
Direction sideHit = ((BlockHitResult)ray).getSide();
if (player.getOwner().isSneaking()) {
sideHit = sideHit.getOpposite();
}
pos = pos.offset(sideHit);
}
if (enterable(w, pos.down())) {
pos = pos.down();
if (enterable(w, pos.down())) {
if (!airAbove) {
return null;
}
pos = new BlockPos(
ray.getPos().getX(),
pos.getY() + 2,
ray.getPos().getZ());
}
}
if ((!enterable(w, pos) && exception(w, pos, player.getOwner()))
|| (!enterable(w, pos.up()) && exception(w, pos.up(), player.getOwner()))) {
return null;
}
return new Location(pos.getX(), pos.getY(), pos.getZ());
}
@Override
public Class<Location> getPackageType() {
return Location.class;
}
@Override
public void apply(IPlayer iplayer, Location data) {
iplayer.getWorld().playSound(null, iplayer.getOrigin(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1, 1);
PlayerEntity player = iplayer.getOwner();
double distance = player.squaredDistanceTo(data.x, data.y, data.z) / 10;
if (player.hasVehicle()) {
Entity mount = player.getVehicle();
player.stopRiding();
if (mount instanceof ServerPlayerEntity) {
((ServerPlayerEntity)player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player));
}
}
player.setPosition(
data.x + (player.x - Math.floor(player.x)),
data.y,
data.z + (player.z - Math.floor(player.z)));
iplayer.subtractEnergyCost(distance);
player.fallDistance /= distance;
player.world.playSound(null, data.pos(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1, 1);
}
private boolean enterable(World w, BlockPos pos) {
BlockState state = w.getBlockState(pos);
Block block = state.getBlock();
return w.isAir(pos)
|| !state.isOpaque()
|| (block instanceof LeavesBlock);
}
private boolean exception(World w, BlockPos pos, PlayerEntity player) {
BlockState state = w.getBlockState(pos);
Block c = state.getBlock();
return state.hasSolidTopSurface(w, pos, player)
|| state.getMaterial().isLiquid()
|| (c instanceof WallBlock)
|| (c instanceof FenceBlock)
|| (c instanceof LeavesBlock);
}
@Override
public void preApply(IPlayer player) {
player.addExertion(3);
player.spawnParticles(UParticles.UNICORN_MAGIC, 5);
}
@Override
public void postApply(IPlayer player) {
player.spawnParticles(UParticles.UNICORN_MAGIC, 5);
}
}

View file

@ -1,4 +1,4 @@
package com.minelittlepony.unicopia.power; package com.minelittlepony.unicopia.ability.powers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -7,7 +7,9 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.input.Keyboard; import com.minelittlepony.unicopia.ability.IData;
import com.minelittlepony.unicopia.ability.IPower;
import com.minelittlepony.unicopia.client.input.Keyboard;
public class PowersRegistry { public class PowersRegistry {

View file

@ -0,0 +1,83 @@
package com.minelittlepony.unicopia.ability.powers.render;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.magic.spells.SpellDisguise;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.entity.Entity;
public class DisguiseRenderer {
private static final DisguiseRenderer INSTANCE = new DisguiseRenderer();
public static DisguiseRenderer getInstance() {
return INSTANCE;
}
private final MinecraftClient mc = MinecraftClient.getInstance();
private boolean rendering;
public boolean renderDisguise(Entity entity, float usedPartialTick) {
EntityRenderDispatcher renderMan = mc.getEntityRenderManager();
if (rendering) {
renderMan.setRenderShadows(true);
renderStaticDisguise(renderMan, entity);
renderMan.setRenderShadows(false);
return true;
} else {
renderMan.setRenderShadows(renderMan.shouldRenderShadows() || usedPartialTick != 1);
}
return false;
}
protected void renderStaticDisguise(EntityRenderDispatcher renderMan, Entity entity) {
Entity observer = mc.getCameraEntity();
double x = entity.x - observer.x;
double y = entity.y - observer.y;
double z = entity.z - observer.z;
renderDisguise(renderMan, entity, x, y, z);
}
public boolean renderDisguiseToGui(IPlayer player) {
SpellDisguise effect = player.getEffect(SpellDisguise.class, false);
if (effect == null || effect.getDead()) {
return false;
}
EntityRenderDispatcher renderMan = mc.getEntityRenderManager();
if (renderMan.shouldRenderShadows()) {
return false;
}
Entity e = effect.getDisguise();
// Check for a disguise and render it in our place.
if (e != null) {
effect.update(player);
e.setCustomNameVisible(false);
e.setInvisible(false);
e.y = player.getOwner().y;
renderDisguise(renderMan, e, 0, 0, 0);
}
return true;
}
protected void renderDisguise(EntityRenderDispatcher renderMan, Entity entity, double x, double y, double z) {
rendering = false;
renderMan.render(entity, x, y, z, 0, 1, false);
rendering = true;
}
}

View file

@ -0,0 +1,52 @@
package com.minelittlepony.unicopia.advancements;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.advancement.criterion.Criterion;
import net.minecraft.advancement.criterion.CriterionConditions;
public abstract class AbstractCriterion<E extends AbstractCriterion.Entry<T>, T extends CriterionConditions> implements Criterion<T> {
protected final Map<PlayerAdvancementTracker, E> listeners = Maps.newHashMap();
@Override
public void beginTrackingCondition(PlayerAdvancementTracker key, Criterion.ConditionsContainer<T> listener) {
listeners.computeIfAbsent(key, this::createEntry).listeners.add(listener);
}
@Override
public void endTrackingCondition(PlayerAdvancementTracker key, Criterion.ConditionsContainer<T> listener) {
if (listeners.containsKey(key)) {
E entry = listeners.get(key);
entry.listeners.remove(listener);
if (entry.listeners.isEmpty()) {
listeners.remove(key);
}
}
}
@Override
public void endTracking(PlayerAdvancementTracker key) {
if (listeners.containsKey(key)) {
listeners.remove(key);
}
}
protected abstract E createEntry(PlayerAdvancementTracker advancement);
protected static class Entry<T extends CriterionConditions> {
protected final PlayerAdvancementTracker advancement;
protected final List<Criterion.ConditionsContainer<T>> listeners = Lists.newArrayList();
Entry(PlayerAdvancementTracker key) {
advancement = key;
}
}
}

View file

@ -1,52 +0,0 @@
package com.minelittlepony.unicopia.advancements;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.minecraft.advancements.ICriterionTrigger;
import net.minecraft.advancements.PlayerAdvancements;
import net.minecraft.advancements.critereon.AbstractCriterionInstance;
public abstract class AbstractTrigger<E extends AbstractTrigger.Entry<T>, T extends AbstractCriterionInstance> implements ICriterionTrigger<T> {
protected final Map<PlayerAdvancements, E> listeners = Maps.newHashMap();
@Override
public void addListener(PlayerAdvancements key, Listener<T> listener) {
listeners.computeIfAbsent(key, this::createEntry).listeners.add(listener);;
}
@Override
public void removeListener(PlayerAdvancements key, Listener<T> listener) {
if (listeners.containsKey(key)) {
E entry = listeners.get(key);
entry.listeners.remove(listener);
if (entry.listeners.isEmpty()) {
listeners.remove(key);
}
}
}
@Override
public void removeAllListeners(PlayerAdvancements key) {
if (listeners.containsKey(key)) {
listeners.remove(key);
}
}
protected abstract E createEntry(PlayerAdvancements advancement);
protected static class Entry<T extends AbstractCriterionInstance> {
protected final PlayerAdvancements advancement;
protected final List<Listener<T>> listeners = Lists.newArrayList();
Entry(PlayerAdvancements key) {
advancement = key;
}
}
}

View file

@ -2,30 +2,30 @@ package com.minelittlepony.unicopia.advancements;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import net.minecraft.advancements.Advancement; import net.minecraft.advancement.Advancement;
import net.minecraft.advancements.PlayerAdvancements; import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.util.ResourceLocation; import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.WorldServer; import net.minecraft.util.Identifier;
/** /**
* Predicate for testing whether a player has a previous advancement. * Predicate for testing whether a player has a previous advancement.
* Allows for unlocking advancements in linear succession. * Allows for unlocking advancements in linear succession.
*/ */
public class AdvancementPredicate { class AdvancementPredicate {
public static AdvancementPredicate deserialize(JsonElement json) { public static AdvancementPredicate deserialize(JsonElement json) {
return new AdvancementPredicate(json.getAsString()); return new AdvancementPredicate(json.getAsString());
} }
private final ResourceLocation id; private final Identifier id;
public AdvancementPredicate(String advancement) { public AdvancementPredicate(String advancement) {
this.id = new ResourceLocation(advancement); this.id = new Identifier(advancement);
} }
public boolean test(WorldServer world, PlayerAdvancements playerAdvancements) { public boolean test(ServerWorld world, PlayerAdvancementTracker tracker) {
Advancement advancement = world.getAdvancementManager().getAdvancement(id); Advancement advancement = world.getServer().getAdvancementManager().get(id);
return advancement != null && playerAdvancements.getProgress(advancement).isDone(); return advancement != null && tracker.getProgress(advancement).isDone();
} }
} }

View file

@ -0,0 +1,74 @@
package com.minelittlepony.unicopia.advancements;
import java.util.Optional;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
/**
* Advantement trigger for the book of holding. It's an achievement to die so spectacularly! :D
*/
public class BOHDeathCriterion extends AbstractCriterion<BOHDeathCriterion.Entry, BOHDeathCriterion.Conditions> {
// TODO: Need to register this
public static final BOHDeathCriterion INSTANCE = new BOHDeathCriterion();
private static final Identifier ID = new Identifier("unicopia", "death_by_bag_of_holding");
@Override
public Identifier getId() {
return ID;
}
@Override
public Conditions conditionsFromJson(JsonObject json, JsonDeserializationContext context) {
return new Conditions(AdvancementPredicate.deserialize(json.get("advancement")));
}
@Override
protected Entry createEntry(PlayerAdvancementTracker advancement) {
return new Entry(advancement);
}
public void trigger(ServerPlayerEntity player) {
PlayerAdvancementTracker key = player.getAdvancementManager();
Optional.ofNullable(listeners.get(key)).ifPresent(e -> {
e.trigger((ServerWorld)player.world, key);
});
}
static class Conditions extends AbstractCriterionConditions {
private final AdvancementPredicate requirement;
public Conditions(AdvancementPredicate key) {
super(ID);
requirement = key;
}
public boolean test(ServerWorld world, PlayerAdvancementTracker stracker) {
return requirement.test(world, stracker);
}
}
static class Entry extends AbstractCriterion.Entry<BOHDeathCriterion.Conditions> {
Entry(PlayerAdvancementTracker key) {
super(key);
}
public void trigger(ServerWorld world, PlayerAdvancementTracker tracker) {
listeners.stream()
.filter(listener -> listener.getConditions().test(world, tracker))
.forEach(winner -> winner.apply(advancement));
}
}
}

View file

@ -1,73 +0,0 @@
package com.minelittlepony.unicopia.advancements;
import java.util.Optional;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.advancements.PlayerAdvancements;
import net.minecraft.advancements.critereon.AbstractCriterionInstance;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.WorldServer;
/**
* Advantement trigger for the book of holding. It's an achievement to die so spectacularly! :D
*/
public class BOHDeathTrigger extends AbstractTrigger<BOHDeathTrigger.Entry, BOHDeathTrigger.Instance> {
private static final ResourceLocation ID = new ResourceLocation("unicopia", "death_by_bag_of_holding");
@Override
public ResourceLocation getId() {
return ID;
}
@Override
public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) {
return new Instance(AdvancementPredicate.deserialize(json.get("advancement")));
}
@Override
protected Entry createEntry(PlayerAdvancements advancement) {
return new Entry(advancement);
}
public void trigger(EntityPlayerMP player) {
PlayerAdvancements key = player.getAdvancements();
Optional.ofNullable(listeners.get(key)).ifPresent(e -> {
e.trigger((WorldServer)player.world, key);
});
}
static class Instance extends AbstractCriterionInstance {
private final AdvancementPredicate requirement;
public Instance(AdvancementPredicate key) {
super(ID);
requirement = key;
}
public boolean test(WorldServer world, PlayerAdvancements playerAdvancements) {
return requirement.test(world, playerAdvancements);
}
}
static class Entry extends AbstractTrigger.Entry<BOHDeathTrigger.Instance> {
Entry(PlayerAdvancements key) {
super(key);
}
public void trigger(WorldServer world, PlayerAdvancements playerAdvancements) {
listeners.stream()
.filter(listener -> listener.getCriterionInstance().test(world, playerAdvancements))
.forEach(winner -> winner.grantCriterion(advancement));;
}
}
}

View file

@ -1,11 +0,0 @@
package com.minelittlepony.unicopia.advancements;
import net.minecraft.advancements.CriteriaTriggers;
public class UAdvancements {
public static final BOHDeathTrigger BOH_DEATH = new BOHDeathTrigger();
public static void init() {
CriteriaTriggers.register(BOH_DEATH);
}
}

View file

@ -4,55 +4,51 @@ import java.util.Random;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.init.UItems; import com.minelittlepony.unicopia.UItems;
import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockState;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.CropBlock;
import net.minecraft.block.properties.PropertyInteger; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable; import net.minecraft.item.Items;
import net.minecraft.util.NonNullList; import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.state.property.IntProperty;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.util.math.Box;
import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeHooks;
public class BlockAlfalfa extends BlockCrops { public class BlockAlfalfa extends CropBlock {
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 4); public static final IntProperty AGE = IntProperty.of("age", 0, 4);
public static final PropertyEnum<Half> HALF = PropertyEnum.create("half", Half.class); public static final EnumProperty<Half> HALF = EnumProperty.of("half", Half.class);
private static final AxisAlignedBB[] BOUNDS = new AxisAlignedBB[] { private static final Box[] BOUNDS = new Box[] {
new AxisAlignedBB(0, 0, 0, 1, 0.1, 1), new Box(0, 0, 0, 1, 0.1, 1),
new AxisAlignedBB(0, 0, 0, 1, 0.2, 1), new Box(0, 0, 0, 1, 0.2, 1),
new AxisAlignedBB(0, 0, 0, 1, 0.4, 1), new Box(0, 0, 0, 1, 0.4, 1),
new AxisAlignedBB(0, 0, 0, 1, 0.6, 1), new Box(0, 0, 0, 1, 0.6, 1),
new AxisAlignedBB(0, 0, 0, 1, 0.8, 1), new Box(0, 0, 0, 1, 0.8, 1),
new AxisAlignedBB(0, 0, 0, 1, 1, 1), new Box(0, 0, 0, 1, 1, 1),
new AxisAlignedBB(0, 0, 0, 1, 1.2, 1), new Box(0, 0, 0, 1, 1.2, 1),
new AxisAlignedBB(0, 0, 0, 1, 1.4, 1), new Box(0, 0, 0, 1, 1.4, 1),
new AxisAlignedBB(0, 0, 0, 1, 1.6, 1), new Box(0, 0, 0, 1, 1.6, 1),
new AxisAlignedBB(0, 0, 0, 1, 1.8, 1), new Box(0, 0, 0, 1, 1.8, 1),
new AxisAlignedBB(0, 0, 0, 1, 2, 1), new Box(0, 0, 0, 1, 2, 1),
new AxisAlignedBB(0, 0, 0, 1, 2.2, 1), new Box(0, 0, 0, 1, 2.2, 1),
new AxisAlignedBB(0, 0, 0, 1, 2.4, 1), new Box(0, 0, 0, 1, 2.4, 1),
new AxisAlignedBB(0, 0, 0, 1, 2.6, 1), new Box(0, 0, 0, 1, 2.6, 1),
new AxisAlignedBB(0, 0, 0, 1, 2.8, 1), new Box(0, 0, 0, 1, 2.8, 1),
new AxisAlignedBB(0, 0, 0, 1, 3, 1) new Box(0, 0, 0, 1, 3, 1)
}; };
public BlockAlfalfa(String domain, String name) { public BlockAlfalfa(String domain, String name) {
setRegistryName(domain, name); setRegistryName(domain, name);
setTranslationKey(name); setTranslationKey(name);
setDefaultState(getDefaultState().withProperty(HALF, Half.BOTTOM)); setDefaultState(getDefaultState().with(HALF, Half.BOTTOM));
} }
@Override @Override
@ -61,7 +57,7 @@ public class BlockAlfalfa extends BlockCrops {
} }
@Override @Override
protected PropertyInteger getAgeProperty() { public IntProperty getAgeProperty() {
return AGE; return AGE;
} }
@ -71,7 +67,7 @@ public class BlockAlfalfa extends BlockCrops {
} }
@Override @Override
protected Item getSeed() { protected Item getSeedsItem() {
return UItems.alfalfa_seeds; return UItems.alfalfa_seeds;
} }
@ -81,37 +77,32 @@ public class BlockAlfalfa extends BlockCrops {
} }
@Override @Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) {
checkAndDropBlock(world, pos, state); checkAndDropBlock(world, pos, state);
if (rand.nextInt(10) != 0) { if (rand.nextInt(10) != 0) {
if (world.isAreaLoaded(pos, 1) && world.getLightFromNeighbors(pos.up()) >= 9) { if (world.isBlockLoaded(pos) && world.getLightLevel(pos.up()) >= 9) {
if (canGrow(world, pos, state, false)) { if (canGrow(world, rand, pos, state)) {
float f = getGrowthChance(this, world, pos);
if(ForgeHooks.onCropsGrowPre(world, pos, state, rand.nextInt((int)(25 / f) + 1) == 0)) {
growUpwards(world, pos, state, 1); growUpwards(world, pos, state, 1);
ForgeHooks.onCropsGrowPost(world, pos, state, world.getBlockState(pos));
}
} }
} }
} }
} }
@Override @Override
protected boolean canSustainBush(IBlockState state) { protected boolean canSustainBush(BlockState state) {
return super.canSustainBush(state) || state.getBlock() == this; return super.canSustainBush(state) || state.getBlock() == this;
} }
protected void growUpwards(World world, BlockPos pos, IBlockState state, int increase) { protected void growUpwards(World world, BlockPos pos, BlockState state, int increase) {
boolean hasDown = world.getBlockState(pos.down()).getBlock() == this; boolean hasDown = world.getBlockState(pos.down()).getBlock() == this;
boolean hasTrunk = world.getBlockState(pos.down(2)).getBlock() == this; boolean hasTrunk = world.getBlockState(pos.down(2)).getBlock() == this;
boolean hasRoot = world.getBlockState(pos.down(3)).getBlock() == this; boolean hasRoot = world.getBlockState(pos.down(3)).getBlock() == this;
if (state.getBlock() != this) { if (state.getBlock() != this) {
if (state.getBlock().isAir(state, world, pos)) { if (state.isAir()) {
if (!(hasDown && hasTrunk && hasRoot)) { if (!(hasDown && hasTrunk && hasRoot)) {
world.setBlockState(pos, withAge(increase).withProperty(HALF, Half.TOP)); world.setBlockState(pos, withAge(increase).with(HALF, Half.TOP));
} }
} }
return; return;
@ -130,17 +121,17 @@ public class BlockAlfalfa extends BlockCrops {
boolean hasUp = world.getBlockState(pos.up()).getBlock() == this; boolean hasUp = world.getBlockState(pos.up()).getBlock() == this;
if (hasDown && hasUp) { if (hasDown && hasUp) {
world.setBlockState(pos, withAge(age).withProperty(HALF, Half.MIDDLE)); world.setBlockState(pos, withAge(age).with(HALF, Half.MIDDLE));
} else if (hasUp) { } else if (hasUp) {
world.setBlockState(pos, withAge(age).withProperty(HALF, Half.BOTTOM)); world.setBlockState(pos, withAge(age).with(HALF, Half.BOTTOM));
} else { } else {
world.setBlockState(pos, withAge(age).withProperty(HALF, Half.TOP)); world.setBlockState(pos, withAge(age).with(HALF, Half.TOP));
} }
} }
@Override @Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) { public Item getItemDropped(BlockState state, Random rand, int fortune) {
if (state.getValue(HALF) != Half.BOTTOM) { if (state.get(HALF) != Half.BOTTOM) {
return Items.AIR; return Items.AIR;
} }
@ -148,8 +139,8 @@ public class BlockAlfalfa extends BlockCrops {
} }
@Override @Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { public void getDrops(NonNullList<ItemStack> drops, BlockView world, BlockPos pos, BlockState state, int fortune) {
Random rand = world instanceof World ? ((World)world).rand : RANDOM; Random rand = world instanceof World ? ((World)world).random : RANDOM;
Item item = getItemDropped(state, rand, fortune); Item item = getItemDropped(state, rand, fortune);
if (item != Items.AIR) { if (item != Items.AIR) {
@ -162,40 +153,32 @@ public class BlockAlfalfa extends BlockCrops {
} }
@Override @Override
public int quantityDropped(IBlockState state, int fortune, Random random) { public int quantityDropped(BlockState state, int fortune, Random random) {
return 1; return 1;
} }
@Override @Override
public boolean canBlockStay(World world, BlockPos pos, IBlockState state) { public boolean canBlockStay(World world, BlockPos pos, BlockState state) {
return getHalf(state) != Half.BOTTOM || super.canBlockStay(world, pos, state); return getHalf(state) != Half.BOTTOM || super.canBlockStay(world, pos, state);
} }
public void onPlayerDestroy(World worldIn, BlockPos pos, IBlockState state) { public void onPlayerDestroy(World worldIn, BlockPos pos, BlockState state) {
breakConnectedBlocks(worldIn, pos, null); breakConnectedBlocks(worldIn, pos, null);
} }
@Override @Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) { public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
breakConnectedBlocks(worldIn, pos, player); breakConnectedBlocks(worldIn, pos, player);
} }
protected void breakConnectedBlocks(World worldIn, BlockPos pos, @Nullable EntityPlayer player) { protected void breakConnectedBlocks(World worldIn, BlockPos pos, @Nullable PlayerEntity player) {
IBlockState state = worldIn.getBlockState(pos); BlockState state = worldIn.getBlockState(pos);
if (state.getBlock() != this) { if (state.getBlock() != this) {
return; return;
} }
if (player != null && player.capabilities.isCreativeMode) { worldIn.breakBlock(pos, true);
worldIn.setBlockToAir(pos);
} else {
if (worldIn.isRemote) {
worldIn.setBlockToAir(pos);
} else {
worldIn.destroyBlock(pos, true);
}
}
Half half = getHalf(state); Half half = getHalf(state);
@ -218,26 +201,25 @@ public class BlockAlfalfa extends BlockCrops {
} }
@Override @Override
public boolean canCollideCheck(IBlockState state, boolean hitIfLiquid) { public boolean canCollideCheck(BlockState state, boolean hitIfLiquid) {
return getHalf(state) != Half.MIDDLE; return getHalf(state) != Half.MIDDLE;
} }
@Deprecated
@Override @Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { public Box getBoundingBox(BlockState state, BlockView source, BlockPos pos) {
return BOUNDS[Math.min(BOUNDS.length - 1, getFullAge(source, pos))].offset(getOffset(state, source, pos)); return BOUNDS[Math.min(BOUNDS.length - 1, getFullAge(source, pos))].offset(getOffset(state, source, pos));
} }
@Override @Override
public boolean canGrow(World world, BlockPos pos, IBlockState state, boolean isClient) { public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
Half half = getHalf(state); Half half = getHalf(state);
if (half == Half.MIDDLE || (half == Half.TOP && world.getBlockState(pos.down()).getBlock() == this)) { if (half == Half.MIDDLE || (half == Half.TOP && world.getBlockState(pos.down()).getBlock() == this)) {
return false; return false;
} }
IBlockState above = world.getBlockState(pos.up(1)); BlockState above = world.getBlockState(pos.up(1));
IBlockState higher = world.getBlockState(pos.up(2)); BlockState higher = world.getBlockState(pos.up(2));
boolean iCanGrow = !isMaxAge(state); boolean iCanGrow = !isMaxAge(state);
boolean aboveCanGrow = above.getBlock() != this || !isMaxAge(above); boolean aboveCanGrow = above.getBlock() != this || !isMaxAge(above);
@ -247,13 +229,13 @@ public class BlockAlfalfa extends BlockCrops {
} }
@Override @Override
public void grow(World world, BlockPos pos, IBlockState state) { public void applyGrowth(World world, BlockPos pos, BlockState state) {
growUpwards(world, pos, state, getBonemealAgeIncrease(world)); growUpwards(world, pos, state, getBonemealAgeIncrease(world));
} }
protected BlockPos getTip(World world, BlockPos pos) { protected BlockPos getTip(World world, BlockPos pos) {
BlockPos above = pos.up(); BlockPos above = pos.up();
IBlockState state = world.getBlockState(above); BlockState state = world.getBlockState(above);
if (state.getBlock() == this) { if (state.getBlock() == this) {
return getTip(world, above); return getTip(world, above);
@ -262,35 +244,29 @@ public class BlockAlfalfa extends BlockCrops {
return pos; return pos;
} }
protected int getFullAge(IBlockAccess world, BlockPos pos) { protected int getFullAge(BlockView world, BlockPos pos) {
IBlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
int age = 0; int age = 0;
if (state.getBlock() == this) { if (state.getBlock() == this) {
age += state.getValue(getAgeProperty()); age += state.get(getAgeProperty());
age += getFullAge(world, pos.up()); age += getFullAge(world, pos.up());
} }
return age; return age;
} }
protected Half getHalf(IBlockState state) { protected Half getHalf(BlockState state) {
return (Half)state.getValue(HALF); return state.get(HALF);
} }
@Override @Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) { public BlockState getStateFromMeta(int meta) {
return EnumPlantType.Crop;
}
@Override
public IBlockState getStateFromMeta(int meta) {
int age = meta % (getMaxAge() + 1); int age = meta % (getMaxAge() + 1);
int half = (int)Math.floor(meta / (getMaxAge() + 1)) % Half.values().length; int half = (int)Math.floor(meta / (getMaxAge() + 1)) % Half.values().length;
return withAge(age).withProperty(HALF, Half.values()[half]); return withAge(age).with(HALF, Half.values()[half]);
} }
// 0: age:0, half:0 // 0: age:0, half:0
@ -310,14 +286,14 @@ public class BlockAlfalfa extends BlockCrops {
//14: age:4, half:2 //14: age:4, half:2
@Override @Override
public int getMetaFromState(IBlockState state) { public int getMetaFromState(BlockState state) {
int age = getAge(state); int age = getAge(state);
int half = getHalf(state).ordinal(); int half = getHalf(state).ordinal();
return (half * (getMaxAge() + 1)) + age; return (half * (getMaxAge() + 1)) + age;
} }
public static enum Half implements IStringSerializable { public enum Half implements StringIdentifiable {
TOP, TOP,
MIDDLE, MIDDLE,
BOTTOM; BOTTOM;
@ -330,12 +306,14 @@ public class BlockAlfalfa extends BlockCrops {
return this != BOTTOM; return this != BOTTOM;
} }
@Override
public String toString() { public String toString() {
return getName();
}
public String getName() {
return this == TOP ? "top" : this == MIDDLE ? "middle" : "bottom"; return this == TOP ? "top" : this == MIDDLE ? "middle" : "bottom";
} }
@Override
public String asString() {
return toString();
}
} }
} }

View file

@ -1,49 +0,0 @@
package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.init.UMaterials;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockChiselledChitin extends BlockDirected {
public BlockChiselledChitin(String domain, String name) {
super(UMaterials.hive, domain, name);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setHardness(50);
setResistance(2000);
}
@Override
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
return MapColor.BLACK;
}
@Deprecated
@Override
public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos) {
float hardness = super.getPlayerRelativeBlockHardness(state, player, worldIn, pos);
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(player);
Race race = iplayer.getPlayerSpecies();
if (race == Race.CHANGELING) {
hardness *= 80;
} else if (race.canInteractWithClouds()) {
hardness /= 4;
} else if (race.canUseEarth()) {
hardness *= 10;
}
return hardness;
}
}

View file

@ -1,113 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.init.UItems;
import com.minelittlepony.unicopia.init.UMaterials;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.properties.PropertyEnum;
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.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockChitin extends Block {
public static final PropertyEnum<Covering> COVERING = PropertyEnum.create("covering", Covering.class);
public BlockChitin(String domain, String name) {
super(UMaterials.hive);
setTranslationKey(name);
setRegistryName(domain, name);
setDefaultState(blockState.getBaseState().withProperty(COVERING, Covering.UNCOVERED));
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setHardness(50);
setResistance(2000);
}
@Override
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
return MapColor.BLACK;
}
@Override
public int quantityDropped(Random random) {
return 3;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return UItems.chitin_shell;
}
@Deprecated
@Override
public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos) {
float hardness = super.getPlayerRelativeBlockHardness(state, player, worldIn, pos);
IPlayer iplayer = PlayerSpeciesList.instance().getPlayer(player);
Race race = iplayer.getPlayerSpecies();
if (race == Race.CHANGELING) {
hardness *= 80;
} else if (race.canInteractWithClouds()) {
hardness /= 4;
} else if (race.canUseEarth()) {
hardness *= 10;
}
return hardness;
}
@Override
public int getMetaFromState(IBlockState state) {
return 0;
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
IBlockState s = world.getBlockState(pos.up());
Block block = s.getBlock();
boolean snowy = block == Blocks.SNOW || block == Blocks.SNOW_LAYER;
boolean solid = (s.isFullBlock() && s.isFullCube()) || s.isSideSolid(world, pos.up(), EnumFacing.DOWN);
return state.withProperty(COVERING, snowy ? Covering.SNOW_COVERED : solid ? Covering.COVERED : Covering.UNCOVERED);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, COVERING);
}
public static enum Covering implements IStringSerializable {
COVERED,
UNCOVERED,
SNOW_COVERED;
@Override
public String toString() {
return getName();
}
@Override
public String getName() {
return name().toLowerCase();
}
}
}

View file

@ -6,9 +6,9 @@ import java.util.Random;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.init.UBlocks; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.item.ItemMoss; import com.minelittlepony.unicopia.item.ItemMoss;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
@ -20,7 +20,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -146,7 +146,7 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
} }
@Deprecated @Deprecated
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(state, entity)) { if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
} }
@ -177,7 +177,7 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable {
@Override @Override
public boolean canBeTilled(ItemStack hoe, EntityPlayer player, World world, IBlockState state, BlockPos pos) { public boolean canBeTilled(ItemStack hoe, EntityPlayer player, World world, IBlockState state, BlockPos pos) {
return PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canInteractWithClouds() return SpeciesList.instance().getPlayer(player).getSpecies().canInteractWithClouds()
&& ITillable.super.canBeTilled(hoe, player, world, state, pos); && ITillable.super.canBeTilled(hoe, player, world, state, pos);
} }

View file

@ -20,7 +20,7 @@ import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -128,7 +128,7 @@ public class BlockCloudAnvil extends BlockAnvil implements ICloudBlock {
} }
@Deprecated @Deprecated
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(state, entity)) { if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
} }

View file

@ -11,7 +11,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -22,28 +22,28 @@ public class BlockCloudBanister extends BlockCloudFence {
public static final double d = 5/16D; public static final double d = 5/16D;
public static final double h = 2/16D; public static final double h = 2/16D;
public static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(d, 0, l, l, h, 1); public static final Box SOUTH_AABB = new Box(d, 0, l, l, h, 1);
public static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0, 0, d, d, h, l); public static final Box WEST_AABB = new Box(0, 0, d, d, h, l);
public static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(d, 0, 0, l, h, d); public static final Box NORTH_AABB = new Box(d, 0, 0, l, h, d);
public static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(l, 0, d, 1, h, l); public static final Box EAST_AABB = new Box(l, 0, d, 1, h, l);
public static final AxisAlignedBB[] BOUNDING_BOXES = new AxisAlignedBB[] { public static final Box[] BOUNDING_BOXES = new Box[] {
new AxisAlignedBB(d, 0, d, l, h, l), new Box(d, 0, d, l, h, l),
new AxisAlignedBB(d, 0, d, l, h, 1), new Box(d, 0, d, l, h, 1),
new AxisAlignedBB(0, 0, d, l, h, l), new Box(0, 0, d, l, h, l),
new AxisAlignedBB(0, 0, d, l, h, 1), new Box(0, 0, d, l, h, 1),
new AxisAlignedBB(d, 0, 0, l, h, l), new Box(d, 0, 0, l, h, l),
new AxisAlignedBB(d, 0, 0, l, h, 1), new Box(d, 0, 0, l, h, 1),
new AxisAlignedBB(0, 0, 0, l, h, l), new Box(0, 0, 0, l, h, l),
new AxisAlignedBB(0, 0, 0, l, h, 1), new Box(0, 0, 0, l, h, 1),
new AxisAlignedBB(d, 0, d, 1, h, l), new Box(d, 0, d, 1, h, l),
new AxisAlignedBB(d, 0, d, 1, h, 1), new Box(d, 0, d, 1, h, 1),
new AxisAlignedBB(0, 0, d, 1, h, l), new Box(0, 0, d, 1, h, l),
new AxisAlignedBB(0, 0, d, 1, h, 1), new Box(0, 0, d, 1, h, 1),
new AxisAlignedBB(d, 0, 0, 1, h, l), new Box(d, 0, 0, 1, h, l),
new AxisAlignedBB(d, 0, 0, 1, h, 1), new Box(d, 0, 0, 1, h, 1),
new AxisAlignedBB(0, 0, 0, 1, h, l), new Box(0, 0, 0, 1, h, l),
new AxisAlignedBB(0, 0, 0, 1, h, 1) new Box(0, 0, 0, 1, h, 1)
}; };
public BlockCloudBanister(Material material, String domain, String name) { public BlockCloudBanister(Material material, String domain, String name) {
@ -73,7 +73,7 @@ public class BlockCloudBanister extends BlockCloudFence {
@Deprecated @Deprecated
@Override @Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState) { public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean isActualState) {
if (!getCanInteract(state, entity)) { if (!getCanInteract(state, entity)) {
return; return;
} }
@ -110,7 +110,7 @@ public class BlockCloudBanister extends BlockCloudFence {
} }
@Override @Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { public Box getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
state = state.getActualState(source, pos); state = state.getActualState(source, pos);
return BOUNDING_BOXES[getBoundingBoxIdx(state)]; return BOUNDING_BOXES[getBoundingBoxIdx(state)];
} }

View file

@ -5,19 +5,18 @@ import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.init.UBlocks; import com.minelittlepony.unicopia.UBlocks;
import net.minecraft.block.SoundType; import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockCloudFarm extends UFarmland implements ICloudBlock { public class BlockCloudFarm extends UFarmland implements ICloudBlock {
@ -29,12 +28,7 @@ public class BlockCloudFarm extends UFarmland implements ICloudBlock {
} }
@Override @Override
public boolean isTranslucent(IBlockState state) { public boolean isAir(BlockState state, IBlockAccess world, BlockPos pos) {
return true;
}
@Override
public boolean isAir(IBlockState state, IBlockAccess world, BlockPos pos) {
return allowsFallingBlockToPass(state, world, pos); return allowsFallingBlockToPass(state, world, pos);
} }
@ -44,21 +38,19 @@ public class BlockCloudFarm extends UFarmland implements ICloudBlock {
} }
@Override @Override
public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
IBlockState beside = world.getBlockState(pos.offset(face));
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
if ((face == EnumFacing.DOWN || face == EnumFacing.UP || cloud == this)) { if ((face.getAxis() == Axis.Y || cloud == this)) {
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
return true; return true;
} }
} }
} }
return super.doesSideBlockRendering(state, world, pos, face); return super.isSideInvisible(state, beside, face);
} }
@Override @Override
@ -69,21 +61,21 @@ public class BlockCloudFarm extends UFarmland implements ICloudBlock {
} }
@Override @Override
public void onLanded(World worldIn, Entity entity) { public void onEntityLand(BlockView world, Entity entity) {
if (!applyRebound(entity)) { if (!applyRebound(entity)) {
super.onLanded(worldIn, entity); super.onEntityLand(world, entity);
} }
} }
@Override @Override
public void onEntityCollision(World w, BlockPos pos, IBlockState state, Entity entity) { public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) {
if (!applyBouncyness(state, entity)) { if (!applyBouncyness(state, entity)) {
super.onEntityCollision(w, pos, state, entity); super.onEntityCollision(state, w, pos, entity);
} }
} }
@Override @Override
public boolean canEntityDestroy(IBlockState state, IBlockAccess world, BlockPos pos, Entity entity) { public boolean canEntityDestroy(BlockState state, BlockView world, BlockPos pos, Entity entity) {
return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity); return getCanInteract(state, entity) && super.canEntityDestroy(state, world, pos, entity);
} }
@ -97,7 +89,7 @@ public class BlockCloudFarm extends UFarmland implements ICloudBlock {
} }
@Deprecated @Deprecated
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(state, entity)) { if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
} }
@ -105,21 +97,21 @@ public class BlockCloudFarm extends UFarmland implements ICloudBlock {
@Deprecated @Deprecated
@Override @Override
public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos) { public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
if (CloudType.NORMAL.canInteract(player)) { if (CloudType.NORMAL.canInteract(player)) {
return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos); return super.calcBlockBreakingDelta(state, player, world, pos);
} }
return -1; return -1;
} }
@Override @Override
public CloudType getCloudMaterialType(IBlockState blockState) { public CloudType getCloudMaterialType(BlockState blockState) {
return CloudType.NORMAL; return CloudType.NORMAL;
} }
@Override @Override
protected IBlockState getDroppedState(IBlockState state) { protected BlockState getDroppedState(BlockState state) {
return UBlocks.normal_cloud.getDefaultState(); return UBlocks.normal_cloud.getDefaultState();
} }
} }

View file

@ -6,22 +6,17 @@ import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import net.minecraft.block.BlockFence; import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.SoundType; import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material; import net.minecraft.block.FenceBlock;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockCloudFence extends BlockFence implements ICloudBlock { public class BlockCloudFence extends FenceBlock implements ICloudBlock {
private final CloudType variant; private final CloudType variant;
@ -71,7 +66,7 @@ public class BlockCloudFence extends BlockFence implements ICloudBlock {
@Override @Override
public BlockRenderLayer getRenderLayer() { public BlockRenderLayer getRenderLayer() {
return variant == CloudType.NORMAL ? BlockRenderLayer.TRANSLUCENT : super.getRenderLayer(); return BlockRenderLayer.TRANSLUCENT;
} }
@Override @Override
@ -82,9 +77,9 @@ public class BlockCloudFence extends BlockFence implements ICloudBlock {
} }
@Override @Override
public void onLanded(World worldIn, Entity entity) { public void onEntityLand(BlockView world, Entity entity) {
if (!applyRebound(entity)) { if (!applyRebound(entity)) {
super.onLanded(worldIn, entity); super.onEntityLand(world, entity);
} }
} }
@ -96,9 +91,9 @@ public class BlockCloudFence extends BlockFence implements ICloudBlock {
} }
@Override @Override
public void onEntityCollision(World w, BlockPos pos, IBlockState state, Entity entity) { public void onEntityCollision(BlockState state, World w, BlockPos pos, Entity entity) {
if (!applyBouncyness(state, entity)) { if (!applyBouncyness(state, entity)) {
super.onEntityCollision(w, pos, state, entity); super.onEntityCollision(state, w, pos, entity);
} }
} }
@ -108,7 +103,7 @@ public class BlockCloudFence extends BlockFence implements ICloudBlock {
} }
@Deprecated @Deprecated
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState) { public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean isActualState) {
if (getCanInteract(state, entity)) { if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, isActualState); super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, isActualState);
} }
@ -116,9 +111,9 @@ public class BlockCloudFence extends BlockFence implements ICloudBlock {
@Deprecated @Deprecated
@Override @Override
public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos) { public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
if (CloudType.NORMAL.canInteract(player)) { if (CloudType.NORMAL.canInteract(player)) {
return super.getPlayerRelativeBlockHardness(state, player, worldIn, pos); return super.calcBlockBreakingDelta(state, player, world, pos);
} }
return -1; return -1;
} }

View file

@ -6,20 +6,18 @@ import java.util.Random;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.forgebullshit.FUF;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs; import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material; import net.minecraft.block.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.StairsBlock;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing; import net.minecraft.state.property.Properties;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends USlab<T> implements ICloudBlock { public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends USlab<T> implements ICloudBlock {
@ -30,19 +28,19 @@ public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends USla
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public boolean isTopSolid(IBlockState state) { public boolean isTopSolid(BlockState state) {
return getCloudMaterialType(state) == CloudType.ENCHANTED && super.isTopSolid(state); return getCloudMaterialType(state) == CloudType.ENCHANTED && super.isTopSolid(state);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@FUF(reason = "...Really?") @FUF(reason = "...Really?")
public boolean isSideSolid(IBlockState base_state, IBlockAccess world, BlockPos pos, EnumFacing side) { public boolean isSideSolid(BlockState base_state, BlockAccess world, BlockPos pos, Direction side) {
return getCloudMaterialType(base_state) == CloudType.ENCHANTED && super.isSideSolid(base_state, world, pos, side); return getCloudMaterialType(base_state) == CloudType.ENCHANTED && super.isSideSolid(base_state, world, pos, side);
} }
@Override @Override
@Deprecated @Deprecated
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { public void addCollisionBoxToList(BlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(state, entity)) { if (getCanInteract(state, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
} }
@ -58,7 +56,7 @@ public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends USla
} }
@Override @Override
public CloudType getCloudMaterialType(IBlockState blockState) { public CloudType getCloudMaterialType(BlockState blockState) {
return modelBlock.getCloudMaterialType(blockState); return modelBlock.getCloudMaterialType(blockState);
} }
@ -78,32 +76,30 @@ public abstract class BlockCloudSlab<T extends Block & ICloudBlock> extends USla
} }
@Override @Override
public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
IBlockState beside = world.getBlockState(pos.offset(face));
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof ICloudBlock) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); ICloudBlock cloud = ((ICloudBlock)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
EnumBlockHalf half = state.getValue(HALF); BlockHalf half = state.get(HALF);
if (beside.getBlock() instanceof BlockCloudStairs) { if (beside.getBlock() instanceof BlockCloudStairs) {
return beside.getValue(BlockStairs.HALF).ordinal() == state.getValue(HALF).ordinal() return beside.get(StairsBlock.HALF).ordinal() == state.get(HALF).ordinal()
&& beside.getValue(BlockStairs.FACING) == face; && beside.get(Properties.FACING) == face;
} }
if (face == EnumFacing.DOWN) { if (face == Direction.DOWN) {
return half == EnumBlockHalf.BOTTOM; return half == BlockHalf.BOTTOM;
} }
if (face == EnumFacing.UP) { if (face == Direction.UP) {
return half == EnumBlockHalf.TOP; return half == BlockHalf.TOP;
} }
if (beside.getBlock() == this) { if (beside.getBlock() == this) {
return beside.getValue(HALF) == state.getValue(HALF); return beside.get(HALF) == state.get(HALF);
} }
} }
} }

View file

@ -13,7 +13,7 @@ import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -32,7 +32,7 @@ public class BlockCloudStairs extends UStairs implements ICloudBlock {
} }
@Override @Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) { public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean p_185477_7_) {
if (getCanInteract(theState, entity)) { if (getCanInteract(theState, entity)) {
super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_); super.addCollisionBoxToList(state, worldIn, pos, entityBox, collidingBoxes, entity, p_185477_7_);
} }

View file

@ -38,7 +38,7 @@ public class BlockDiamondDoor extends UDoor {
@Override @Override
protected boolean onPowerStateChanged(World world, IBlockState state, BlockPos pos, boolean powered) { protected boolean onPowerStateChanged(World world, IBlockState state, BlockPos pos, boolean powered) {
if (state.getValue(OPEN)) { if (state.getValue(OPEN)) {
world.setBlockState(pos, state.withProperty(OPEN, false), 2); world.setBlockState(pos, state.with(OPEN, false), 2);
return true; return true;
} }

View file

@ -1,53 +0,0 @@
package com.minelittlepony.unicopia.block;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockDirected extends BlockDirectional {
public BlockDirected(Material material, String domain, String name) {
super(material);
setTranslationKey(name);
setRegistryName(domain, name);
setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.UP));
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
}
@Override
public IBlockState withMirror(IBlockState state, Mirror mirror) {
return state.withProperty(FACING, mirror.mirror(state.getValue(FACING)));
}
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
return getDefaultState().withProperty(FACING, facing);
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(FACING, EnumFacing.byIndex(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(FACING).getIndex();
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, FACING);
}
}

View file

@ -33,7 +33,7 @@ public class BlockDutchDoor extends UDoor {
IBlockState upper = world.getBlockState(pos.up()); IBlockState upper = world.getBlockState(pos.up());
if (upper.getBlock() == this && upper.getValue(OPEN) != powered) { if (upper.getBlock() == this && upper.getValue(OPEN) != powered) {
world.setBlockState(pos.up(), upper.withProperty(OPEN, powered)); world.setBlockState(pos.up(), upper.with(OPEN, powered));
return true; return true;
} }
@ -52,14 +52,14 @@ public class BlockDutchDoor extends UDoor {
IBlockState other = world.getBlockState(pos.up()); IBlockState other = world.getBlockState(pos.up());
if (other.getBlock() == this) { if (other.getBlock() == this) {
return state.withProperty(HINGE, other.getValue(HINGE)) return state.with(HINGE, other.getValue(HINGE))
.withProperty(POWERED, other.getValue(POWERED)); .with(POWERED, other.getValue(POWERED));
} }
} else { } else {
IBlockState other = world.getBlockState(pos.down()); IBlockState other = world.getBlockState(pos.down());
if (other.getBlock() == this) { if (other.getBlock() == this) {
return state.withProperty(FACING, other.getValue(FACING)); return state.with(FACING, other.getValue(FACING));
} }
} }
@ -72,15 +72,15 @@ public class BlockDutchDoor extends UDoor {
boolean upper = (meta & 8) != 0; boolean upper = (meta & 8) != 0;
IBlockState state = getDefaultState() IBlockState state = getDefaultState()
.withProperty(HALF, upper ? EnumDoorHalf.UPPER : EnumDoorHalf.LOWER) .with(HALF, upper ? EnumDoorHalf.UPPER : EnumDoorHalf.LOWER)
.withProperty(OPEN, (meta & 4) != 0); .with(OPEN, (meta & 4) != 0);
if (upper) { if (upper) {
return state.withProperty(POWERED, (meta & 1) != 0) return state.with(POWERED, (meta & 1) != 0)
.withProperty(HINGE, (meta & 2) != 0 ? EnumHingePosition.RIGHT : EnumHingePosition.LEFT); .with(HINGE, (meta & 2) != 0 ? EnumHingePosition.RIGHT : EnumHingePosition.LEFT);
} }
return state.withProperty(FACING, EnumFacing.byHorizontalIndex(meta & 3).rotateYCCW()); return state.with(FACING, EnumFacing.byHorizontalIndex(meta & 3).rotateYCCW());
} }
@Override @Override

View file

@ -1,250 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import java.util.function.Function;
import javax.annotation.Nonnull;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLeaves;
import net.minecraft.block.BlockPlanks.EnumType;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome.TempCategory;
public class BlockFruitLeaves extends BlockLeaves implements IColourful {
public static final PropertyBool HEAVY = PropertyBool.create("heavy");
private final Block sapling;
private boolean hardy;
private int baseGrowthChance;
private int customTint;
private Function<World, ItemStack> fruitProducer = w -> ItemStack.EMPTY;
private Function<World, ItemStack> compostProducer = w -> ItemStack.EMPTY;
public BlockFruitLeaves(String domain, String name, Block sapling) {
setTranslationKey(name);
setRegistryName(domain, name);
setDefaultState(blockState.getBaseState()
.withProperty(HEAVY, false)
.withProperty(CHECK_DECAY, true)
.withProperty(DECAYABLE, true)
);
this.sapling = sapling;
}
public BlockFruitLeaves setHardy(boolean value) {
hardy = value;
return this;
}
public BlockFruitLeaves setHarvestFruit(@Nonnull Function<World, ItemStack> producer) {
fruitProducer = producer;
return this;
}
public BlockFruitLeaves setUnharvestFruit(@Nonnull Function<World, ItemStack> producer) {
compostProducer = producer;
return this;
}
public BlockFruitLeaves setBaseGrowthChance(int chance) {
baseGrowthChance = chance;
return this;
}
public BlockFruitLeaves setTint(int tint) {
customTint = tint;
return this;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return Blocks.LEAVES.getDefaultState().isOpaqueCube();
}
@Override
public BlockRenderLayer getRenderLayer() {
setGraphicsLevel(!Blocks.LEAVES.getDefaultState().isOpaqueCube());
return super.getRenderLayer();
}
@Deprecated
@Override
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
setGraphicsLevel(!Blocks.LEAVES.getDefaultState().isOpaqueCube());
return super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(sapling);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies().canUseEarth()) {
if (stack.isEmpty()) {
if (state.getValue(HEAVY)) {
dropApple(world, pos, state, 0);
world.setBlockState(pos, state.withProperty(HEAVY, false));
}
} else if (stack.getItem() instanceof ItemDye && EnumDyeColor.byDyeDamage(stack.getMetadata()) == EnumDyeColor.WHITE) {
if (!state.getValue(HEAVY)) {
world.setBlockState(pos, state.withProperty(HEAVY, true));
if (!world.isRemote) {
world.playEvent(2005, pos, 0);
}
if (!player.capabilities.isCreativeMode) {
stack.shrink(1);
}
}
}
return true;
}
return false;
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (!world.isRemote && world.isAreaLoaded(pos, 1)) {
if (state.getValue(DECAYABLE)) {
int growthChance = getGrowthChance(world, pos, state);
if (!state.getValue(HEAVY) && (growthChance <= 0 || rand.nextInt(growthChance) == 0)) {
world.setBlockState(pos, state.withProperty(HEAVY, true));
} else {
growthChance /= 10;
if (state.getValue(HEAVY) && (growthChance <= 0 || rand.nextInt(growthChance) == 0)) {
dropApple(world, pos, state, 0);
world.setBlockState(pos, state.withProperty(HEAVY, false));
} else {
super.updateTick(world, pos, state, rand);
}
}
}
}
}
protected int getGrowthChance(World world, BlockPos pos, IBlockState state) {
int chance = baseGrowthChance;
if (!hardy && !world.isDaytime()) {
chance *= 40;
}
if (world.getLight(pos) >= 4) {
chance /= 3;
}
TempCategory temp = world.getBiome(pos).getTempCategory();
if (!hardy && temp == TempCategory.COLD) {
chance *= 1000;
}
if (temp == TempCategory.WARM) {
chance /= 100;
}
if (temp == TempCategory.MEDIUM) {
chance /= 50;
}
return chance;
}
@Override
public int getCustomTint(IBlockState state, int tint) {
return customTint;
}
@Override
protected void dropApple(World world, BlockPos pos, IBlockState state, int chance) {
if (state.getValue(HEAVY)) {
Function<World, ItemStack> fruit = world.rand.nextInt(40) == 0 ? compostProducer : fruitProducer;
spawnAsEntity(world, pos, fruit.apply(world));
world.playSound(null, pos, SoundEvents.ENTITY_ITEMFRAME_PLACE, SoundCategory.BLOCKS, 0.3F, 1);
}
}
@Override
public NonNullList<ItemStack> onSheared(ItemStack item, net.minecraft.world.IBlockAccess world, BlockPos pos, int fortune) {
return NonNullList.withSize(1, new ItemStack(this, 1, 0));
}
@Override
public EnumType getWoodType(int meta) {
return EnumType.OAK;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState()
.withProperty(HEAVY, (meta & 1) != 0)
.withProperty(DECAYABLE, (meta & 2) != 0)
.withProperty(CHECK_DECAY, (meta & 4) != 0);
}
@Override
public int getMetaFromState(IBlockState state) {
int i = 0;
if (state.getValue(HEAVY)) {
i |= 1;
}
if (!state.getValue(DECAYABLE)) {
i |= 2;
}
if (state.getValue(CHECK_DECAY)) {
i |= 4;
}
return i;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, HEAVY, CHECK_DECAY, DECAYABLE);
}
}

View file

@ -1,223 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.init.UItems;
import com.minelittlepony.unicopia.init.UParticles;
import com.minelittlepony.unicopia.particle.Particles;
import net.minecraft.block.BlockTorch;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.NonNullList;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockGlowingGem extends BlockTorch implements ICloudBlock {
public static PropertyBool ON = PropertyBool.create("on");
private static final double A = 5/16D;
private static final double B = 6/16D;
private static final double C = 10/16D;
// tiltedOffWall
private static final double F = 10/16D;
// tiltedMinY
private static final double E = 3/16D;
protected static final AxisAlignedBB STANDING_AABB = new AxisAlignedBB(
7/16D, 0, 7/16D,
9/16D, 1, 9/16D
);
protected static final AxisAlignedBB TORCH_NORTH_AABB = new AxisAlignedBB(
B, E, F,
C, 1, 1
);
protected static final AxisAlignedBB TORCH_SOUTH_AABB = new AxisAlignedBB(
B, E, 0,
C, 1, A
);
protected static final AxisAlignedBB TORCH_WEST_AABB = new AxisAlignedBB(
F, E, B,
1, 1, C
);
protected static final AxisAlignedBB TORCH_EAST_AABB = new AxisAlignedBB(
0, E, B,
A, 1, C
);
public BlockGlowingGem(String domain, String name) {
setTranslationKey(name);
setRegistryName(domain, name);
setHardness(0);
setLightLevel(1);
setSoundType(SoundType.GLASS);
setTickRandomly(true);
setDefaultState(blockState.getBaseState()
.withProperty(FACING, EnumFacing.UP)
.withProperty(ON, true)
);
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
switch (state.getValue(FACING)) {
case EAST: return TORCH_EAST_AABB;
case WEST: return TORCH_WEST_AABB;
case SOUTH: return TORCH_SOUTH_AABB;
case NORTH: return TORCH_NORTH_AABB;
default: return STANDING_AABB;
}
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (!state.getValue(ON)) {
ItemStack held = player.getHeldItem(hand);
if (!held.isEmpty() && (held.getItem() == Items.FLINT_AND_STEEL || held.getItem() == Items.FIRE_CHARGE)) {
world.playSound(null, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
world.setBlockState(pos, state.withProperty(ON, true));
if (held.getItem() == Items.FLINT_AND_STEEL) {
held.damageItem(1, player);
} else if (!player.capabilities.isCreativeMode) {
held.shrink(1);
}
}
return true;
}
return false;
}
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
EnumFacing facing = state.getValue(FACING);
double x = pos.getX() + 0.5;
double y = pos.getY() + 1;
double z = pos.getZ() + 0.5;
double drop = 0.22D;
double variance = 0.27D;
if (facing.getAxis().isHorizontal()) {
facing = facing.getOpposite();
x += variance * facing.getXOffset();
y += drop;
z += variance * facing.getZOffset();
}
if (state.getValue(ON)) {
for (int i = 0; i < 3; i++) {
Particles.instance().spawnParticle(UParticles.UNICORN_MAGIC, false,
x - 0.3, y - 0.3, z - 0.3,
rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
}
} else {
world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x, y, z, 0, 0, 0);
}
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (world.isRainingAt(pos)) {
if (state.getValue(ON)) {
world.playSound(null, pos, SoundEvents.BLOCK_REDSTONE_TORCH_BURNOUT, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
world.setBlockState(pos, state.withProperty(ON, false));
}
} else {
if (!state.getValue(ON)) {
world.playSound(null, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
world.setBlockState(pos, state.withProperty(ON, true));
}
}
}
@Override
public int getStrongPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
return state.getValue(ON) && side == EnumFacing.DOWN ? state.getWeakPower(world, pos, side) : 0;
}
@Override
public int getWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
return state.getValue(ON) && state.getValue(FACING) != side ? 12 : 0;
}
@Override
public CloudType getCloudMaterialType(IBlockState blockState) {
return CloudType.ENCHANTED;
}
@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
drops.add(new ItemStack(Items.STICK));
Random rand = world instanceof World ? ((World)world).rand : RANDOM;
if (rand.nextInt(10) == 0) {
drops.add(new ItemStack(UItems.spell));
} else {
drops.add(new ItemStack(UItems.curse));
}
}
@Override
@Deprecated
public int getLightValue(IBlockState state) {
if (state.getValue(ON)) {
return super.getLightValue(state);
}
return 0;
}
@Override
public IBlockState getStateFromMeta(int meta) {
IBlockState iblockstate = this.getDefaultState();
int facing = (meta % 5) + 1;
return iblockstate
.withProperty(FACING, EnumFacing.byIndex(facing))
.withProperty(ON, meta > 5);
}
@Override
public int getMetaFromState(IBlockState state) {
int meta = Math.max(0, state.getValue(FACING).getIndex() - 1);
if (state.getValue(ON)) {
meta += EnumFacing.VALUES.length;
}
return meta;
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, FACING, ON);
}
}

View file

@ -6,56 +6,47 @@ import java.util.Random;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.Predicates;
import com.minelittlepony.unicopia.init.UBlocks; import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.init.UMaterials; import com.minelittlepony.unicopia.UMaterials;
import com.minelittlepony.unicopia.init.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.util.MagicalDamageSource;
import com.minelittlepony.util.PosHelper; import com.minelittlepony.util.PosHelper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.SoundType; import net.minecraft.block.BlockState;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.particle.ParticleTypes;
import net.minecraft.nbt.NBTUtil; import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.BlockRenderLayer; import net.minecraft.state.property.IntProperty;
import net.minecraft.util.DamageSource; import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.EnumFacing; import net.minecraft.util.math.Box;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class BlockGrowingCuccoon extends Block { public class BlockGrowingCuccoon extends Block {
public static final DamageSource DAMAGE_SOURCE = new DamageSource("acid"); public static final DamageSource DAMAGE_SOURCE = MagicalDamageSource.mundane("acid");
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7); public static final IntProperty AGE = IntProperty.of("age", 0, 7);
public static final PropertyEnum<Shape> SHAPE = PropertyEnum.create("shape", Shape.class); public static final EnumProperty<Shape> SHAPE = EnumProperty.of("shape", Shape.class);
public static final AxisAlignedBB[] SHAFTS = new AxisAlignedBB[] { public static final Box[] SHAFTS = new Box[] {
new AxisAlignedBB(7/16F, 0, 7/16F, 9/16F, 1, 7/16F), new Box(7/16F, 0, 7/16F, 9/16F, 1, 7/16F),
new AxisAlignedBB(6/16F, 0, 6/16F, 10/16F, 1, 10/16F), new Box(6/16F, 0, 6/16F, 10/16F, 1, 10/16F),
new AxisAlignedBB(5/16F, 0, 5/16F, 11/16F, 1, 11/16F), new Box(5/16F, 0, 5/16F, 11/16F, 1, 11/16F),
new AxisAlignedBB(4/16F, 0, 4/16F, 12/16F, 1, 12/16F) new Box(4/16F, 0, 4/16F, 12/16F, 1, 12/16F)
}; };
public static final AxisAlignedBB[] BULBS = new AxisAlignedBB[] { public static final Box[] BULBS = new Box[] {
new AxisAlignedBB(6/16F, 1/16F, 6/16F, 10/16F, 8/16F, 10/16F), new Box(6/16F, 1/16F, 6/16F, 10/16F, 8/16F, 10/16F),
new AxisAlignedBB(4/16F, 0, 4/16F, 12/16F, 9/16F, 12/16F), new Box(4/16F, 0, 4/16F, 12/16F, 9/16F, 12/16F),
new AxisAlignedBB(3/16F, 0, 3/16F, 13/16F, 10/16F, 13/16F), new Box(3/16F, 0, 3/16F, 13/16F, 10/16F, 13/16F),
new AxisAlignedBB(2/16F, 0, 2/16F, 14/16F, 12/16F, 14/16F), new Box(2/16F, 0, 2/16F, 14/16F, 12/16F, 14/16F),
}; };
public BlockGrowingCuccoon(String domain, String name) { public BlockGrowingCuccoon(String domain, String name) {
@ -74,8 +65,8 @@ public class BlockGrowingCuccoon extends Block {
useNeighborBrightness = true; useNeighborBrightness = true;
setDefaultState(getBlockState().getBaseState() setDefaultState(getBlockState().getBaseState()
.withProperty(AGE, 0) .with(AGE, 0)
.withProperty(SHAPE, Shape.BULB)); .with(SHAPE, Shape.BULB));
} }
@Override @Override
@ -106,7 +97,7 @@ public class BlockGrowingCuccoon extends Block {
@Deprecated @Deprecated
@Override @Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) { public Box getCollisionBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return getBoundingBox(state, world, pos); return getBoundingBox(state, world, pos);
} }
@ -122,23 +113,23 @@ public class BlockGrowingCuccoon extends Block {
return; return;
} }
int age = state.getValue(AGE); int age = state.get(AGE);
BlockPos below = pos.down(); BlockPos below = pos.down();
if (world.isBlockLoaded(below)) { if (world.isBlockLoaded(below)) {
boolean spaceBelow = world.isAirBlock(below); boolean spaceBelow = world.isAirBlock(below);
Shape shape = state.getValue(SHAPE); Shape shape = state.get(SHAPE);
if (shape == Shape.STRING && spaceBelow) { if (shape == Shape.STRING && spaceBelow) {
world.setBlockState(pos, state.withProperty(SHAPE, Shape.BULB).withProperty(AGE, age / 2)); world.setBlockState(pos, state.with(SHAPE, Shape.BULB).with(AGE, age / 2));
} else if (shape == Shape.BULB && !spaceBelow) { } else if (shape == Shape.BULB && !spaceBelow) {
world.setBlockState(pos, state.withProperty(SHAPE, Shape.STRING).withProperty(AGE, age / 2)); world.setBlockState(pos, state.with(SHAPE, Shape.STRING).with(AGE, age / 2));
} else if (age >= 7) { } else if (age >= 7) {
if (rand.nextInt(12) == 0 && spaceBelow) { if (rand.nextInt(12) == 0 && spaceBelow) {
world.setBlockState(below, state.withProperty(AGE, age / 2)); world.setBlockState(below, state.with(AGE, age / 2));
world.setBlockState(pos, getDefaultState().withProperty(AGE, age / 2).withProperty(SHAPE, Shape.STRING)); world.setBlockState(pos, getDefaultState().with(AGE, age / 2).with(SHAPE, Shape.STRING));
world.playSound(null, pos, USounds.SLIME_ADVANCE, SoundCategory.BLOCKS, 1, 1); world.playSound(null, pos, USounds.SLIME_ADVANCE, SoundCategory.BLOCKS, 1, 1);
} }
} else { } else {
@ -163,14 +154,14 @@ public class BlockGrowingCuccoon extends Block {
} }
protected int getMaximumAge(World world, BlockPos pos, IBlockState state, boolean spaceBelow) { protected int getMaximumAge(World world, BlockPos pos, IBlockState state, boolean spaceBelow) {
if (state.getValue(SHAPE) == Shape.STRING) { if (state.get(SHAPE) == Shape.STRING) {
IBlockState higher = world.getBlockState(pos.up()); IBlockState higher = world.getBlockState(pos.up());
if (higher.getBlock() != this) { if (higher.getBlock() != this) {
return 7; return 7;
} }
return Math.min(higher.getValue(AGE), return Math.min(higher.get(AGE),
((BlockGrowingCuccoon)higher.getBlock()).getMaximumAge(world, pos.up(), higher, false) - 1 ((BlockGrowingCuccoon)higher.getBlock()).getMaximumAge(world, pos.up(), higher, false) - 1
); );
} }
@ -184,7 +175,7 @@ public class BlockGrowingCuccoon extends Block {
@Override @Override
public int quantityDropped(IBlockState state, int fortune, Random random) { public int quantityDropped(IBlockState state, int fortune, Random random) {
return random.nextInt(3) == 0 ? state.getValue(AGE) : 0; return random.nextInt(3) == 0 ? state.get(AGE) : 0;
} }
@Override @Override
@ -217,14 +208,14 @@ public class BlockGrowingCuccoon extends Block {
@Override @Override
public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity) { public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity) {
if (entity instanceof EntityLivingBase && !entity.isDead) { if (entity instanceof LivingEntity && !entity.isDead) {
EntityLivingBase living = (EntityLivingBase)entity; LivingEntity living = (LivingEntity)entity;
if (!Predicates.BUGGY.test(living) && living.getHealth() > 0) { if (!Predicates.BUGGY.test(living) && living.getHealth() > 0) {
living.attackEntityFrom(DAMAGE_SOURCE, 1); living.attackEntityFrom(DAMAGE_SOURCE, 1);
living.setInWeb(); living.setInWeb();
if (!world.isRemote) { if (!world.isClient) {
if (living.getHealth() <= 0) { if (living.getHealth() <= 0) {
living.dropItem(Items.BONE, 3); living.dropItem(Items.BONE, 3);
@ -274,44 +265,32 @@ public class BlockGrowingCuccoon extends Block {
@Deprecated @Deprecated
@Override @Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState) { public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, Box entityBox, List<Box> collidingBoxes, @Nullable Entity entity, boolean isActualState) {
if (!isActualState) { if (!isActualState) {
state = state.getActualState(world, pos); state = state.getActualState(world, pos);
} }
int age = state.getValue(AGE) / 2; int age = state.get(AGE) / 2;
Vec3d offset = state.getOffset(world, pos); Vec3d offset = state.getOffset(world, pos);
addCollisionBoxToList(pos, entityBox, collidingBoxes, SHAFTS[age % SHAFTS.length].offset(offset)); addCollisionBoxToList(pos, entityBox, collidingBoxes, SHAFTS[age % SHAFTS.length].offset(offset));
if (state.getValue(SHAPE) == Shape.BULB) { if (state.get(SHAPE) == Shape.BULB) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, BULBS[age % BULBS.length].offset(offset)); addCollisionBoxToList(pos, entityBox, collidingBoxes, BULBS[age % BULBS.length].offset(offset));
} }
} }
@Deprecated @Deprecated
@Override @Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { public Box getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
state = state.getActualState(source, pos); state = state.getActualState(source, pos);
if (state.getValue(SHAPE) == Shape.BULB) { if (state.get(SHAPE) == Shape.BULB) {
return BULBS[state.getValue(AGE) / 2].offset(state.getOffset(source, pos)); return BULBS[state.get(AGE) / 2].offset(state.getOffset(source, pos));
} }
return SHAFTS[state.getValue(AGE) / 2].offset(state.getOffset(source, pos)); return SHAFTS[state.get(AGE) / 2].offset(state.getOffset(source, pos));
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState()
.withProperty(AGE, meta % 8)
.withProperty(SHAPE, Shape.VALUES[(meta >> 3) % Shape.VALUES.length]);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(AGE) | (state.getValue(SHAPE).ordinal() << 3);
} }
@Override @Override
@ -320,28 +299,29 @@ public class BlockGrowingCuccoon extends Block {
} }
@Override @Override
public boolean isLadder(IBlockState state, IBlockAccess world, BlockPos pos, EntityLivingBase entity) { public boolean isLadder(BlockState state, BlockView world, BlockPos pos, LivingEntity entity) {
return true; return true;
} }
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) { @Override
if (state.getValue(SHAPE) == Shape.BULB) { public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random rand) {
if (state.get(SHAPE) == Shape.BULB) {
if (rand.nextInt(8) == 0) { if (rand.nextInt(8) == 0) {
AxisAlignedBB bounds = BULBS[state.getValue(AGE) / 2] Box bounds = BULBS[state.get(AGE) / 2]
.offset(pos) .offset(pos)
.offset(state.getOffset(world, pos)); .offset(state.getOffsetPos(world, pos));
double x = bounds.minX + (bounds.maxX - bounds.minX) * rand.nextFloat(); double x = bounds.minX + (bounds.maxX - bounds.minX) * rand.nextFloat();
double y = bounds.minY; double y = bounds.minY;
double z = bounds.minZ + (bounds.maxZ - bounds.minZ) * rand.nextFloat(); double z = bounds.minZ + (bounds.maxZ - bounds.minZ) * rand.nextFloat();
world.spawnParticle(EnumParticleTypes.DRIP_LAVA, x, y, z, 0, 0, 0); world.addParticle(ParticleTypes.DRIPPING_LAVA, x, y, z, 0, 0, 0);
} }
} }
} }
static enum Shape implements IStringSerializable { enum Shape implements StringIdentifiable {
BULB, BULB,
STRING; STRING;
@ -349,11 +329,11 @@ public class BlockGrowingCuccoon extends Block {
@Override @Override
public String toString() { public String toString() {
return getName(); return asString();
} }
@Override @Override
public String getName() { public String asString() {
return name().toLowerCase(); return name().toLowerCase();
} }

View file

@ -1,374 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.init.UBlocks;
import com.minelittlepony.unicopia.init.UMaterials;
import com.minelittlepony.unicopia.init.USounds;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.util.PosHelper;
import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.shape.Sphere;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class BlockHiveWall extends BlockFalling {
public static final PropertyEnum<State> STATE = PropertyEnum.create("state", State.class);
public static final PropertyEnum<Axis> AXIS = PropertyEnum.create("axis", Axis.class);
private static final IShape shape = new Sphere(false, 1.5);
public BlockHiveWall(String domain, String name) {
super(UMaterials.hive);
setTranslationKey(name);
setRegistryName(domain, name);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setDefaultState(blockState.getBaseState().withProperty(STATE, State.GROWING).withProperty(AXIS, Axis.Y));
setHardness(2);
setSoundType(SoundType.SAND);
setHarvestLevel("pickaxe", 1);
setResistance(10);
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (rand.nextInt(300) == 0) {
world.playSound(null, pos, USounds.INSECT, SoundCategory.BLOCKS, 1, 1);
}
State type = getState(state);
Axis axis = getAxis(state);
int matchedNeighbours = countNeighbours(world, pos);
if (type == State.GROWING) {
if (testForAxis(world, pos, axis)) {
world.setBlockState(pos, state.withProperty(STATE, State.STABLE));
} else {
Axis newAxis = axis;
for (Axis i : Axis.VALUES) {
if (testForAxis(world, pos, i)) {
newAxis = i;
break;
}
}
if (newAxis != axis) {
world.setBlockState(pos, state.withProperty(AXIS, newAxis).withProperty(STATE, State.STABLE));
} else if (rand.nextInt(10) == 0) {
EnumFacing facing = axis.randomFacing(rand);
BlockPos other = pos.offset(facing);
if (canSpreadInto(world, other, axis)) {
world.playSound(null, pos, USounds.SLIME_RETRACT, SoundCategory.BLOCKS, 1, 1);
world.setBlockState(other, state);
world.setBlockState(pos, state.withProperty(STATE, State.STABLE));
}
}
}
} else if (type == State.DYING) {
if (matchedNeighbours > 1 && matchedNeighbours < 17) {
world.setBlockState(pos, state.withProperty(STATE, State.STABLE));
} else {
die(world, pos, rand);
}
} else {
if (pos.getX() % 3 == 0 && pos.getZ() % 4 == 0 && isEmptySpace(world, pos.down()) && UBlocks.cuccoon.canPlaceBlockAt(world, pos.down())) {
world.setBlockState(pos.down(), UBlocks.cuccoon.getDefaultState());
} else if (!testForAxis(world, pos, axis)) {
world.setBlockState(pos, state.withProperty(STATE, State.GROWING));
} else if (matchedNeighbours >= 27) {
world.setBlockState(pos, state.withProperty(STATE, State.DYING));
} else {
return;
}
}
world.scheduleUpdate(pos, this, tickRate(world));
}
public State getState(IBlockState state) {
return state.getValue(STATE);
}
public Axis getAxis(IBlockState state) {
return state.getValue(AXIS);
}
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
if (state.getValue(STATE) != State.STABLE) {
world.scheduleUpdate(pos, this, 10);
}
}
protected boolean testForAxis(World world, BlockPos pos, Axis axis) {
return !PosHelper.some(pos, p -> isEmptySpace(world, p), axis.getFacings());
}
protected boolean isEmptySpace(World world, BlockPos pos) {
if (world.isAirBlock(pos)) {
return true;
}
IBlockState state = world.getBlockState(pos);
return !(state.getMaterial().isLiquid()
|| state.isBlockNormalCube()
|| state.isNormalCube()
|| state.isFullCube()
|| state.isOpaqueCube());
}
protected void die(World world, BlockPos pos, Random rand) {
world.destroyBlock(pos, false);
PosHelper.all(pos, p -> {
IBlockState s = world.getBlockState(p);
if (s.getBlock() == this) {
notifyDying(world, p, s, rand);
}
}, EnumFacing.VALUES);
}
protected void notifyDying(World world, BlockPos pos, IBlockState state, Random rand) {
State oldState = state.getValue(STATE);
State newState = oldState.downGrade();
if (newState != oldState) {
world.setBlockState(pos, state.withProperty(STATE, newState));
}
}
@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
if (entity instanceof EntityPlayer) {
IPlayer player = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity);
IBlockState state = world.getBlockState(pos);
if (player.getPlayerSpecies() != Race.CHANGELING) {
if (!world.isRemote) {
if (((isEmptySpace(world, pos.down()) || canFallThrough(world.getBlockState(pos.down()))) && pos.getY() >= 0)) {
EntityFallingBlock faller = new EntityFallingBlock(world, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, state);
onStartFalling(faller);
world.spawnEntity(faller);
}
}
}
}
}
@Override
public void onEndFalling(World world, BlockPos pos, IBlockState fallingState, IBlockState hitState) {
world.destroyBlock(pos, true);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (hand == EnumHand.MAIN_HAND && playerIn.getHeldItem(hand).isEmpty()) {
IPlayer player = PlayerSpeciesList.instance().getPlayer(playerIn);
if (player.getPlayerSpecies() == Race.CHANGELING) {
retreat(world, pos);
PosHelper.adjacentNeighbours(pos).forEach(p -> {
if (world.getBlockState(p).getBlock() == this) {
retreat(world, p);
}
});
return true;
}
}
return false;
}
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return getDefaultState().withProperty(AXIS, Axis.fromVanilla(facing.getAxis()));
}
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
if (rand.nextInt(16) == 0) {
Vec3d vel = shape.computePoint(rand);
Vec3d vec = vel.add(pos.getX(), pos.getY(), pos.getZ());
world.spawnParticle(EnumParticleTypes.BLOCK_DUST,
vec.x, vec.y, vec.z,
vel.x, vel.y, vel.z,
Block.getStateId(state));
}
}
public void retreat(World world, BlockPos pos) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
world.playSound(null, pos, USounds.SLIME_RETRACT, SoundCategory.BLOCKS, 1, 1);
}
protected int countNeighbours(World world, BlockPos pos) {
int count = 0;
for (BlockPos i : BlockPos.getAllInBoxMutable(pos.add(-1, -1, -1), pos.add(1, 1, 1))) {
if (world.getBlockState(i).getBlock() == this) {
count++;
}
}
return count;
}
protected boolean exposed(World world, BlockPos pos) {
return PosHelper.some(pos, p -> isEmptySpace(world, p), EnumFacing.VALUES);
}
protected boolean canSpreadInto(World world, BlockPos pos, Axis axis) {
if (world.isBlockLoaded(pos) && isEmptySpace(world, pos)) {
boolean one = false;
for (EnumFacing facing : axis.getFacings()) {
BlockPos op = pos.offset(facing);
if (world.getBlockState(op).getMaterial() == UMaterials.hive) {
if (one) {
return true;
}
one = true;
}
}
}
return false;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState()
.withProperty(STATE, State.VALUES[meta % State.VALUES.length])
.withProperty(AXIS, Axis.VALUES[(meta << 2) % Axis.VALUES.length]);
}
@Override
public int getMetaFromState(IBlockState state) {
return getState(state).ordinal() | (getAxis(state).ordinal() >> 2);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, STATE, AXIS);
}
public static enum State implements IStringSerializable {
GROWING,
STABLE,
DYING;
static final State[] VALUES = values();
@Override
public String toString() {
return getName();
}
@Override
public String getName() {
return name().toLowerCase();
}
public State upgrade() {
switch (this) {
case DYING: return STABLE;
default: return GROWING;
}
}
public State downGrade() {
switch (this) {
case GROWING: return STABLE;
default: return DYING;
}
}
}
public static enum Axis implements IStringSerializable {
X(EnumFacing.Axis.X, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.UP, EnumFacing.DOWN),
Y(EnumFacing.Axis.Y, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH),
Z(EnumFacing.Axis.Z, EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.UP, EnumFacing.DOWN);
static final Axis[] VALUES = values();
static final Map<EnumFacing.Axis, Axis> AXIS_MAP = Maps.newEnumMap(EnumFacing.Axis.class);
private final EnumFacing.Axis vanilla;
private final EnumFacing[] facings;
static {
for (Axis i : VALUES) {
AXIS_MAP.put(i.vanilla, i);
}
}
Axis(EnumFacing.Axis vanilla, EnumFacing... facings) {
this.vanilla = vanilla;
this.facings = facings;
}
@Override
public String toString() {
return getName();
}
@Override
public String getName() {
return name().toLowerCase();
}
public EnumFacing randomFacing(Random rand) {
return facings[rand.nextInt(facings.length)];
}
public EnumFacing[] getFacings() {
return facings;
}
public static Axis fromVanilla(EnumFacing.Axis axis) {
return AXIS_MAP.get(axis);
}
}
}

View file

@ -1,68 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import net.minecraft.block.BlockSnow;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockSlimeLayer extends BlockSnow {
public BlockSlimeLayer(String domain, String name) {
setTranslationKey(name);
setRegistryName(domain, name);
setSoundType(SoundType.SLIME);
setCreativeTab(CreativeTabs.DECORATIONS);
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Deprecated
public Material getMaterial(IBlockState state) {
return Material.CLAY;
}
@Override
public MapColor getMapColor(IBlockState state, IBlockAccess world, BlockPos pos) {
return MapColor.GRASS;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Items.SLIME_BALL;
}
@Deprecated
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
float factor = getMotionFactor(world.getBlockState(pos));
entity.motionX *= factor;
entity.motionY *= factor;
entity.motionZ *= factor;
}
protected float getMotionFactor(IBlockState state) {
return 1/state.getValue(LAYERS);
}
}

View file

@ -1,106 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemLead;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
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.EnumPlantType;
import net.minecraftforge.common.IPlantable;
public class BlockStick extends Block implements IPlantable {
static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(
7/16F, -1/16F, 7/16F,
9/16F, 15/16F, 9/16F
);
public BlockStick(String domain, String name) {
super(Material.PLANTS);
setRegistryName(domain, name);
setTranslationKey(name);
setHardness(0.2F);
setSoundType(SoundType.WOOD);
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Deprecated
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Deprecated
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return BOUNDING_BOX.offset(state.getOffset(source, pos));
}
@Deprecated
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return state.getBoundingBox(world, pos);
}
@Override
public EnumOffsetType getOffsetType() {
return EnumOffsetType.XZ;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Items.STICK;
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float x, float y, float z) {
if (!world.isRemote) {
return ItemLead.attachToFence(player, world, pos);
}
ItemStack stack = player.getHeldItem(hand);
return stack.getItem() == Items.LEAD || stack.isEmpty();
}
public boolean canSustainPlant(IBlockAccess world, BlockPos pos, IPlantable plantable) {
pos = pos.down();
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof BlockStick) {
return ((BlockStick)block).canSustainPlant(world, pos, plantable);
}
return block.canSustainPlant(state, world, pos, EnumFacing.UP, plantable);
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Crop;
}
@Override
public IBlockState getPlant(IBlockAccess world, BlockPos pos) {
return getDefaultState();
}
}

View file

@ -1,34 +0,0 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
public class BlockSugar extends BlockFalling {
public BlockSugar(String domain, String name) {
super(Material.SAND);
setTranslationKey(name);
setRegistryName(domain, name);
setSoundType(SoundType.SAND);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setHardness(0.7F);
}
@Override
public int quantityDropped(Random random) {
return 9;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Items.SUGAR;
}
}

View file

@ -2,68 +2,61 @@ package com.minelittlepony.unicopia.block;
import java.util.Random; import java.util.Random;
import com.minelittlepony.unicopia.init.UItems; import com.minelittlepony.unicopia.UItems;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.CropBlock;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.Fertilizable;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.entity.EntityContext;
import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.item.Items;
import net.minecraft.util.EnumHand; import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.IStringSerializable; import net.minecraft.sound.SoundCategory;
import net.minecraft.util.NonNullList; import net.minecraft.state.StateFactory;
import net.minecraft.util.SoundCategory; import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.Hand;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable;
public class BlockTomatoPlant extends BlockCrops { public class BlockTomatoPlant extends CropBlock {
public static final PropertyEnum<Type> TYPE = PropertyEnum.create("type", Type.class); public static final EnumProperty<Type> TYPE = EnumProperty.of("type", Type.class);
public BlockTomatoPlant(String domain, String name) { public BlockTomatoPlant(String domain, String name) {
setRegistryName(domain, name); setDefaultState(getDefaultState().with(TYPE, Type.NORMAL));
setTranslationKey(name);
setDefaultState(getDefaultState().withProperty(TYPE, Type.NORMAL));
setHardness(0.2F); setHardness(0.2F);
setSoundType(SoundType.WOOD); setSoundType(SoundType.WOOD);
} }
@Deprecated @Deprecated
@Override @Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { public VoxelShape getOutlineShape(BlockState state, BlockView source, BlockPos pos, EntityContext context) {
return BlockStick.BOUNDING_BOX.offset(state.getOffset(source, pos)); Vec3d off = state.getOffsetPos(source, pos);
} return StickBlock.BOUNDING_BOX.offset(off.x, off.y, off.z);
@Deprecated
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return state.getBoundingBox(world, pos);
} }
@Override @Override
protected BlockStateContainer createBlockState() { protected void appendProperties(StateFactory.Builder<Block, BlockState> builder) {
return new BlockStateContainer(this, TYPE, AGE); super.appendProperties(builder);
builder.add(TYPE);
} }
@Override @Override
public EnumOffsetType getOffsetType() { public Block.OffsetType getOffsetType() {
return EnumOffsetType.XZ; return Block.OffsetType.XZ;
} }
@Override @Override
protected Item getSeed() { protected Item getSeedsItem() {
return UItems.tomato_seeds; return UItems.tomato_seeds;
} }
@ -81,9 +74,9 @@ public class BlockTomatoPlant extends BlockCrops {
} }
@Override @Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) { public boolean canSustainPlant(BlockState state, BlockView world, BlockPos pos, Direction direction, Fertilizable plantable) {
if (direction == EnumFacing.UP && state.getBlock() instanceof BlockTomatoPlant) { if (direction == Direction.UP && state.getBlock() instanceof BlockTomatoPlant) {
return true; return true;
} }
@ -91,46 +84,37 @@ public class BlockTomatoPlant extends BlockCrops {
} }
@Override @Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) { public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) {
checkAndDropBlock(world, pos, state); checkAndDropBlock(world, pos, state);
if (world.isAreaLoaded(pos, 1) && world.getLightFromNeighbors(pos.up()) >= 9) { if (world.isBlockLoaded(pos) && world.getLightLevel(pos.up()) >= 9) {
int i = getAge(state); int i = getAge(state);
if (i < getMaxAge()) { if (i < getMaxAge()) {
float f = getGrowthChance(this, world, pos); float f = getAvailableMoisture(this, world, pos);
if (ForgeHooks.onCropsGrowPre(world, pos, state, rand.nextInt((int)(25 / f) + 1) == 0)) { world.setBlockState(pos, state.with(getAgeProperty(), i + 1), 2);
world.setBlockState(pos, state.withProperty(getAgeProperty(), i + 1), 2);
ForgeHooks.onCropsGrowPost(world, pos, state, world.getBlockState(pos));
}
} }
} }
} }
@Override @Override
public int quantityDropped(IBlockState state, int fortune, Random random) { public int quantityDropped(BlockState state, int fortune, Random random) {
return 1; return 1;
} }
@Override @Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) { public Item getItemDropped(BlockState state, Random rand, int fortune) {
return EnumPlantType.Crop;
}
@Override if (isMature(state)) {
public Item getItemDropped(IBlockState state, Random rand, int fortune) { return state.get(TYPE).getCrop();
if (isMaxAge(state)) {
return state.getValue(TYPE).getCrop();
} }
return getSeed(); return getSeed();
} }
@Override @Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { public void getDrops(NonNullList<ItemStack> drops, WorldView world, BlockPos pos, BlockState state, int fortune) {
Random rand = world instanceof World ? ((World)world).rand : RANDOM; Random rand = world instanceof World ? ((World)world).rand : RANDOM;
drops.add(new ItemStack(Items.STICK, 1, 0)); drops.add(new ItemStack(Items.STICK, 1, 0));
@ -142,25 +126,25 @@ public class BlockTomatoPlant extends BlockCrops {
} }
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (hand == EnumHand.MAIN_HAND && isMaxAge(state)) { if (hand == Hand.MAIN_HAND && isMature(state)) {
if (player.getHeldItem(hand).isEmpty()) { if (player.getStackInHand(hand).isEmpty()) {
Type type = state.getValue(TYPE); Type type = state.get(TYPE);
int good = getAge(state); int good = getAge(state);
int rotten = world.rand.nextInt(good); int rotten = world.random.nextInt(good);
good -= rotten; good -= rotten;
if (good > 0) { if (good > 0) {
spawnAsEntity(world, pos, new ItemStack(type.getCrop(), good)); dropStack(world, pos, new ItemStack(type.getCrop(), good));
} }
if (rotten > 0) { if (rotten > 0) {
spawnAsEntity(world, pos, new ItemStack(type.getWaste(), rotten)); dropStack(world, pos, new ItemStack(type.getWaste(), rotten));
} }
world.setBlockState(pos, state.withProperty(getAgeProperty(), 0)); world.setBlockState(pos, state.with(getAgeProperty(), 0));
return true; return true;
} }
@ -170,20 +154,20 @@ public class BlockTomatoPlant extends BlockCrops {
} }
@Override @Override
public void grow(World worldIn, BlockPos pos, IBlockState state) { public void applyGrowth(World world, BlockPos pos, BlockState state) {
int age = Math.min(getAge(state) + getBonemealAgeIncrease(worldIn), getMaxAge()); int age = Math.min(getAge(state) + getGrowthAmount(world), getMaxAge());
worldIn.setBlockState(pos, state.withProperty(getAgeProperty(), age), 2); world.setBlockState(pos, state.with(getAgeProperty(), age), 2);
} }
public boolean plant(World world, BlockPos pos, IBlockState state) { public boolean plant(World world, BlockPos pos, BlockState state) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof BlockStick && ((BlockStick)block).canSustainPlant(world, pos, this)) { if (block instanceof StickBlock && ((StickBlock)block).canSustainPlant(world, pos, this)) {
world.setBlockState(pos, getPlacedState(world, pos, state).withProperty(getAgeProperty(), 1)); world.setBlockState(pos, getPlacedState(world, pos, state).with(getAgeProperty(), 1));
SoundType sound = getSoundType(state, world, pos, null); BlockSoundGroup sound = getSoundGroup(state);
world.playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, sound.getVolume(), sound.getPitch() * 2); world.playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, sound.getVolume(), sound.getPitch() * 2);
@ -193,48 +177,34 @@ public class BlockTomatoPlant extends BlockCrops {
return false; return false;
} }
@Override public BlockState getPlacedState(World world, BlockPos pos, BlockState state) {
public IBlockState getStateFromMeta(int meta) { if (state.getBlock() instanceof StickBlock) {
int age = meta % (getMaxAge() + 1);
int half = meta >> 3;;
return withAge(age).withProperty(TYPE, Type.values()[half]);
}
public IBlockState getPlacedState(World world, BlockPos pos, IBlockState state) {
if (state.getBlock() instanceof BlockStick) {
pos = pos.down(); pos = pos.down();
return getPlacedState(world, pos, world.getBlockState(pos)); return getPlacedState(world, pos, world.getBlockState(pos));
} }
if (state.getBlock() instanceof BlockCloudFarm) { if (state.getBlock() instanceof BlockCloudFarm) {
return getDefaultState().withProperty(TYPE, Type.CLOUDSDALE); return getDefaultState().with(TYPE, Type.CLOUDSDALE);
} }
if (state.getBlock() instanceof BlockTomatoPlant) { if (state.getBlock() instanceof BlockTomatoPlant) {
return getDefaultState().withProperty(TYPE, state.getValue(TYPE)); return getDefaultState().with(TYPE, state.get(TYPE));
} }
return getDefaultState(); return getDefaultState();
} }
@Override public enum Type implements StringIdentifiable {
public int getMetaFromState(IBlockState state) {
int age = getAge(state);
int half = state.getValue(TYPE).ordinal();
return (half << 3) + age;
}
public static enum Type implements IStringSerializable {
NORMAL, NORMAL,
CLOUDSDALE; CLOUDSDALE;
@Override
public String toString() { public String toString() {
return getName(); return asString();
} }
public String getName() { @Override
public String asString() {
return this == NORMAL ? "normal" : "cloudsdale"; return this == NORMAL ? "normal" : "cloudsdale";
} }

View file

@ -0,0 +1,79 @@
package com.minelittlepony.unicopia.block;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UMaterials;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.MaterialColor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateFactory;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
public class ChiselledChitinBlock extends Block {
public ChiselledChitinBlock(String domain, String name) {
super(FabricBlockSettings.of(UMaterials.hive)
.strength(50, 2000)
.materialColor(MaterialColor.BLACK)
.build()
);
setDefaultState(stateFactory.getDefaultState()
.with(Properties.FACING, Direction.UP)
);
// TODO:
// setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
@Override
public BlockState rotate(BlockState state, BlockRotation rot) {
return state.with(Properties.FACING, rot.rotate(state.get(Properties.FACING)));
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.with(Properties.FACING, mirror.apply(state.get(Properties.FACING)));
}
@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext context) {
return getDefaultState().with(Properties.FACING, context.getPlayerFacing());
}
@Override
protected void appendProperties(StateFactory.Builder<Block, BlockState> builder) {
builder.add(Properties.FACING);
}
@Deprecated
@Override
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView worldIn, BlockPos pos) {
float hardness = super.calcBlockBreakingDelta(state, player, worldIn, pos);
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
Race race = iplayer.getSpecies();
if (race == Race.CHANGELING) {
hardness *= 80;
} else if (race.canInteractWithClouds()) {
hardness /= 4;
} else if (race.canUseEarth()) {
hardness *= 10;
}
return hardness;
}
}

View file

@ -0,0 +1,97 @@
package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UMaterials;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.MaterialColor;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.StateFactory;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld;
public class ChitinBlock extends Block {
public static final EnumProperty<Covering> COVERING = EnumProperty.of("covering", Covering.class);
public ChitinBlock(String domain, String name) {
super(FabricBlockSettings.of(UMaterials.hive)
.hardness(50)
.strength(2000, 2000)
.materialColor(MaterialColor.BLACK)
.build()
);
setDefaultState(stateFactory.getDefaultState().with(COVERING, Covering.UNCOVERED));
// TODO: drops:
// UItems.chitin_shell x 3
// setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
}
@Deprecated
@Override
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
float hardness = super.calcBlockBreakingDelta(state, player, world, pos);
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
Race race = iplayer.getSpecies();
if (race == Race.CHANGELING) {
hardness *= 80;
} else if (race.canInteractWithClouds()) {
hardness /= 4;
} else if (race.canUseEarth()) {
hardness *= 10;
}
return hardness;
}
@Override
@Deprecated
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState other, IWorld world, BlockPos pos, BlockPos otherPos) {
if (direction == Direction.UP) {
Block block = other.getBlock();
boolean snowy = block == Blocks.SNOW_BLOCK || block == Blocks.SNOW;
boolean solid = (other.isOpaque() && other.isSimpleFullBlock(world, pos)) || Block.isFaceFullSquare(other.getCollisionShape(world, otherPos, EntityContext.absent()), Direction.DOWN);
return state.with(COVERING, snowy ? Covering.SNOW_COVERED : solid ? Covering.COVERED : Covering.UNCOVERED);
}
return state;
}
@Override
protected void appendProperties(StateFactory.Builder<Block, BlockState> builder) {
builder.add(COVERING);
}
public enum Covering implements StringIdentifiable {
COVERED,
UNCOVERED,
SNOW_COVERED;
@Override
public String toString() {
return asString();
}
@Override
public String asString() {
return name().toLowerCase();
}
}
}

View file

@ -0,0 +1,177 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import java.util.function.Function;
import javax.annotation.Nonnull;
import com.minelittlepony.unicopia.SpeciesList;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.DyeItem;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateFactory;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome.TemperatureGroup;
public class FruitLeavesBlock extends LeavesBlock implements IColourful {
public static final BooleanProperty HEAVY = BooleanProperty.of("heavy");
private boolean hardy;
private int baseGrowthChance;
private int customTint;
private Function<World, ItemStack> fruitProducer = w -> ItemStack.EMPTY;
private Function<World, ItemStack> compostProducer = w -> ItemStack.EMPTY;
public FruitLeavesBlock() {
super(FabricBlockSettings.of(Material.LEAVES)
.strength(0.2F, 0.2F)
.ticksRandomly()
.sounds(BlockSoundGroup.GRASS)
.build()
);
setDefaultState(stateFactory.getDefaultState()
.with(HEAVY, false)
.with(DISTANCE, 7)
.with(PERSISTENT, false)
);
}
public FruitLeavesBlock hardy(boolean value) {
hardy = value;
return this;
}
public FruitLeavesBlock fruit(@Nonnull Function<World, ItemStack> producer) {
fruitProducer = producer;
return this;
}
public FruitLeavesBlock compost(@Nonnull Function<World, ItemStack> producer) {
compostProducer = producer;
return this;
}
public FruitLeavesBlock growthChance(int chance) {
baseGrowthChance = chance;
return this;
}
public FruitLeavesBlock tint(int tint) {
customTint = tint;
return this;
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack stack = player.getStackInHand(hand);
if (SpeciesList.instance().getPlayer(player).getSpecies().canUseEarth()) {
if (stack.isEmpty()) {
if (state.get(HEAVY)) {
dropContents(world, pos, state, 0);
}
} else if (stack.getItem() instanceof DyeItem && ((DyeItem)stack.getItem()).getColor() == DyeColor.WHITE) {
if (!state.get(HEAVY)) {
world.setBlockState(pos, state.with(HEAVY, true));
if (!world.isClient) {
world.playGlobalEvent(2005, pos, 0);
}
if (!player.abilities.creativeMode) {
stack.decrement(1);
}
}
}
return true;
}
return false;
}
@Override
public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) {
if (!world.isClient && world.isBlockLoaded(pos) && !state.get(PERSISTENT)) {
int growthChance = getGrowthChance(world, pos, state);
if (!state.get(HEAVY) && (growthChance <= 0 || rand.nextInt(growthChance) == 0)) {
world.setBlockState(pos, state.with(HEAVY, true));
} else {
growthChance /= 10;
if (state.get(HEAVY) && (growthChance <= 0 || rand.nextInt(growthChance) == 0)) {
dropContents(world, pos, state, 0);
} else {
super.onScheduledTick(state, world, pos, rand);
}
}
}
}
protected int getGrowthChance(World world, BlockPos pos, BlockState state) {
int chance = baseGrowthChance;
if (!hardy && !world.isDaylight()) {
chance *= 40;
}
if (world.getLightLevel(pos) >= 4) {
chance /= 3;
}
TemperatureGroup temp = world.getBiome(pos).getTemperatureGroup();
if (!hardy && temp == TemperatureGroup.COLD) {
chance *= 1000;
}
if (temp == TemperatureGroup.WARM) {
chance /= 100;
}
if (temp == TemperatureGroup.MEDIUM) {
chance /= 50;
}
return chance;
}
@Override
public int getCustomTint(BlockState state, int tint) {
return customTint;
}
protected void dropContents(World world, BlockPos pos, BlockState state, int chance) {
Function<World, ItemStack> fruit = world.random.nextInt(40) == 0 ? compostProducer : fruitProducer;
dropStack(world, pos, fruit.apply(world));
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_FRAME_PLACE, SoundCategory.BLOCKS, 0.3F, 1);
world.setBlockState(pos, state.with(HEAVY, false));
}
@Override
protected void appendProperties(StateFactory.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(HEAVY);
}
}

View file

@ -0,0 +1,194 @@
package com.minelittlepony.unicopia.block;
import java.util.Random;
import com.minelittlepony.unicopia.CloudType;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.TorchBlock;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateFactory;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
public class GlowingGemBlock extends TorchBlock implements ICloudBlock {
public static BooleanProperty ON = BooleanProperty.of("on");
private static final double A = 5/16D;
private static final double B = 6/16D;
private static final double C = 10/16D;
// tiltedOffWall
private static final double F = 10/16D;
// tiltedMinY
private static final double E = 3/16D;
protected static final VoxelShape STANDING_AABB = VoxelShapes.cuboid(new Box(
7/16D, 0, 7/16D,
9/16D, 1, 9/16D
));
protected static final VoxelShape TORCH_NORTH_AABB = VoxelShapes.cuboid(new Box(B, E, F, C, 1, 1));
protected static final VoxelShape TORCH_SOUTH_AABB = VoxelShapes.cuboid(new Box(B, E, 0, C, 1, A));
protected static final VoxelShape TORCH_WEST_AABB = VoxelShapes.cuboid(new Box(F, E, B, 1, 1, C));
protected static final VoxelShape TORCH_EAST_AABB = VoxelShapes.cuboid(new Box(0, E, B, A, 1, C));
public GlowingGemBlock(String domain, String name) {
super(FabricBlockSettings.of(Material.PART)
.noCollision()
.strength(0, 0)
.ticksRandomly()
.lightLevel(1)
.sounds(BlockSoundGroup.GLASS)
.build()
);
setDefaultState(stateFactory.getDefaultState()
.with(Properties.FACING, Direction.UP)
.with(ON, true)
);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView source, BlockPos pos, EntityContext context) {
switch (state.get(Properties.FACING)) {
case EAST: return TORCH_EAST_AABB;
case WEST: return TORCH_WEST_AABB;
case SOUTH: return TORCH_SOUTH_AABB;
case NORTH: return TORCH_NORTH_AABB;
default: return STANDING_AABB;
}
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!state.get(ON)) {
ItemStack held = player.getStackInHand(hand);
if (!held.isEmpty() && (held.getItem() == Items.FLINT_AND_STEEL || held.getItem() == Items.FIRE_CHARGE)) {
world.playSound(null, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
world.setBlockState(pos, state.with(ON, true));
if (held.getItem() == Items.FLINT_AND_STEEL) {
held.damage(1, player, p -> p.sendToolBreakStatus(hand));
} else if (!player.abilities.creativeMode) {
held.decrement(1);
}
}
return true;
}
return false;
}
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random rand) {
Direction facing = state.get(Properties.FACING);
double x = pos.getX() + 0.5;
double y = pos.getY() + 1;
double z = pos.getZ() + 0.5;
double drop = 0.22D;
double variance = 0.27D;
if (facing.getAxis().isHorizontal()) {
facing = facing.getOpposite();
x += variance * facing.getOffsetX();
y += drop;
z += variance * facing.getOffsetZ();
}
if (state.get(ON)) {
for (int i = 0; i < 3; i++) {
// TODO:
// ParticleTypeRegistry.getTnstance().spawnParticle(UParticles.UNICORN_MAGIC, false,
// x - 0.3, y - 0.3, z - 0.3,
// rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
}
} else {
world.addParticle(ParticleTypes.SMOKE, x, y, z, 0, 0, 0);
}
}
@Override
public void onScheduledTick(BlockState state, World world, BlockPos pos, Random random) {
if (world.hasRain(pos)) {
if (state.get(ON)) {
world.playSound(null, pos, SoundEvents.BLOCK_REDSTONE_TORCH_BURNOUT, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
world.setBlockState(pos, state.with(ON, false));
}
} else {
if (!state.get(ON)) {
world.playSound(null, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
world.setBlockState(pos, state.with(ON, true));
}
}
}
@Override
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction side) {
return state.get(ON) && side == Direction.DOWN ? state.getWeakRedstonePower(world, pos, side) : 0;
}
@Override
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction side) {
return state.get(ON) && state.get(Properties.FACING) != side ? 12 : 0;
}
@Override
public CloudType getCloudMaterialType(BlockState blockState) {
return CloudType.ENCHANTED;
}
// TODO: this is a loot table now
/*@Override
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder context) {
Random rand = context.world instanceof World ? ((World)world).random : random;
if (rand.nextInt(10) == 0) {
drops.add(new ItemStack(UItems.spell));
} else {
drops.add(new ItemStack(UItems.curse));
}
return drops;
}*/
@Override
public int getLuminance(BlockState state) {
if (state.get(ON)) {
return super.getLuminance(state);
}
return 0;
}
@Override
protected void appendProperties(StateFactory.Builder<Block, BlockState> builder) {
builder.add(Properties.FACING).add(ON);
}
}

View file

@ -0,0 +1,366 @@
package com.minelittlepony.unicopia.block;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.UMaterials;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.util.PosHelper;
import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.shape.Sphere;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateFactory;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.Hand;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.ViewableWorld;
import net.minecraft.world.World;
public class HiveWallBlock extends FallingBlock {
public static final EnumProperty<State> STATE = EnumProperty.of("state", State.class);
public static final EnumProperty<Axis> AXIS = EnumProperty.of("axis", Axis.class);
private static final IShape shape = new Sphere(false, 1.5);
public HiveWallBlock(String domain, String name) {
super(FabricBlockSettings.of(UMaterials.hive)
.noCollision()
.strength(10, 10)
.hardness(2)
.ticksRandomly()
.lightLevel(1)
.sounds(BlockSoundGroup.SAND)
.build()
);
setDefaultState(stateFactory.getDefaultState()
.with(STATE, State.GROWING).with(AXIS, Axis.Y)
);
// TODO:
// setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
// setHarvestLevel("pickaxe", 1);
}
@Override
public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) {
if (rand.nextInt(300) == 0) {
world.playSound(null, pos, USounds.INSECT, SoundCategory.BLOCKS, 1, 1);
}
State type = getState(state);
Axis axis = getAxis(state);
int matchedNeighbours = countNeighbours(world, pos);
if (type == State.GROWING) {
if (testForAxis(world, pos, axis)) {
world.setBlockState(pos, state.with(STATE, State.STABLE));
} else {
Axis newAxis = axis;
for (Axis i : Axis.VALUES) {
if (testForAxis(world, pos, i)) {
newAxis = i;
break;
}
}
if (newAxis != axis) {
world.setBlockState(pos, state.with(AXIS, newAxis).with(STATE, State.STABLE));
} else if (rand.nextInt(10) == 0) {
Direction facing = axis.randomFacing(rand);
BlockPos other = pos.offset(facing);
if (canSpreadInto(world, other, axis)) {
world.playSound(null, pos, USounds.SLIME_RETRACT, SoundCategory.BLOCKS, 1, 1);
world.setBlockState(other, state);
world.setBlockState(pos, state.with(STATE, State.STABLE));
}
}
}
} else if (type == State.DYING) {
if (matchedNeighbours > 1 && matchedNeighbours < 17) {
world.setBlockState(pos, state.with(STATE, State.STABLE));
} else {
die(world, pos, rand);
}
} else {
if (pos.getX() % 3 == 0 && pos.getZ() % 4 == 0 && isEmptySpace(world, pos.down()) && UBlocks.cuccoon.canPlaceBlockAt(world, pos.down())) {
world.setBlockState(pos.down(), UBlocks.cuccoon.getDefaultState());
} else if (!testForAxis(world, pos, axis)) {
world.setBlockState(pos, state.with(STATE, State.GROWING));
} else if (matchedNeighbours >= 27) {
world.setBlockState(pos, state.with(STATE, State.DYING));
} else {
return;
}
}
world.getBlockTickScheduler().schedule(pos, this, getTickRate(world));
}
public State getState(BlockState state) {
return state.get(STATE);
}
public Axis getAxis(BlockState state) {
return state.get(AXIS);
}
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean uuuuh) {
if (state.get(STATE) != State.STABLE) {
super.onBlockAdded(state, world, pos, oldState, uuuuh);
}
}
@Override
public int getTickRate(ViewableWorld view) {
return 10;
}
protected boolean testForAxis(World world, BlockPos pos, Axis axis) {
return !PosHelper.some(pos, p -> isEmptySpace(world, p), axis.getFacings());
}
protected boolean isEmptySpace(World world, BlockPos pos) {
if (world.isAir(pos)) {
return true;
}
BlockState state = world.getBlockState(pos);
return !(state.getMaterial().isLiquid()
|| state.isFullOpaque(world, pos)
|| state.isOpaque());
}
protected void die(World world, BlockPos pos, Random rand) {
world.breakBlock(pos, false);
PosHelper.all(pos, p -> {
BlockState s = world.getBlockState(p);
if (s.getBlock() == this) {
notifyDying(world, p, s, rand);
}
}, Direction.values());
}
protected void notifyDying(World world, BlockPos pos, BlockState state, Random rand) {
State oldState = state.get(STATE);
State newState = oldState.downGrade();
if (newState != oldState) {
world.setBlockState(pos, state.with(STATE, newState));
}
}
@Override
public void onSteppedOn(World world, BlockPos pos, Entity entity) {
if (entity instanceof PlayerEntity) {
IPlayer player = SpeciesList.instance().getPlayer((PlayerEntity)entity);
if (player.getSpecies() != Race.CHANGELING && !world.isClient) {
if (((isEmptySpace(world, pos.down()) || canFallThrough(world.getBlockState(pos.down()))) && pos.getY() >= 0)) {
FallingBlockEntity faller = new FallingBlockEntity(world, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, world.getBlockState(pos));
configureFallingBlockEntity(faller);
world.spawnEntity(faller);
}
}
}
}
@Override
public void onLanding(World world, BlockPos pos, BlockState fallingState, BlockState hitState) {
world.breakBlock(pos, true);
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (hand == Hand.MAIN_HAND && player.getStackInHand(hand).isEmpty()) {
IPlayer iplayer = SpeciesList.instance().getPlayer(player);
if (iplayer.getSpecies() == Race.CHANGELING) {
retreat(world, pos);
PosHelper.adjacentNeighbours(pos).forEach(p -> {
if (world.getBlockState(p).getBlock() == this) {
retreat(world, p);
}
});
return true;
}
}
return false;
}
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
return getDefaultState().with(AXIS, Axis.fromVanilla(context.getPlayerFacing().getAxis()));
}
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random rand) {
if (rand.nextInt(16) == 0) {
Vec3d vel = shape.computePoint(rand);
Vec3d vec = vel.add(pos.getX(), pos.getY(), pos.getZ());
world.addParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, state), vec.x, vec.y, vec.z, vel.x, vel.y, vel.z);
}
}
public void retreat(World world, BlockPos pos) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
world.playSound(null, pos, USounds.SLIME_RETRACT, SoundCategory.BLOCKS, 1, 1);
}
protected int countNeighbours(World world, BlockPos pos) {
int count = 0;
for (BlockPos i : BlockPos.iterate(pos.add(-1, -1, -1), pos.add(1, 1, 1))) {
if (world.getBlockState(i).getBlock() == this) {
count++;
}
}
return count;
}
protected boolean exposed(World world, BlockPos pos) {
return PosHelper.some(pos, p -> isEmptySpace(world, p), Direction.values());
}
protected boolean canSpreadInto(World world, BlockPos pos, Axis axis) {
if (world.isBlockLoaded(pos) && isEmptySpace(world, pos)) {
boolean one = false;
for (Direction facing : axis.getFacings()) {
BlockPos op = pos.offset(facing);
if (world.getBlockState(op).getMaterial() == UMaterials.hive) {
if (one) {
return true;
}
one = true;
}
}
}
return false;
}
@Override
protected void appendProperties(StateFactory.Builder<Block, BlockState> builder) {
builder.add(STATE).add(AXIS);
}
public enum State implements StringIdentifiable {
GROWING,
STABLE,
DYING;
static final State[] VALUES = values();
@Override
public String toString() {
return asString();
}
@Override
public String asString() {
return name().toLowerCase();
}
public State upgrade() {
switch (this) {
case DYING: return STABLE;
default: return GROWING;
}
}
public State downGrade() {
switch (this) {
case GROWING: return STABLE;
default: return DYING;
}
}
}
public enum Axis implements StringIdentifiable {
X(Direction.Axis.X, Direction.EAST, Direction.WEST, Direction.UP, Direction.DOWN),
Y(Direction.Axis.Y, Direction.EAST, Direction.WEST, Direction.NORTH, Direction.SOUTH),
Z(Direction.Axis.Z, Direction.NORTH, Direction.SOUTH, Direction.UP, Direction.DOWN);
static final Axis[] VALUES = values();
static final Map<Direction.Axis, Axis> AXIS_MAP = Maps.newEnumMap(Direction.Axis.class);
private final Direction.Axis vanilla;
private final Direction[] facings;
static {
for (Axis i : VALUES) {
AXIS_MAP.put(i.vanilla, i);
}
}
Axis(Direction.Axis vanilla, Direction... facings) {
this.vanilla = vanilla;
this.facings = facings;
}
@Override
public String toString() {
return asString();
}
@Override
public String asString() {
return name().toLowerCase();
}
public Direction randomFacing(Random rand) {
return facings[rand.nextInt(facings.length)];
}
public Direction[] getFacings() {
return facings;
}
public static Axis fromVanilla(Direction.Axis axis) {
return AXIS_MAP.get(axis);
}
}
}

View file

@ -3,32 +3,31 @@ package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.Predicates;
import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.UClient;
import com.minelittlepony.unicopia.forgebullshit.FUF; import net.minecraft.block.BedBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockBed; import net.minecraft.block.BlockState;
import net.minecraft.block.BlockChest; import net.minecraft.block.ChestBlock;
import net.minecraft.block.BlockFalling; import net.minecraft.block.FallingBlock;
import net.minecraft.block.BlockTorch; import net.minecraft.block.TorchBlock;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.Blocks; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface ICloudBlock { public interface ICloudBlock {
CloudType getCloudMaterialType(IBlockState blockState); CloudType getCloudMaterialType(BlockState blockState);
default boolean handleRayTraceSpecialCases(World world, BlockPos pos, IBlockState state) { default boolean handleRayTraceSpecialCases(World world, BlockPos pos, BlockState state) {
if (world.isRemote) { if (world.isClient) {
EntityPlayer player = UClient.instance().getPlayer(); PlayerEntity player = UClient.instance().getPlayer();
if (player.capabilities.isCreativeMode) { if (player.abilities.creativeMode) {
return false; return false;
} }
@ -38,20 +37,21 @@ public interface ICloudBlock {
CloudType type = getCloudMaterialType(state); CloudType type = getCloudMaterialType(state);
ItemStack main = player.getHeldItemMainhand(); ItemStack main = player.getMainHandStack();
if (main.isEmpty()) { if (main.isEmpty()) {
main = player.getHeldItemOffhand(); main = player.getOffHandStack();
} }
if (!main.isEmpty() && main.getItem() instanceof ItemBlock) { if (!main.isEmpty() && main.getItem() instanceof BlockItem) {
Block block = ((ItemBlock)main.getItem()).getBlock(); Block block = ((BlockItem)main.getItem()).getBlock();
BlockState heldState = block.getDefaultState();
if (block == null || block == Blocks.AIR) { if (block == null || block.isAir(heldState)) {
return false; return false;
} }
if (block instanceof ICloudBlock) { if (block instanceof ICloudBlock) {
CloudType other = ((ICloudBlock)block).getCloudMaterialType(block.getDefaultState()); CloudType other = ((ICloudBlock)block).getCloudMaterialType(heldState);
if (other.canInteract(player)) { if (other.canInteract(player)) {
return false; return false;
@ -72,14 +72,14 @@ public interface ICloudBlock {
} }
default boolean isPlacementExcempt(Block block) { default boolean isPlacementExcempt(Block block) {
return block instanceof BlockTorch return block instanceof TorchBlock
|| block instanceof BlockBed || block instanceof BedBlock
|| block instanceof BlockChest; || block instanceof ChestBlock;
} }
default boolean applyLanding(Entity entity, float fallDistance) { default boolean applyLanding(Entity entity, float fallDistance) {
if (!entity.isSneaking()) { if (!entity.isSneaking()) {
entity.fall(fallDistance, 0); entity.handleFallDamage(fallDistance, 0);
return false; return false;
} }
@ -88,12 +88,17 @@ public interface ICloudBlock {
} }
default boolean applyRebound(Entity entity) { default boolean applyRebound(Entity entity) {
if (!entity.isSneaking() && entity.motionY < 0) {
if (Math.abs(entity.motionY) >= 0.25) { Vec3d vel = entity.getVelocity();
entity.motionY = -entity.motionY * 1.2; double y = vel.y;
if (!entity.isSneaking() && y < 0) {
if (Math.abs(y) >= 0.25) {
y = -y * 1.2;
} else { } else {
entity.motionY = 0; y = 0;
} }
entity.setVelocity(vel.x, y, vel.z);
return true; return true;
} }
@ -101,13 +106,17 @@ public interface ICloudBlock {
return false; return false;
} }
default boolean applyBouncyness(IBlockState state, Entity entity) { default boolean applyBouncyness(BlockState state, Entity entity) {
if (getCanInteract(state, entity)) { if (getCanInteract(state, entity)) {
if (!entity.isSneaking() && Math.abs(entity.motionY) >= 0.25) { Vec3d vel = entity.getVelocity();
entity.motionY += 0.0155 * (entity.fallDistance < 1 ? 1 : entity.fallDistance); double y = vel.y;
if (!entity.isSneaking() && Math.abs(y) >= 0.25) {
y += 0.0155 * (entity.fallDistance < 1 ? 1 : entity.fallDistance);
} else { } else {
entity.motionY = 0; y = 0;
} }
entity.setVelocity(vel.x, y, vel.z);
return true; return true;
} }
@ -116,9 +125,9 @@ public interface ICloudBlock {
} }
default boolean getCanInteract(IBlockState state, Entity e) { default boolean getCanInteract(BlockState state, Entity e) {
if (getCloudMaterialType(state).canInteract(e)) { if (getCloudMaterialType(state).canInteract(e)) {
if (e instanceof EntityItem) { if (e instanceof ItemEntity) {
// @FUF(reason = "There is no TickEvents.EntityTickEvent. Waiting on mixins...") // @FUF(reason = "There is no TickEvents.EntityTickEvent. Waiting on mixins...")
e.setNoGravity(true); e.setNoGravity(true);
} }
@ -128,7 +137,7 @@ public interface ICloudBlock {
return false; return false;
} }
default boolean isDense(IBlockState blockState) { default boolean isDense(BlockState blockState) {
return getCloudMaterialType(blockState) != CloudType.NORMAL; return getCloudMaterialType(blockState) != CloudType.NORMAL;
} }
@ -139,14 +148,15 @@ public interface ICloudBlock {
* @param pos The current position * @param pos The current position
* *
* @return True to allow blocks to pass. * @return True to allow blocks to pass.
*
* @fuf Hacked until we can get mixins to implement a proper hook
*/ */
@FUF(reason = "Hacked until we can get mixins to implement a proper hook") default boolean allowsFallingBlockToPass(BlockState state, BlockView world, BlockPos pos) {
default boolean allowsFallingBlockToPass(IBlockState state, IBlockAccess world, BlockPos pos) {
if (isDense(state)) { if (isDense(state)) {
return false; return false;
} }
Block above = world.getBlockState(pos.up()).getBlock(); Block above = world.getBlockState(pos.up()).getBlock();
return !(above instanceof ICloudBlock) && above instanceof BlockFalling; return !(above instanceof ICloudBlock) && above instanceof FallingBlock;
} }
} }

View file

@ -1,8 +1,8 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
@FunctionalInterface @FunctionalInterface
public interface IColourful { public interface IColourful {
int getCustomTint(IBlockState state, int tint); int getCustomTint(BlockState state, int tint);
} }

View file

@ -2,8 +2,8 @@ package com.minelittlepony.unicopia.block;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -16,9 +16,9 @@ public interface ITillable {
* Gets the farmland/tilled state for this block when attacked by a hoe. * Gets the farmland/tilled state for this block when attacked by a hoe.
*/ */
@Nonnull @Nonnull
IBlockState getFarmlandState(ItemStack hoe, EntityPlayer player, World world, IBlockState state, BlockPos pos); BlockState getFarmlandState(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos);
default boolean canBeTilled(ItemStack hoe, EntityPlayer player, World world, IBlockState state, BlockPos pos) { default boolean canBeTilled(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos) {
return world.isAirBlock(pos.up()); return world.isAir(pos.up());
} }
} }

View file

@ -1,12 +1,11 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.BlockState;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenAbstractTree;
@FunctionalInterface @FunctionalInterface
public interface ITreeGen { public interface ITreeGen {
WorldGenAbstractTree getTreeGen(World world, IBlockState state, boolean massive); WorldGenAbstractTree getTreeGen(World world, BlockState state, boolean massive);
default boolean canGrowMassive() { default boolean canGrowMassive() {
return false; return false;

View file

@ -0,0 +1,43 @@
package com.minelittlepony.unicopia.block;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.MaterialColor;
import net.minecraft.block.SnowBlock;
import net.minecraft.entity.Entity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class SlimeLayerBlock extends SnowBlock {
public SlimeLayerBlock(String domain, String name) {
super(FabricBlockSettings.of(Material.CLAY)
.sounds(BlockSoundGroup.SLIME)
.materialColor(MaterialColor.GRASS)
.build()
);
// TODO:
// drops Items.SLIME_BALL x1
// setCreativeTab(CreativeTabs.DECORATIONS);
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Override
public void onSteppedOn(World world, BlockPos pos, Entity entity) {
float factor = getMotionFactor(world.getBlockState(pos));
entity.setVelocity(entity.getVelocity().multiply(factor));
}
protected float getMotionFactor(BlockState state) {
return 1/state.get(LAYERS);
}
}

View file

@ -0,0 +1,81 @@
package com.minelittlepony.unicopia.block;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.BlockState;
import net.minecraft.block.FarmlandBlock;
import net.minecraft.block.Material;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.LeadItem;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.ViewableWorld;
import net.minecraft.world.World;
public class StickBlock extends Block {
static final VoxelShape BOUNDING_BOX = VoxelShapes.cuboid(new Box(
7/16F, -1/16F, 7/16F,
9/16F, 15/16F, 9/16F
));
public StickBlock(String domain, String name) {
super(FabricBlockSettings.of(Material.PLANT)
.noCollision()
.strength(0.2F, 0.2F)
.ticksRandomly()
.lightLevel(1)
.sounds(BlockSoundGroup.WOOD)
.build()
);
// TODO:
// drops Items.STICK x1
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Deprecated
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView source, BlockPos pos, EntityContext context) {
Vec3d off = state.getOffsetPos(source, pos);
return BOUNDING_BOX.offset(off.x, off.y, off.z);
}
@Override
public Block.OffsetType getOffsetType() {
return Block.OffsetType.XZ;
}
@Override
public boolean activate(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient) {
return LeadItem.attachHeldMobsToBlock(player, world, pos);
}
ItemStack stack = player.getStackInHand(hand);
return stack.getItem() == Items.LEAD || stack.isEmpty();
}
@Override
public boolean canPlaceAt(BlockState state, ViewableWorld world, BlockPos pos) {
Block block = state.getBlock();
return block instanceof StickBlock || block instanceof FarmlandBlock;
}
}

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