ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java

145 lines
6.6 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("ClientProxy.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.proxy;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.ClientRegistryHandler;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
2021-02-26 22:15:48 +01:00
import de.ellpeck.actuallyadditions.mod.blocks.render.*;
2016-07-22 20:23:51 +02:00
import de.ellpeck.actuallyadditions.mod.entity.InitEntities;
import de.ellpeck.actuallyadditions.mod.entity.RenderWorm;
2016-07-03 20:57:00 +02:00
import de.ellpeck.actuallyadditions.mod.event.ClientEvents;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit;
2021-02-26 22:15:48 +01:00
import de.ellpeck.actuallyadditions.mod.tile.*;
2017-02-13 23:17:08 +01:00
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingBlock;
2016-03-19 15:10:20 +01:00
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
2016-03-18 23:47:22 +01:00
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.color.IBlockColor;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
2021-02-26 22:15:48 +01:00
import net.minecraft.entity.player.PlayerEntity;
2016-01-08 16:52:53 +01:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketPlayerDigging;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
2021-02-26 22:15:48 +01:00
import java.util.ArrayList;
import java.util.List;
2019-05-02 09:10:29 +02:00
public class ClientProxy implements IProxy {
2019-02-27 19:53:05 +01:00
private static final List<Item> COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING = new ArrayList<>();
private static final List<Block> COLOR_PRODIVIDING_BLOCKS_FOR_REGISTERING = new ArrayList<>();
2016-12-18 17:50:31 +01:00
@Override
2019-05-02 09:10:29 +02:00
public void preInit(FMLPreInitializationEvent event) {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.info("PreInitializing ClientProxy...");
2015-06-15 22:06:07 +02:00
MinecraftForge.EVENT_BUS.register(new ClientRegistryHandler());
2016-07-22 20:23:51 +02:00
InitEntities.initClient();
}
@Override
2019-05-02 09:10:29 +02:00
public void init(FMLInitializationEvent event) {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.info("Initializing ClientProxy...");
2015-03-30 18:42:14 +02:00
RenderWorm.fixItemStack();
2019-02-27 19:53:05 +01:00
2016-07-03 20:57:00 +02:00
new ClientEvents();
//ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompost.class, new RenderCompost());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAtomicReconstructor.class, new RenderReconstructorLens());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySmileyCloud.class, new RenderSmileyCloud());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDisplayStand.class, new RenderDisplayStand());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEmpowerer.class, new RenderEmpowerer());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBatteryBox.class, new RenderBatteryBox());
TileEntitySpecialRenderer<TileEntityLaserRelay> laser = new RenderLaserRelay();
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayEnergy.class, laser);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayEnergyAdvanced.class, laser);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayEnergyExtreme.class, laser);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayItem.class, laser);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayItemWhitelist.class, laser);
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityLaserRelayFluids.class, laser);
2019-05-02 09:10:29 +02:00
for (Item item : COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING) {
if (item instanceof IColorProvidingItem) {
2021-02-26 22:15:48 +01:00
Minecraft.getInstance().getItemColors().registerItemColorHandler(((IColorProvidingItem) item).getItemColor(), item);
2017-02-13 23:17:08 +01:00
}
}
2019-05-02 09:10:29 +02:00
for (Block block : COLOR_PRODIVIDING_BLOCKS_FOR_REGISTERING) {
if (block instanceof IColorProvidingBlock) {
2021-02-26 22:15:48 +01:00
Minecraft.getInstance().getBlockColors().registerBlockColorHandler(((IColorProvidingBlock) block).getBlockColor(), block);
2017-02-13 23:17:08 +01:00
}
2019-05-02 09:10:29 +02:00
if (block instanceof IColorProvidingItem) {
2021-02-26 22:15:48 +01:00
Minecraft.getInstance().getItemColors().registerItemColorHandler(((IColorProvidingItem) block).getItemColor(), block);
2016-03-19 15:10:20 +01:00
}
2016-01-08 16:52:53 +01:00
}
2019-02-27 19:53:05 +01:00
IBlockColor color = (state, world, pos, tint) -> {
if (world != null && pos != null) {
TileEntity tileentity = world.getTileEntity(pos);
if (tileentity instanceof TileEntityCompost && ((TileEntityCompost) tileentity).getCurrentDisplay().getBlock() != state.getBlock()) {
2021-02-26 22:15:48 +01:00
BlockState iblockstate = ((TileEntityCompost) tileentity).getCurrentDisplay();
return Minecraft.getInstance().getBlockColors().colorMultiplier(iblockstate, world, pos, tint);
}
}
return -1;
};
2021-02-26 22:15:48 +01:00
Minecraft.getInstance().getBlockColors().registerBlockColorHandler(color, InitBlocks.blockCompost);
}
@Override
2019-05-02 09:10:29 +02:00
public void postInit(FMLPostInitializationEvent event) {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.info("PostInitializing ClientProxy...");
2016-07-03 20:57:00 +02:00
new SpecialRenderInit();
}
2016-01-08 20:51:03 +01:00
@Override
2019-05-02 09:10:29 +02:00
public void addRenderRegister(ItemStack stack, ResourceLocation location, String variant) {
ClientRegistryHandler.MODEL_LOCATIONS_FOR_REGISTERING.put(stack, new ModelResourceLocation(location, variant));
2016-01-08 20:51:03 +01:00
}
2016-03-19 15:10:20 +01:00
@Override
2019-05-02 09:10:29 +02:00
public void addColoredItem(Item item) {
COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING.add(item);
2016-03-19 15:10:20 +01:00
}
2017-02-13 23:17:08 +01:00
@Override
2019-05-02 09:10:29 +02:00
public void addColoredBlock(Block block) {
2017-02-13 23:17:08 +01:00
COLOR_PRODIVIDING_BLOCKS_FOR_REGISTERING.add(block);
}
@Override
2021-02-26 22:15:48 +01:00
public PlayerEntity getCurrentPlayer() {
return Minecraft.getInstance().player;
}
2019-02-27 19:53:05 +01:00
@Override
public void sendBreakPacket(BlockPos pos) {
2021-02-26 22:15:48 +01:00
NetHandlerPlayClient netHandlerPlayClient = Minecraft.getInstance().getConnection();
assert netHandlerPlayClient != null;
2021-02-26 22:15:48 +01:00
netHandlerPlayClient.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, Minecraft.getInstance().objectMouseOver.sideHit));
}
}