Skip to content

Commit

Permalink
Upgrade Iron Chests to 1.15.2. Textures are broken at the moment due …
Browse files Browse the repository at this point in the history
…to vanilla changes.
  • Loading branch information
alexbegt committed Jan 22, 2020
1 parent d015254 commit 56db909
Show file tree
Hide file tree
Showing 42 changed files with 548 additions and 147 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ out/
.idea/
/*.iml
/*.ipr
/*.iws
/*.iws
/generated
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = co
minecraft {
mappings channel: 'snapshot', version: mappings_version

accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

runs {
client {
workingDirectory project.file('run')
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ org.gradle.daemon=false
mod_version=10.0

# Minecraft Version Information
minecraft_version=1.15.1
minecraft_version=1.15.2
minecraft_version_toml=15

# Forge Version Information
forge_version=30.0.18
forge_version_toml=30
forge_version=31.0.0
forge_version_toml=31

# Mappings Information
mappings_version=20191217-1.14.3
mappings_version=20200122-1.15.1
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package com.progwml6.ironchest.client.data;

import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.Util;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.item.IronChestsItems;
import net.minecraft.block.Block;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.DirectoryCache;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.IItemProvider;
import net.minecraftforge.common.data.LanguageProvider;
import net.minecraftforge.registries.IForgeRegistryEntry;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class IronChestsLangProvider extends LanguageProvider {

Expand Down Expand Up @@ -34,7 +49,57 @@ public IronChestsLangProvider(DataGenerator gen) {

@Override
protected void addTranslations() {
// Blocks

this.addBlock(IronChestsBlocks.IRON_CHEST);
this.addBlock(IronChestsBlocks.GOLD_CHEST);
this.addBlock(IronChestsBlocks.DIAMOND_CHEST);
this.addBlock(IronChestsBlocks.COPPER_CHEST);
this.addBlock(IronChestsBlocks.SILVER_CHEST);
this.addBlock(IronChestsBlocks.CRYSTAL_CHEST);
this.addBlock(IronChestsBlocks.OBSIDIAN_CHEST);
this.addBlock(IronChestsBlocks.DIRT_CHEST);

// ITEMS

IronChestsItems.UPGRADES.values().forEach(this::addItem);

// MISC

this.add(IronChests.IRONCHESTS_ITEM_GROUP, "Iron Chests");

//IronChestsTypes.values()
}

private String getAutomaticName(Supplier<? extends IForgeRegistryEntry<?>> sup) {
return Util.toEnglishName(sup.get().getRegistryName().getPath());
}

private void addBlock(Supplier<? extends Block> block) {
this.addBlock(block, this.getAutomaticName(block));
}

private void addItem(Supplier<? extends Item> item) {
this.addItem(item, this.getAutomaticName(item));
}

private void addItemWithTooltip(Supplier<? extends Item> block, String name, List<String> tooltip) {
this.addItem(block, name);
this.addTooltip(block, tooltip);
}

private void addTooltip(Supplier<? extends IItemProvider> item, String tooltip) {
this.add(item.get().asItem().getTranslationKey() + ".desc", tooltip);
}

private void addTooltip(Supplier<? extends IItemProvider> item, List<String> tooltip) {
for (int i = 0; i < tooltip.size(); i++) {
this.add(item.get().asItem().getTranslationKey() + ".desc." + i, tooltip.get(i));
}
}

private void add(ItemGroup group, String name) {
this.add(group.getTranslationKey(), name);
}

// Automatic en_ud generation
Expand Down Expand Up @@ -83,7 +148,7 @@ private String toUpsideDown(String normal) {
}

@Override
protected void add(String key, String value) {
public void add(String key, String value) {
super.add(key, value);
this.upsideDown.add(key, this.toUpsideDown(value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IronChestItemStackRenderer(Supplier<T> te) {
}

@Override
public void func_228364_a_(ItemStack itemStackIn, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int p_228364_4_, int p_228364_5_) {
TileEntityRendererDispatcher.instance.func_228852_a_(this.te.get(), matrixStack, iRenderTypeBuffer, p_228364_4_, p_228364_5_);
public void render(ItemStack itemStackIn, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int p_228364_4_, int p_228364_5_) {
TileEntityRendererDispatcher.instance.renderNullable(this.te.get(), matrixStack, iRenderTypeBuffer, p_228364_4_, p_228364_5_);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public IronChestTileEntityRenderer(TileEntityRendererDispatcher tileEntityRender
super(tileEntityRendererDispatcher);

this.chestBottom = new ModelRenderer(64, 64, 0, 19);
this.chestBottom.func_228301_a_(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F);
this.chestBottom.addBox(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F);
this.chestLid = new ModelRenderer(64, 64, 0, 0);
this.chestLid.func_228301_a_(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
this.chestLid.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
this.chestLid.rotationPointY = 9.0F;
this.chestLid.rotationPointZ = 1.0F;
this.chestLock = new ModelRenderer(64, 64, 0, 0);
this.chestLock.func_228301_a_(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
this.chestLock.addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
this.chestLock.rotationPointY = 8.0F;
}

@Override
public void func_225616_a_(T tileEntityIn, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int p_225616_5_, int p_225616_6_) {
public void render(T tileEntityIn, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int p_225616_5_, int p_225616_6_) {
GenericIronChestTileEntity tileEntity = (GenericIronChestTileEntity) tileEntityIn;

World world = tileEntity.getWorld();
Expand All @@ -62,11 +62,11 @@ public void func_225616_a_(T tileEntityIn, float partialTicks, MatrixStack matri
if (block instanceof GenericIronChestBlock) {
GenericIronChestBlock ironChestBlock = (GenericIronChestBlock) block;

matrixStack.func_227860_a_();
matrixStack.push();
float f = blockstate.get(GenericIronChestBlock.FACING).getHorizontalAngle();
matrixStack.func_227861_a_(0.5D, 0.5D, 0.5D);
matrixStack.func_227863_a_(Vector3f.field_229181_d_.func_229187_a_(-f));
matrixStack.func_227861_a_(-0.5D, -0.5D, -0.5D);
matrixStack.translate(0.5D, 0.5D, 0.5D);
matrixStack.rotate(Vector3f.field_229181_d_.func_229187_a_(-f));
matrixStack.translate(-0.5D, -0.5D, -0.5D);

TileEntityMerger.ICallbackWrapper<? extends GenericIronChestTileEntity> iCallbackWrapper;
if (flag) {
Expand All @@ -82,19 +82,19 @@ public void func_225616_a_(T tileEntityIn, float partialTicks, MatrixStack matri
int i = iCallbackWrapper.apply(new DualBrightnessCallback<>()).applyAsInt(p_225616_5_);

Material material = IronChestsModels.chooseChestModel(tileEntity, chestType);
IVertexBuilder ivertexbuilder = material.func_229311_a_(iRenderTypeBuffer, RenderType::func_228638_b_);
IVertexBuilder ivertexbuilder = material.func_229311_a_(iRenderTypeBuffer, RenderType::entityCutout);

this.handleModelRender(matrixStack, ivertexbuilder, this.chestLid, this.chestLock, this.chestBottom, f1, i, p_225616_6_);

matrixStack.func_227865_b_();
matrixStack.pop();
}
}

private void handleModelRender(MatrixStack matrixStack, IVertexBuilder iVertexBuilder, ModelRenderer firstModel, ModelRenderer secondModel, ModelRenderer thirdModel, float f1, int p_228871_7_, int p_228871_8_) {
firstModel.rotateAngleX = -(f1 * ((float) Math.PI / 2F));
secondModel.rotateAngleX = firstModel.rotateAngleX;
firstModel.func_228308_a_(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
secondModel.func_228308_a_(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
thirdModel.func_228308_a_(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
firstModel.render(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
secondModel.render(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
thirdModel.render(matrixStack, iVertexBuilder, p_228871_7_, p_228871_8_);
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
package com.progwml6.ironchest.client.tileentity;

import com.google.common.collect.Sets;
import com.mojang.datafixers.util.Pair;
import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Atlases;
import net.minecraft.client.renderer.model.Material;
import net.minecraft.client.renderer.model.ModelBakery;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.profiler.EmptyProfiler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Util;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

@Mod.EventBusSubscriber(modid = IronChests.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class IronChestsModels {

public static final ResourceLocation chestAtlas = new ResourceLocation("textures/atlas/chest.png");

protected static final Set<Material> LOCATIONS_BUILTIN_TEXTURES = Util.make(Sets.newHashSet(), (p_229337_0_) -> {
addTextures(p_229337_0_::add);
});

public IronChestsModels() {
System.out.println("IronChestsModels");
//ModelBakery.LOCATIONS_BUILTIN_TEXTURES.addAll(LOCATIONS_BUILTIN_TEXTURES);
}

public static final Material IRON_CHEST_LOCATION = getChestMaterial("iron");
public static final Material GOLD_CHEST_LOCATION = getChestMaterial("gold");
public static final Material DIAMOND_CHEST_LOCATION = getChestMaterial("diamond");
Expand All @@ -54,7 +39,7 @@ public static void addTextures(Consumer<Material> p_228775_0_) {
}

private static Material getChestMaterial(String name) {
return new Material(Atlases.field_228747_f_, new ResourceLocation(IronChests.MODID, "model/" + name + "_chest"));
return new Material(Atlases.CHEST_ATLAS, new ResourceLocation(IronChests.MODID, "model/" + name + "_chest"));
}

public static Material chooseChestModel(TileEntity tileEntity, IronChestsTypes type) {
Expand All @@ -77,7 +62,23 @@ public static Material chooseChestModel(TileEntity tileEntity, IronChestsTypes t
return DIRT_CHEST_LOCATION;
case WOOD:
default:
return Atlases.field_228758_q_;
return Atlases.CHEST_MATERIAL;
}
}

@SubscribeEvent
public static void onStitch(TextureStitchEvent.Pre event) {
if (!event.getMap().getBasePath().equals(Atlases.CHEST_ATLAS)) {
return;
}

event.addSprite(IRON_CHEST_LOCATION.func_229313_b_());
event.addSprite(GOLD_CHEST_LOCATION.func_229313_b_());
event.addSprite(DIAMOND_CHEST_LOCATION.func_229313_b_());
event.addSprite(COPPER_CHEST_LOCATION.func_229313_b_());
event.addSprite(SILVER_CHEST_LOCATION.func_229313_b_());
event.addSprite(CRYSTAL_CHEST_LOCATION.func_229313_b_());
event.addSprite(OBSIDIAN_CHEST_LOCATION.func_229313_b_());
event.addSprite(DIRT_CHEST_LOCATION.func_229313_b_());
}
}

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/java/com/progwml6/ironchest/common/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.progwml6.ironchest.common;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Locale;
import java.util.stream.Collectors;

public class Util {

public static String toEnglishName(String internalName) {
return Arrays.stream(internalName.toLowerCase(Locale.ROOT).split("_"))
.map(StringUtils::capitalize)
.collect(Collectors.joining(" "));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.progwml6.ironchest.common.ai;

import net.minecraft.entity.ai.goal.CatSitOnBlockGoal;
import net.minecraft.entity.ai.goal.PrioritizedGoal;
import net.minecraft.entity.passive.CatEntity;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import java.util.HashSet;

public class CatsSitOnChestsHandler {

@SubscribeEvent
public void changeSittingTaskForOcelots(final LivingEvent.LivingUpdateEvent evt) {
if (evt.getEntityLiving().ticksExisted < 5 && evt.getEntityLiving() instanceof CatEntity) {
HashSet<PrioritizedGoal> goals = new HashSet<>();

CatEntity catEntity = (CatEntity) evt.getEntityLiving();

for (PrioritizedGoal goal : catEntity.goalSelector.goals) {
if (goal.getGoal().getClass() == CatSitOnBlockGoal.class) {
goals.add(goal);
}
}

for (PrioritizedGoal goal : goals) {
catEntity.goalSelector.removeGoal(goal.getGoal());
catEntity.goalSelector.addGoal(goal.getPriority(), new IronChestCatSitOnBlockGoal(catEntity, 0.4F));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.progwml6.ironchest.common.ai;

import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.ai.goal.CatSitOnBlockGoal;
import net.minecraft.entity.passive.CatEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader;

public class IronChestCatSitOnBlockGoal extends CatSitOnBlockGoal {

public IronChestCatSitOnBlockGoal(CatEntity catEntity, double p_i50330_2_) {
super(catEntity, p_i50330_2_);
}

@Override
protected boolean shouldMoveTo(IWorldReader worldIn, BlockPos pos) {
if (!worldIn.isAirBlock(pos.up())) {
return false;
}
else {
BlockState blockstate = worldIn.getBlockState(pos);
Block block = blockstate.getBlock();

if (block instanceof GenericIronChestBlock) {
return GenericIronChestTileEntity.getPlayersUsing(worldIn, pos) < 1;
}

return super.shouldMoveTo(worldIn, pos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState
}

@Override
public ActionResultType func_225533_a_(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
if (!worldIn.isRemote) {
INamedContainerProvider inamedcontainerprovider = this.getContainer(state, worldIn, pos);
if (inamedcontainerprovider != null) {
Expand Down
Loading

0 comments on commit 56db909

Please sign in to comment.