diff --git a/gradle.properties b/gradle.properties index bd08fa1d..ab86377a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.daemon=true org.gradle.parallel=true # Minecraft Version mc_version=1.12.2 -mod_version=4.11.1.0-pre4 +mod_version=4.11.1.0-pre5 forge_version=14.23.5.2860 mappings_version=snapshot_20171003 # Dependencies diff --git a/src/main/java/tauri/dev/jsg/block/props/DestinyVentBlock.java b/src/main/java/tauri/dev/jsg/block/props/DestinyVentBlock.java index 5e09b5f1..7f2c43f9 100644 --- a/src/main/java/tauri/dev/jsg/block/props/DestinyVentBlock.java +++ b/src/main/java/tauri/dev/jsg/block/props/DestinyVentBlock.java @@ -1,5 +1,6 @@ package tauri.dev.jsg.block.props; +import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.BlockFaceShape; @@ -7,10 +8,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; 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; @@ -19,6 +23,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import tauri.dev.jsg.JSG; import tauri.dev.jsg.block.JSGBlock; +import tauri.dev.jsg.config.JSGConfigUtil; import tauri.dev.jsg.creativetabs.JSGCreativeTabsHandler; import tauri.dev.jsg.renderer.props.DestinyVentRenderer; import tauri.dev.jsg.tileentity.props.DestinyVentTile; @@ -26,6 +31,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; @SuppressWarnings("deprecation") public class DestinyVentBlock extends JSGBlock { @@ -74,6 +80,30 @@ public void onBlockPlacedBy(World world, @Nonnull BlockPos pos, @Nonnull IBlockS world.setBlockState(pos, state); } + @Override + @ParametersAreNonnullByDefault + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + ItemStack heldItemStack = player.getHeldItem(EnumHand.MAIN_HAND); + + if (heldItemStack.isEmpty()) return false; + if (!(heldItemStack.getItem() instanceof ItemBlock)) return false; + + if (!JSGConfigUtil.canBeUsedAsCamoBlock(Block.getBlockFromItem(heldItemStack.getItem()).getBlockState().getBaseState())) { + return false; + } + if (world.isRemote) return false; + + DestinyVentTile ventTile = (DestinyVentTile) world.getTileEntity(pos); + + if (ventTile == null) return false; + + Block block = Block.getBlockFromItem(heldItemStack.getItem()); + int meta = heldItemStack.getMetadata(); + ventTile.setCamoState(block.getStateFromMeta(meta)); + + return true; + } + // -------------------------------------------------------------------------------------- @Override diff --git a/src/main/java/tauri/dev/jsg/renderer/props/DestinyVentRenderer.java b/src/main/java/tauri/dev/jsg/renderer/props/DestinyVentRenderer.java index f50fdee5..0d7746f5 100644 --- a/src/main/java/tauri/dev/jsg/renderer/props/DestinyVentRenderer.java +++ b/src/main/java/tauri/dev/jsg/renderer/props/DestinyVentRenderer.java @@ -1,11 +1,15 @@ package tauri.dev.jsg.renderer.props; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; import tauri.dev.jsg.loader.ElementEnum; +import tauri.dev.jsg.loader.texture.TextureLoader; import tauri.dev.jsg.particle.ParticleBlenderCOBlast; +import tauri.dev.jsg.renderer.biomes.BiomeOverlayEnum; import tauri.dev.jsg.tileentity.props.DestinyVentTile; import tauri.dev.jsg.util.FacingHelper; import tauri.dev.jsg.util.main.JSGProps; @@ -20,6 +24,8 @@ public void render(@Nonnull DestinyVentTile te, double x, double y, double z, fl float animationStage = te.getAnimationStage(tick); boolean fireParticles = (animationStage == 1f); + IBlockState camoBlockState = te.getCamoState(); + GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); GlStateManager.translate(0.5, 0f, 0.5); @@ -35,7 +41,16 @@ public void render(@Nonnull DestinyVentTile te, double x, double y, double z, fl ElementEnum.DESTINY_VENT_HOLE.bindTextureAndRender(); GlStateManager.pushMatrix(); GlStateManager.rotate((70f * animationStage), 1, 0, 0); - ElementEnum.DESTINY_VENT_MOVING.bindTextureAndRender(); + + if(camoBlockState == null){ + ElementEnum.DESTINY_VENT_MOVING.bindTexture(BiomeOverlayEnum.NORMAL); + } + else{ + ResourceLocation overlayResource = TextureLoader.getBlockTexture(camoBlockState); + Minecraft.getMinecraft().getTextureManager().bindTexture(overlayResource); + } + + ElementEnum.DESTINY_VENT_MOVING.render(); if (fireParticles) { for (int i = 0; i < 50; i++) { boolean orange = (i < 25); diff --git a/src/main/java/tauri/dev/jsg/tileentity/props/DestinyVentTile.java b/src/main/java/tauri/dev/jsg/tileentity/props/DestinyVentTile.java index d65a81fe..3383efba 100644 --- a/src/main/java/tauri/dev/jsg/tileentity/props/DestinyVentTile.java +++ b/src/main/java/tauri/dev/jsg/tileentity/props/DestinyVentTile.java @@ -1,17 +1,27 @@ package tauri.dev.jsg.tileentity.props; import io.netty.buffer.ByteBuf; +import net.minecraft.block.Block; +import net.minecraft.block.BlockSlab; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import tauri.dev.jsg.JSG; +import tauri.dev.jsg.packet.JSGPacketHandler; +import tauri.dev.jsg.packet.StateUpdateRequestToServer; import tauri.dev.jsg.sound.JSGSoundHelper; import tauri.dev.jsg.sound.SoundEventEnum; import tauri.dev.jsg.state.State; import tauri.dev.jsg.state.StateTypeEnum; +import tauri.dev.jsg.state.stargate.StargateCamoState; import javax.annotation.Nonnull; +import java.util.Objects; public class DestinyVentTile extends DestinyBearingTile { - public float getAnimationStage(double tick){ + public float getAnimationStage(double tick) { double time = Math.max((tick - animationStart - ANIMATION_DELAY_BEFORE), 0); float animationStage = 0; if (time <= (ANIMATION_DELAY_BETWEEN + OPEN_ANIMATION_LENGTH * 2)) @@ -64,17 +74,27 @@ public DestinyVentRenderState getRendererState() { return rendererState; } + @Override + public void onLoad() { + super.onLoad(); + if (!world.isRemote) { + sendState(StateTypeEnum.CAMO_STATE, getState(StateTypeEnum.CAMO_STATE)); + } else { + JSGPacketHandler.INSTANCE.sendToServer(new StateUpdateRequestToServer(pos, StateTypeEnum.CAMO_STATE)); + } + } + @Override public void update() { super.update(); - if(!world.isRemote) { + if (!world.isRemote) { boolean isOpen = (getAnimationStage(world.getTotalWorldTime()) == 1); if (!isOpen && soundPlayed) { soundPlayed = false; markDirty(); - } else if(isOpen && !soundPlayed){ + } else if (isOpen && !soundPlayed) { soundPlayed = true; markDirty(); JSGSoundHelper.playSoundEvent(world, pos, SoundEventEnum.DESTINY_BLASTER); @@ -93,32 +113,123 @@ public void startAnimation() { // Server @Override public State getState(StateTypeEnum stateType) { - if (stateType == StateTypeEnum.RENDERER_STATE) { - return getRendererState().animate(isActive, animationStart); + switch (stateType) { + case CAMO_STATE: + return new StargateCamoState(camoBlockState); + + case RENDERER_STATE: + return getRendererState().animate(isActive, animationStart); + + default: + return null; } - return null; } // Server @Override public State createState(StateTypeEnum stateType) { - if (stateType == StateTypeEnum.RENDERER_STATE) { - return getRendererState().animate(isActive, animationStart); + switch (stateType) { + case CAMO_STATE: + return new StargateCamoState(); + case RENDERER_STATE: + return getRendererState().animate(isActive, animationStart); + default: + return null; } - return null; } // Client @Override public void setState(StateTypeEnum stateType, State state) { - if (stateType == StateTypeEnum.RENDERER_STATE) { - this.animationStart = ((DestinyVentRenderState) state).animationStart; + switch (stateType) { + case CAMO_STATE: + StargateCamoState memberState = (StargateCamoState) state; + camoBlockState = memberState.getState(); + + world.markBlockRangeForRenderUpdate(pos, pos); + break; + case RENDERER_STATE: + this.animationStart = ((DestinyVentRenderState) state).animationStart; + break; + default: + break; + } + } + + + // --------------------------------------------------------------------------------- + private IBlockState camoBlockState; + + /** + * Should only be called from server. Updates camoBlockState and + * syncs the change to clients. + * + * @param camoBlockState Camouflage block state. + */ + public void setCamoState(IBlockState camoBlockState) { + // JSG.logger.debug("Setting camo for " + pos + " to " + camoBlockState); + + this.camoBlockState = camoBlockState; + markDirty(); + + if (!world.isRemote) { + sendState(StateTypeEnum.CAMO_STATE, getState(StateTypeEnum.CAMO_STATE)); + } else { + JSG.warn("Tried to set camoBlockState from client. This won't work!"); + } + } + + public IBlockState getCamoState() { + return camoBlockState; + } + + public ItemStack getCamoItemStack() { + if (camoBlockState != null) { + Block block = camoBlockState.getBlock(); + + if (block == Blocks.SNOW_LAYER) + return null; + + int quantity = 1; + int meta; + + if (block instanceof BlockSlab && ((BlockSlab) block).isDouble()) { + quantity = 2; + meta = block.getMetaFromState(camoBlockState); + + if (block == Blocks.DOUBLE_STONE_SLAB) + block = Blocks.STONE_SLAB; + + else if (block == Blocks.DOUBLE_STONE_SLAB2) + block = Blocks.STONE_SLAB2; + + else if (block == Blocks.DOUBLE_WOODEN_SLAB) + block = Blocks.WOODEN_SLAB; + + else if (block == Blocks.PURPUR_DOUBLE_SLAB) + block = Blocks.PURPUR_SLAB; + } else { + meta = block.getMetaFromState(camoBlockState); + } + + return new ItemStack(block, quantity, meta); + } else { + return null; } } + // ------------------------------------------------------------ + @Override public void readFromNBT(@Nonnull NBTTagCompound compound) { this.animationStart = compound.getLong("animationStart"); + + if (compound.hasKey("camoBlock")) { + Block dblSlabBlock = Block.getBlockFromName(compound.getString("camoBlock")); + if (dblSlabBlock != null) + camoBlockState = dblSlabBlock.getStateFromMeta(compound.getInteger("camoBlocMeta")); + } + super.readFromNBT(compound); } @@ -126,6 +237,11 @@ public void readFromNBT(@Nonnull NBTTagCompound compound) { @Override public NBTTagCompound writeToNBT(@Nonnull NBTTagCompound compound) { compound.setLong("animationStart", animationStart); + + if (camoBlockState != null) { + compound.setString("camoBlock", Objects.requireNonNull(camoBlockState.getBlock().getRegistryName()).toString()); + compound.setInteger("camoBlocMeta", camoBlockState.getBlock().getMetaFromState(camoBlockState)); + } return super.writeToNBT(compound); } }